Tag: command

RAID1By Robert Camilleri

We start by listing the partition tables present on the server to locate the new hard disk

[root@mail ~]# fdisk -l

Disk /dev/hda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 13 104391 fd Linux raid autodetect
/dev/hda2 14 6387 51199155 fd Linux raid autodetect
/dev/hda3 6388 6769 3068415 fd Linux raid autodetect
/dev/hda4 6770 60801 434012040 fd Linux raid autodetect

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/hdc doesn’t contain a valid partition table

Disk /dev/md1: 52.4 GB, 52427816960 bytes
2 heads, 4 sectors/track, 12799760 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md1 doesn’t contain a valid partition table

Disk /dev/md3: 444.4 GB, 444428255232 bytes
2 heads, 4 sectors/track, 108502992 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md3 doesn’t contain a valid partition table

Disk /dev/md2: 3141 MB, 3141926912 bytes
2 heads, 4 sectors/track, 767072 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md2 doesn’t contain a valid partition table

Disk /dev/md0: 106 MB, 106823680 bytes
2 heads, 4 sectors/track, 26080 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn’t contain a valid partition table

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 121601 976760001 83 Linux
[root@mail ~]#

The above output shows that there are two hard disks (hda and hdc). Partitions are visible on hda however hdc does not contain a valid partition table. In fact this is the replacement for the faulty disk.

To view the health of the Software RAID type cat /proc/mdstat

[root@mail ~]# cat /proc/mdstat

Personalities: [raid1]

md0: active raid1 hda1[1]

104320 blocks [2/1] [_U]

md2: active raid1 hda3[1]
3068288 blocks [2/1] [_U]

md3: active raid1 hda4[1]
434011968 blocks [2/1] [_U]

md1: active raid1 hda2[1]
51199040 blocks [2/1] [_U]

unused devices:
[root@mail ~]#

Note that [2/1] shows that there are 2 disks in the array however only 1 is active. The symbols [_U] mean that one of the two disks is missing from the array and must be reconfigured.

Since the new disk is /dev/hdc we need create the partitions required for the RAID. Use fdisk to create the boot partition on the new disk.

[root@mail ~]# fdisk /dev/hdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0×0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60801, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801): +100M

Command (m for help): p

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): l

0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot
1 FAT12 24 NEC DOS 81 Minix / old Lin bf Solaris
2 XENIX root 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
4 FAT16 5 Extended 41 PPC PReP Boot 85 Linux extended c7 Syrinx
6 FAT16 42 SFS 86 NTFS volume set da Non-FS data
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set db CP/M / CTOS /.
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3 75 PC/IX
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect

Command (m for help):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mail ~]#

Type fdisk -l to verify creation of partition on the second disk

[root@mail ~]# fdisk -l

Disk /dev/hda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 13 104391 fd Linux raid autodetect
/dev/hda2 14 6387 51199155 fd Linux raid autodetect
/dev/hda3 6388 6769 3068415 fd Linux raid autodetect
/dev/hda4 6770 60801 434012040 fd Linux raid autodetect

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect

Disk /dev/md1: 52.4 GB, 52427816960 bytes
2 heads, 4 sectors/track, 12799760 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md1 doesn’t contain a valid partition table

Disk /dev/md3: 444.4 GB, 444428255232 bytes
2 heads, 4 sectors/track, 108502992 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md3 doesn’t contain a valid partition table

Disk /dev/md2: 3141 MB, 3141926912 bytes
2 heads, 4 sectors/track, 767072 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md2 doesn’t contain a valid partition table

Disk /dev/md0: 106 MB, 106823680 bytes
2 heads, 4 sectors/track, 26080 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn’t contain a valid partition table

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 121601 976760001 83 Linux
[root@mail ~]#

Software RAID requires disks in the array to be partitioned identically. You can try to do this manually calculating the exact number of cylinders required for each partition to match their counterparts on the other disk. This is highly discouraged. Instead we use the sfdisk command.

[root@mail ~]# sfdisk -d /dev/hda

# partition table of /dev/hda

unit: sectors

/dev/hda1: start= 63, 208782, Id=fd
/dev/hda2: start= 208845, Id=fd
/dev/hda3: start=102607155, 6136830, Id=fd
/dev/hda4: start=108743985, Id=fd
[root@mail ~]#

The output above displays the partition sizes on the primary disk

In order to create identical partitions on the secondary disk we type the following

[root@mail ~]# sfdisk -d /dev/hda | sfdisk /dev/hdc

Checking that no-one is using this disk right now... 

OK

Disk /dev/hdc: 60801 cylinders, 255 heads, 63 sectors/track
Old situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/hdc1 0+ 12 13- 104391 fd Linux raid autodetect
/dev/hdc2 0 – 0 0 0 Empty
/dev/hdc3 0 – 0 0 0 Empty
/dev/hdc4 0 – 0 0 0 Empty
New situation:
Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System
/dev/hdc1 63 208844 208782 fd Linux raid autodetect
/dev/hdc2 208845 102607154 102398310 fd Linux raid autodetect
/dev/hdc3 102607155 108743984 6136830 fd Linux raid autodetect
/dev/hdc4 108743985 976768064 868024080 fd Linux raid autodetect
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Successfully wrote the new partition table

Re-reading the partition table…

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
[root@mail ~]#

Typing fdisk -l once again displays that the partitions on both disks are in fact identical

[root@mail ~]# fdisk -l

Disk /dev/hda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 13 104391 fd Linux raid autodetect
/dev/hda2 14 6387 51199155 fd Linux raid autodetect
/dev/hda3 6388 6769 3068415 fd Linux raid autodetect
/dev/hda4 6770 60801 434012040 fd Linux raid autodetect

Disk /dev/hdc: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 13 104391 fd Linux raid autodetect
/dev/hdc2 14 6387 51199155 fd Linux raid autodetect
/dev/hdc3 6388 6769 3068415 fd Linux raid autodetect
/dev/hdc4 6770 60801 434012040 fd Linux raid autodetect

Disk /dev/md1: 52.4 GB, 52427816960 bytes
2 heads, 4 sectors/track, 12799760 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md1 doesn’t contain a valid partition table

Disk /dev/md3: 444.4 GB, 444428255232 bytes
2 heads, 4 sectors/track, 108502992 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md3 doesn’t contain a valid partition table

Disk /dev/md2: 3141 MB, 3141926912 bytes
2 heads, 4 sectors/track, 767072 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md2 doesn’t contain a valid partition table

Disk /dev/md0: 106 MB, 106823680 bytes
2 heads, 4 sectors/track, 26080 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn’t contain a valid partition table

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 121601 976760001 83 Linux
[root@mail ~]#

Now that the partitions are identical we can re-sync the information across the RAID configuration

Type mdadm -a /dev/md0 /dev/hdc1 to add /dev/hdc1 partition to the /dev/md0 RAID partition.

[root@mail ~]# mdadm -a /dev/md0 /dev/hdc1

mdadm: added /dev/hdc1

[root@mail ~]#

Type cat /proc/mdstat to view the re-syncing process

[root@mail ~]# cat /proc/mdstat

Personalities: [raid1]

md0: active raid1 hdc1[2] hda1[1]

104320 blocks [2/1] [_U]

[=>... ] recovery = 7.8% (8512/104320) finish=0.7min speed=2128K/sec

md2: active raid1 hda3[1]
3068288 blocks [2/1] [_U]

md3: active raid1 hda4[1]
434011968 blocks [2/1] [_U]

md1: active raid1 hda2[1]
51199040 blocks [2/1] [_U]

unused devices:
[root@mail ~]# cat /proc/mdstat
Personalities: [raid1]
md0: active raid1 hdc1[2] hda1[1]
104320 blocks [2/1] [_U]
[=======>... ] recovery = 37.2% (39808/104320) finish=0.5min speed=1809K/sec

md2: active raid1 hda3[1]
3068288 blocks [2/1] [_U]

md3: active raid1 hda4[1]
434011968 blocks [2/1] [_U]

md1: active raid1 hda2[1]
51199040 blocks [2/1] [_U]

unused devices:

The below shows how the output should be when the re-syncing process has ended. Note the “[UU]“. This confirms that both disks are active.

[root@mail ~]# cat /proc/mdstat

Personalities: [raid1]

md0: active raid1 hdc1[0] hda1[1]

104320 blocks [2/2] [UU]

md2: active raid1 hda3[1]
3068288 blocks [2/1] [_U]

md3: active raid1 hda4[1]
434011968 blocks [2/1] [_U]

md1: active raid1 hda2[1]
51199040 blocks [2/1] [_U]

unused devices:
[root@mail ~]#

The same process has to be performed on the other partitions

[root@mail ~]# mdadm -a /dev/md1 /dev/hdc2

mdadm: added /dev/hdc2

[root@mail ~]# mdadm -a /dev/md2 /dev/hdc3

mdadm: added /dev/hdc3

[root@mail ~]# mdadm -a /dev/md3 /dev/hdc4

mdadm: added /dev/hdc4

[root@mail ~]# cat /proc/mdstat

Personalities: [raid1]

md0: active raid1 hdc1[0] hda1[1]

104320 blocks [2/2] [UU]

md2: active raid1 hdc3[2] hda3[1]
3068288 blocks [2/1] [_U]
resync=DELAYED

md3: active raid1 hdc4[2] hda4[1]
434011968 blocks [2/1] [_U]
resync=DELAYED

md1: active raid1 hdc2[2] hda2[1]
51199040 blocks [2/1] [_U]
[>... ] recovery = 0.0% (37376/51199040) finish=501.5min speed=1698K/sec

unused devices:
[root@mail ~]#

Finally we need to install GRUB on the second disk’s MBR.

[root@mail ~]# grub
GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> find /grub/grub.conf
(hd0,0)
(hd1,0)

grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd1)
Checking if “/boot/grub/stage1″ exists… no
Checking if “/grub/stage1″ exists… yes
Checking if “/grub/stage2″ exists… yes
Checking if “/grub/e2fs_stage1_5″ exists… yes
Running “embed /grub/e2fs_stage1_5 (hd1)”… 15 sectors are embedded.
succeeded
Running “install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf”… succeeded
Done.

grub> quit

Tags: , , , , ,

Linux Mint 12 logoBy Christopher P Wakefield

Usually I would set up a Linux dhcp server using the dhcp3-server package. With the arrival of Linux Mint 12 the configuration is slightly different. This tutorial will outline the new steps.

First thing to do is to give your server a static IP address.

Now we need to install the dhcp package. Open up a terminal and type:

sudo apt-get install isc-dhcp-server

There are two main files /etc/default/isc-dhcp-server and /etc/dhcp/dhcpd.conf~ which we will need to configure so lets take the first. Open up a terminal and using your favourite text editor type:

sudo gedit /etc/default/isc-dhcp-server

You should get the following:

———————————————————————————————–

# Defaults for dhcp initscript # sourced by /etc/init.d/dhcp # installed at /etc/default/isc-dhcp-server by the maintainer scripts

# # This is a POSIX shell fragment #

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests? # Separate multiple interfaces with spaces, e.g. “eth0 eth1″. INTERFACES=”eth0″

————————————————————————————————–

Replace eth0 above with the name of your network interface that you want the server to lease addresses on. Onto the next file. Open up a terminal and type:

sudo gedit /etc/dhcp/dhcdp.conf~

which should give you the output below.

————————————————————————————————-

# # Sample configuration file for ISC dhcpd for Debian # # Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as # configuration file instead of this file. # #

# The ddns-updates-style parameter controls whether or not the server will # attempt to do a DNS update when a lease is confirmed. We default to the # behavior of the version 2 packages (‘none’, since DHCP v2 didn’t # have support for DDNS.) ddns-update-style none;

# option definitions common to all supported networks… option domain-name “example.org”; option domain-name-servers ns1.example.org, ns2.example.org;

option domain-name “business.com”; default-lease-time 600; max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative;

# Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7;

# No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 { #}

# This is a very basic subnet declaration.

subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.150 10.0.0.253; option routers 10.0.0.2; option subnet-mask 255.255.255.0;

option broadcast-address 10.0.0.254; option domain-name-servers 10.0.0.1, 10.0.0.2;

option ntp-servers 10.0.0.1; option netbios-name-servers 10.0.0.1; option netbios-node-type 8; }

option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;

}

# This declaration allows BOOTP clients to get dynamic addresses, # which we don’t really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 { # range dynamic-bootp 10.254.239.40 10.254.239.60; # option broadcast-address 10.254.239.31; # option routers rtr-239-32-1.example.org; #}

# A slightly different configuration for an internal subnet. #subnet 10.5.5.0 netmask 255.255.255.224 { # range 10.5.5.26 10.5.5.30; # option domain-name-servers ns1.internal.example.org; # option domain-name “internal.example.org”; # option routers 10.5.5.1; # option broadcast-address 10.5.5.31; # default-lease-time 600; # max-lease-time 7200; #}

# Hosts which require special configuration options can be listed in # host statements. If no address is specified, the address will be # allocated dynamically (if possible), but the host-specific information # will still come from the host declaration.

#host passacaglia { # hardware ethernet 0:0:c0:5d:bd:95; # filename “vmunix.passacaglia”; # server-name “toccata.fugue.com”; #}

# Fixed IP addresses can also be specified for hosts. These addresses # should not also be listed as being available for dynamic assignment. # Hosts for which fixed IP addresses have been specified can boot using # BOOTP or DHCP. Hosts for which no fixed address is specified can only # be booted with DHCP, unless there is an address range on the subnet # to which a BOOTP client is connected which has the dynamic-bootp flag # set. #host fantasia { # hardware ethernet 08:00:07:26:c0:a5; # fixed-address fantasia.fugue.com; #}

# You can declare a class of clients and then do address allocation # based on that. The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all # other clients get addresses on the 10.0.29/24 subnet.

#class “foo” { # match if substring (option vendor-class-identifier, 0, 4) = “SUNW”; #}

#shared-network 224-29 { # subnet 10.17.224.0 netmask 255.255.255.0 { # option routers rtr-224.example.org; # } # subnet 10.0.29.0 netmask 255.255.255.0 { # option routers rtr-29.example.org; # } # pool { # allow members of “foo”; # range 10.17.224.10 10.17.224.250; # } # pool { # deny members of “foo”; # range 10.0.29.10 10.0.29.230; # } #}

————————————————————————————————

This needs a little bit of explaining.

1. Everything in bold needs adding to the file. Adjust your settings according to your network requirements.

2. The option domain name is your dns zone name. For example set to business.com.

3. Range should be the range of ip addresses that you want the server to give out to clients.

Now restart the dhcp service by typing:

sudo service isc-dhcp-server restart

That’s it!! Your dhcp server should be running, however it is best to check. Open up a terminal and type:

sudo netstat -uap

which will show you the following information:

————————————————————————————————

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

udp 0 0 *:55827 *:* 916/avahi-daemon: r udp 0 0 chris-desktop.lo:domain *:* 1273/named udp 0 0 chris-desktop:domain *:* 1273/named udp 0 0 *:bootps *:* 4525/dhcpd udp 0 0 *:17500 *:* 1768/dropbox udp 0 0 *:54407 *:* 4539/VirtualBox udp 0 0 10.0.0.255:netbios-ns *:* 1016/nmbd udp 0 0 chris-deskto:netbios-ns *:* 1016/nmbd udp 0 0 *:netbios-ns *:* 1016/nmbd udp 0 0 10.0.0.255:netbios-dgm *:* 1016/nmbd udp 0 0 chris-deskt:netbios-dgm *:* 1016/nmbd udp 0 0 *:netbios-dgm *:* 1016/nmbd udp 0 0 *:mdns *:* 916/avahi-daemon: r udp6 0 0 [::]:domain [::]:* 1273/named udp6 0 0 [::]:51853 [::]:* 916/avahi-daemon: r udp6 0 0 [::]:mdns [::]:* 916/avahi-daemon: r

————————————————————————————————

This shows that the dhcp daemon is working.

Hi I am Chris the owner of ComTech. I provide IT support to both personal and business clients from my base in Alloa, Clacknmannanshire. Here at ComTech I am experienced in using Windows and Linux technologies whether it be for the home or business. I also incorporate Blackberry hardware into my business, namely the Blackberry Playbook and Bold 9780. I can advise, design and implement solutions to any problems you may have so if you have IT issues just pick up the phone. Please go to http://www.comtech247.net for more information.

Tags: , , , , ,

By Clyde E. Boom

When you are a new user and trying to get Linux training, you need to learn how to use commands.

What you most often need is a clear, detailed example showing you exactly how to use a command.

And you’ll often hear seasoned Linux users say (over and over again) “just see the man page” for a command. This has become a quick and easy way out of really trying to explain how to use the command.

Linux man pages are useful if you already know how to use a command, but extremely frustrating if you are new to the OS (operating system).

Linux Training Tips: Linux man pages are practically useless for someone new. In fact, they’re almost as easy as trying to read hieroglyphics. Great for the ancient Egyptians – lots of really nice pictures, but really hard to read.

Here’s Why Man Pages Don’t Work for Someone New to Linux – And What You Can Do About It

linux man command“Man” stands for “manual”, as in “software documentation and you run the Linux man command to display the contents of a help page (file).

So, if you need help on a Linux command (or software program), you just run the man command to get instant online help.

Sounds great – but it’s not great for a new user.

And it would be great if the people that knew how to use Linux, didn’t expect the people that are new to understand man pages!

Linux Training Tips: The Linux System Administration concepts, commands and tasks covered here apply to ALL other Linux distributions, including: Red Hat, Fedora, Ubuntu, Kubuntu, Edubuntu, Slackware, Debian, SUSE and openSUSE.

Here’s how to run the Linux man command and get help on the grep command:

$ man grep

This displays the contents of the help page (file) for the grep command.

Linux Training Tips: There are several options of this command that can be used to display information on multiple pages. But hey, how do I get help on this command? You guessed it – just run: man man

Now, the grep command is pretty amazing in what it can do. It has lots of options and different ways of getting tons of useful information from a Linux system – but you’d never know it from looking at the man page.

The man page for any Linux command just shows you: a vague description of the command, a cryptic statement showing how to run the command, and a long alphabetic listing of the options. There’s no way of knowing which options are the most useful and most commonly used.

And the worst part is that it’s almost impossible to find an example of a command.

In the thousands of man pages, there are almost never any examples of how to use a command. And seeing examples of a command (and then running the command) – is the best way to learn how to use Linux.

Instead of trying to decipher a cryptic man page, imagine watching a clearly narrated Linux training videos. Easy training at it’s best!

With this Linux training method you get to see and hear how to use a command – or learn a new concept.

You see every step in the process – and whenever you need to think about something, or want to try a command you’ve just seen, you just click pause and try it yourself!

And now I would like to offer you free access to my Linux Commands Training Mini-Course, a 7 Lesson, Daily Mini-Course, including the free Linux Commands ebook and Linux audio podcasts – showing you how to get started learning how to use Linux commands.

You can get your instant access at: http://www.LinuxCommandsTrainingCourse.com

From Clyde Boom – The Easy Linux Training Guy – Easy, self-paced Linux training – In Plain English!

Tags: , , , ,

By Rand Whitehall

damn small linuxIf you want to move a file from one place to another, use the mv, or move command. Now, the mv tool can send a file from one directory to another, but it also can rename a file. If you simply want to change the name of a file, say, from joo.txt to joe.txt, you can do that with mv also. Here are a few examples to get you going.

mv joe joe1

The file joe is simply renamed joe1

mv joe /Documents/joe

The file joe is moved to the Documents directory.

Now, what if we wanted to move joe.txt to the Documents directory and at the same time rename it to joe2?

mv joe Documents/joe2

This would move the file joe to the Documents directory and would change the name to joe2. This is similar to cp, but the original file is changed. With cp we get a new file and the original file is unchanged.

If you’d like to see the contents of a file, use the cat command. cat stands for concatenate. cat will display the contents of a file and also join, or concatenate several files.

cat joe

This command will output the contents of joe.

What if you’d like to view the contents of two or more files?

cat joe bob

Will output the contents of joe and then bob.

Ok. Now let’s play around with cat and two new commands: touch and echo.

Do this:

touch jj.txt

Which will create new text file called jj.txt.

echo “Hi there” >> jj.txt

This adds the text “Hi there!” to jj.txt.

You can append some more text to the end of jj.txt with another echo command and two greater than signs “>>” like this:

echo “How are you?” >> jj.txt

Now take a look at the contents of jj.txt via:

cat jj.txt

One thing to know when using cat, if you use only one greater than sign “>”, it will overwrite the contents of the file. Be careful!

Let’s overwrite jj.txt on purpose.

echo “See you later.” > jj.txt

Now view the contents via cat:

cat jj.txt

… and you should see only the “See you later.” line.

I hope this helped you become a little more familiar with the Linux command line. Have fun and experiment. Remember, while playing around, it’s best to create a new directory and make new files specifically to experiment with so you don’t lose any important data. Soon you’ll be using the command line like a pro!

Rand writes about web design, men’s health and latex free nitrile gloves. Please check out his new website all about Blue Nitrile Exam Gloves for info and nitrile glove knowhow! Rand’s other writings can be found here: Rand Whitehall.

Tags: , , , , ,

By Rand Whitehall

To copy a file in the Linux command line interface (cli) then use the cp command. If you are familiar with DOS, cp is like the COPY command. To copy a file you need to write the name of the file you want to copy and the name of the newly copied file.

So, to make a copy of my file called joe and name the new file joe2, I type:

cp joe joe2

I then issue the ls command to show a list of the current files in the directory and I should see my old file joe and a new file called joe2 which is an exact copy of tom.

Now what if I wanted to copy the file joe, but put the copy in another directory? Well, then I simply specify which directory I want the copy to go into.

cp joe Documents/joe2

This will copy the file joe, name the new copy joe2, and place joe2 in the Documents directory. So with one simple command I copied, renamed, and moved a file. It took under a second. If I had done that in the GUI (graphical user interface) it would have taken at least a minute and a bunch of clicks.

What if I type this?: (hint: Documents is a directory.)

cp joe Documents/

Well, if you said a new copy of joe (named joe) would be created in the Documents directory, then you’d be right.

Since we did not specify a name for our copy, but did specify a directory, cp simply used the original name.

What if we do this?:

cp bashcp joe

The output is this an error:

cp: missing destination file operand after `joe’

Try `cp –help’ for more information.

Oops. cp needs a destination, which is either a new name for the copied file, or another directory to place the copy into.

I hope this helps you understand the basics of the GNU Linux command cp. The more you learn about the different cli commands, the more you can do. Soon you’ll be saving tons of time using the cli to perform tasks that would have taken the GUI hundreds of clicks.

Please be careful, though, when starting out with the cli. The command line tools can perform just about any task quickly and efficiently. But it’s easy to damage your system if you accidentally delete something or move a file that shouldn’t have been moved. The cli is like a very sharp katana that can slice through just any problem you may have, but it can also do unintended harm if you aren’t careful.

So when starting out, it’s best to work in safe, “sandbox” directories, on files you have created specifically to learn cli commands. I usually make a new directory, then copy a few files in to play with, so if I screw up, it’s no problem.

Rand writes about web design, men’s health and nitrile gloves. Please check out his new website all about allergy free Nitrile Gloves for info and nitrile glove know how! Check out the Nitrile Gloves vs. Latex Gloves page to find out how nitrile stacks up against latex.

Tags: , , ,

By Rand Whitehall

If you are just starting out using the command line in Linux, knowing just a few key commands can take you a long way towards fluency in the cli (command line interface) environment. Most new linux users fear the dreaded command line and its archane text-based commands. But if you warm up to the command line slowly and patiently, you’ll start to see you can wield great power over your computer using cli tools. It is truly amazing how much you can do with the cli and how quickly and efficiently it can do things. Some tasks can be done with a few lines of commands in under a second that would take thousands of mouse clicks and hours to accomplish in a typical GUI (graphical user interface).

The ls command is very powerful and useful so we’ll start there, then take a look at the file command.

ls: The ls command lists the contents of a directory. Simply type ls and hit the enter key. You should see a list of the contents of your current directory.

Now, if you want to get a bit fancy, you can tell ls to show you file sizes as well by adding the -l switch like this: ls -l.

This will show you the contents of the directory and files size, file date, file time and file name.

Now, while you are looking at details of the files in your current directory, you may be wondering what type of files they are. For example, if my home directory had a file called joe, I would type file joe to find out what type of file it was.

The file named joe is a text file so the file command outputs: joe.txt UTF-8 Unicode English text.

I’ve also got a directory listed called bob. If I type file: bob, then file outputs: bob/ directory.

The file command can tell us about any type of file. Digging deeper into my filesystem I come across a file that I don’t know. What type of file is it? Run the file command. file: bak.sh. The output of the file command: Bourne-Again shell script text executable. Ahh, it’s a bash script.

What’s a bash script? It’s a list of cli commands strung together in a text file. A bash script is like a small program that can perform just about any number of tasks. Very powerful stuff once you get a few more commands under your belt.

Rand writes about Linux, old school safety razors and blue nitrile gloves! Check out Rand’s site all about latex free nitrile gloves, a great barrier against infection. Black Nitrile Gloves are also available and used often by tattoo artists, mechanics and industries where keeping dirt and grime free is important.

Tags: , , , , ,

By Josh Bellendir

This tutorial will help the novice Unix/Linux user to be able to set the Path Variable. This can be useful to speed up access to software in the linux environment. Once you have a path added to your path variable, you can then simply type the executive to run the program or filename to open the file. You won’t need to specify the full path any longer.

To view what your current PATH variable is type the following at the command prompt:

# echo $PATH

This will output the PATH stored in the $PATH variable. If you simply wish to add an additional directory, simply do something like this:

# export PATH=$PATH:/the/directory/you/want/to/add

Then type echo $PATH to view the results and to make sure everything worked out. However, you should know that this is only temporarily set for the current terminal/instance you are logged into. If you want this path to always be set then you will want to edit the.bash_profile file which should be located in your home directory. Edit the.bash_profile with your favorite editor. For example:

#vi /home/myusername/.bash_profile

Find the line that states PATH=$PATH:$HOME/bin or something similar. And then just add whatever directory you want to have included in the path. For example:

PATH=$PATH:$HOME/bin:/usr/local/bin:/export/mycustomerapps

Save the file and you’re done. The next time you boot up your Linux box or create a new terminal connection, you will have your path set.

Written by Josh R Bellendir, 12/31/2010
For more articles, stories, tutorials, and reviews like these, please check out http://www.jbellendir.com.

Tags: , , , , , , ,

5 Useful Unix DD Command Examples

By Erik Schweigert

dd is a common Unix program whose primary purpose is the low-level copying and conversion of raw data. You can backup whole hard drives, create a large file filled with only zeros, create and modify image files at specific points, and even do conversions to upper case.

To display dd‘s help simply enter:dd command unix linux

$dd –help

Alright, lets get to the juicy stuff.

1. Make an ISO of a your favourite CD just for backing up purposes with dd:

dd if=/dev/cdrom of=/home/erik/myCD.iso bs=2048 conv=sync

Breaking down the commands:

  • if is “input file”, so in this case our cdrom drive at /dev/cdrom
  • of is “output file”, in this case myCD.iso
  • bs is “block size”, in this case 2048 bytes per block
  • conv is for conversion, in this case we are using “sync” which tells DD to execute synchronized input and output, this is needed for the CD-ROM as we want to read a whole block to ensure no data loss occurs.

2. Duplicate one hard disk partition to another hard disk with dd:

dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror

In this case everything is the same as example 1 but our conversion methods states that noerror should be executed, this tells DD to continue after read errors.

3. Fill a file with 1MB of random bytes with dd:

erik@debian:~$dd if=/dev/urandom bs=1024 count=1000 of=fun.bin

1000+0 records in

1000+0 records out

1024000 bytes (1.0 MB) copied, 0.198349 s, 5.2 MB/s

This time I stated that our block size is 1024 bytes, and we are going to make 1000 of them sequentially. I also used the built-in kernel device urandom which provides random bytes.

4. Skip first 128K of input file then write remaining with dd:

dd if=/home/erik/fun.bin skip=128k bs=1 of=/home/erik/fun2.bin

The skip command tells DD to move passed the (in this case) 128k of data infun.bin then write the rest to fun2.bin. This can be handy if you have a large file that needs to be written across more than one partition. For instance, if you had 3 partitions each 128k. You wouldn’t want to write the same 128k to each partition, you would want to write the first 128k to partition 1, then from 128k-256k of the file to partition 2 and so on.

5. Using dd to convert a file to uppercase:

dd if=erik.txt of=erik_up.txt conv=ucase

Finally, we use conv again to do a conversion. In this case we convert with the specifier of ucase.

What is your favourite use of dd?

Erik is an avid Linux user and has experience with a wide variety of Linux/Unix based systems. In his spare time he likes writing software (C/C++/Perl/PHP/BASH/Python) and experimenting with different Linux distributions. He is starting to build a wide variety of articles Unix driven (what a surprise) that hope to inform those just getting into Linux on his website.

http://www.lainoox.com

Tags: , , , , , , , , , , , ,

By Erick M Aqqa

Unix based operating systems like Linux offer a unique approach to join two discrete commands, and generate a new command using the concept of pipe(lines). For example, consider command1|command2. Here, whatever output is generated by the first command becomes the standard input for the second command. We can develop more and more complex Unix command sequences by joining many commands while maintaining input output relationships.

Another more Linux specific example would be ls -l|grep “^d”. This command displays details of only directories of the current working directory, i.e. the output of the ‘ls -l’ command becomes the input to the grep command, which displays only those lines that start with ‘d’ (they are nothing but the details of the files).

ls -l | grep “^d” | wc -l

This command displays number of directories in the given file.

grep “bash$/ etc / passwd | wc -l

This command displays number of users of the machine whose default shell is bash.

cut -t “: “-f 3 / etc / passwd | sort – n | tail – l

This command displays a number which is the largest used UID number in the system. Here, cut command first extracts UID’s of all the users in the system from the /etc / passwd file, and the same becomes input to sort; which sorts these numbers in numerical order and sends to tail command as input which in turn displays the largest number (last one).

tee command

The ‘tee’ command is used to save intermediate results in a piping sequence. It accepts a set of filenames as arguments and sends its standard input to all these files while giving the same as standard output. Thus, use of this in piping sequence will not break up the pipe.

For example, if you want to save the details of the directories of the current working directory while knowing their using the above piping sequence we can use tee as follows. Here, the file xyz will have the details of the directories stored.

ls -l | grep “^d” |tee xyz | wc -l

The following piping sequence writes the number of directories into the file pqr while displaying the name on the screen.

ls -l | grep “^d” | tee xyz | wc -l |tee pqr

cmp command

The cmp utility compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same. If they differ, the byte and line number at which the first difference occurred is reported.

Bytes and lines are numbered beginning with one.

For example, cmp file1 file2

comm command

comm is a command used to compare two sorted files line by line.

Compare sorted files LEFT_FILE and RIGHT_FILE line by line.

-1 suppresses lines that are unique to the left file.

-2 suppress files that are unique to the right file.

-3 suppress lines that appear in both the left file and the right file. For example, comm p1 p2.

A pipe thus helps connect a set of processes, so that the output of one becomes the input of another. It lets a user browse through a large amount of data in a convenient manner.

Linux2Aix is an upbeat Linux blog containing all the latest and the newest Linus news and how-to’s for both amateur and professional Linux lovers

Tags: , , , , , , , , , , , , ,

By Clyde E. Boom

Linux Commands – The great thing about Linux commands is that they are virtually identical from one Linux distribution (version) to another. So the way the real pros do Linux administration is to work at the Linux command line and run Linux command lineLinux commands.

Learning how to run a Linux command can be very difficult for someone new to Linux, so here are some Linux tips that will help you to learn how to use Linux commands when working at the Linux command line prompt.

There are three main parts of a Linux command:

1. The Linux command name

2. Options that can be used with the Linux command

3. The “item(s)” that the Linux command is being run “on”

When you run a Linux command, spaces are used between: the Linux command name, the command options and the “item” the command is being run “on”. The “item” could be a Linux directory, file, user or some other Linux software component.

For example, you run the Linux command named ls (for list) “on” a Linux directory to see a list of files in the directory. You run the Linux command named rm (remove) “on” a Linux directory to remove the directory from the Linux file system.

To run a Linux command, you type in the name of the command, and any other parts of the command, such as options, and press the Enter key.

You can see an example of the Linux command that is used to create a new Linux user below. The useradd command is being run “on” the bthatcher user name to create this Linux user.

Linux Tips: Linux commands are run at the Linux command line prompt and this prompt is shown as ]# at the left of the command. You don’t type in the prompt, you type the Linux command at the right of the prompt.

Linux Tips: The Linux command prompt may also appear as: ]$ or as another symbol, instead of # or $.

]# useradd -c “Becky Thatcher” bthatcher

This Linux command creates a new Linux user named bthatcher with the full name of “Becky Thatcher”. The -c (for comment) option is used with this command to add the full name as a comment to the Linux user name of bthatcher.

One of the easiest and best ways to get Linux training is to see Linux commands being run in Linux video tutorials. With this method – you see, hear and do.

With a Linux video tutorial, you see and hear how to run a Linux command and see and hear a description of the output of the command. You can also pause the video so you can run the Linux command yourself!

Copyright ©  Clyde Boom

Clyde Boom, Author and Expert Trainer with 20+ Years of Training Successes. Explains intricate technical matters in an easy-to- understand, non-technical manner, with tens of thousands of software and hardware learners into masters.

You can watch Free Sample I Learn Linux Video Tutorials at http://www.iLearnLinux.com and get over the steep Linux learning curve.

Sign up for Free I Learn Linux News to receive technical tips, info on new video samples and important updates on Linux.

You need to learn Linux the easy way to get that new job, qualify for that next promotion, earn a hefty raise, get Linux certification, or keep your current job because your company is trying to save on software licensing fees (eza). Watch, do, and learn!

Tags: , , , , , , , , , , ,
« Previous posts Back to top