Handy Linux Commands PDF Print E-mail
Written by Michael   
Tuesday, 06 May 2008

Here are some commands in Linux that I've found handy.
I'll continue to post more commands as I find them.

First off,
man
This command can be prefixed infront of another command to give you details on its use.
i.e. >man df
Will tell you what the df command is and how to use it.
Depending on your operating system, you might need to press : followed by q to exit the man command.


df
Displays free disk space on all currently mounted files systems, including mounted nfs shares.
I use it with the -h option which gives human readable sizes, eg 400G instead of 429496729600

ls
Displays a directory listing, similar to the dir command in ms-dos.
I use it with the following options, -ltr and sometimes -ltrh
l
list in long format
t
sorts on date
r
reverses the sort order

Many more soon to come.

top

free

ps

cp

mdadm

I use this command to check the health of my array
mdadm -D /dev/md0
-D meaning to display Details.
and /dev/md0 is the name of my raid array.

This returns the following:

/dev/md0:
Version : 00.90.03
Creation Time : Mon Nov 12 21:56:27 2007
Raid Level : raid5
Array Size : 976767744 (931.52 GiB 1000.21 GB)
Used Dev Size : 488383872 (465.76 GiB 500.11 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Mar 8 14:32:06 2009
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 128K

Rebuild Status : 5% complete

UUID : 90631e50:4e99bd4b:1f24cd7c:4c4a7d9f
Events : 0.16880349

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 33 1 spare rebuilding /dev/sdc1
2 8 49 2 active sync /dev/sdd1

From this you can see my array is in the process of being re-built.
This is because I found that a power connector had slipped off one of the SATA drives.
After locating the drive and re-connecting the cable, I just needed to add the drive back in to the array using the following command.

mdadm /dev/md0 --add /dev/sdc1

I could see that it was sdc1 that needed to be added back in as when I first ran mdadm with the -D option it reported the following at the bottom.

0 0 8 17 0 active sync /dev/sdb1
1 1 0 0 1 faulty removed
2 2 8 49 2 active sync /dev/sdd1
3 3 8 33 3 spare /dev/sdc1

My assumption was that the drive sdc1 was placed as spare due to to power lead coming loose, and then re-connecting (I must fix them in place with a small amount of silicon). I still haven't worked out how to pysically identify which drive, so I re-seated the connections on all drives. My guess is that sda1 = sata connection 1 on the motherboard, sdb1 = sata connection 2 etc etc.

Now if I run this:
watch cat /proc/mdstat
I can see the progress of the array rebuild.
Personalities : [raid5] [raid4]
md0 : active raid5 sdc1[3] sdb1[0] sdd1[2]
976767744 blocks level 5, 128k chunk, algorithm 2 [3/2] [U_U]
[=====>...............] recovery = 28.1% (137507200/488383872) finish=84.1min speed=69512K/sec

unused devices: <none>

I also found this, to speed up the rebuild.which I'm not sure if it is making a noticable difference.
echo 50000 > /proc/sys/dev/raid/speed_limit_min
It appears to raise the lower speed limit on the raid array.

Last Updated ( Sunday, 08 March 2009 )
 
Next >