Archive for May, 2009

Okay so as part of being a Linux sysadmin, I’ve run into the need to rebuild a software RAID (mdadm) array. This process usually takes forever, and in an effort to make sure it won’t take any longer than necessary, I usually leave the volume in question unmounted during the resync/reshape. I know, I know, you can read/write to an array during the process safely, otherwise anaconda (the most superior Linux installer) wouldn’t be able to move forward with the install for a long while. But I still like the reshape to go faster. I’d rather not use the system for an hour and have it be perfectly fast afterwards than have the machine crawl along all day.

Long-winded ideals speech beside, I want to monitor how long the rebuild is going to take in quasi-realtime. Details of the software raid can be found in the file /proc/mdstat. You can cat this file once in a while to see the progress. But that wasn’t ever good enough, too much of that whole keyboard-button-pushing thing in order to get the statistics to update. So I would usually type this in real quick:

while [ 1 ]; do clear; cat /proc/mdstat ; sleep 1; done

It’s just a simple loop that keeps the information fresh on the screen. Well boy did I just find out something today that helps greatly with that dilemma. Enter the Linux “watch” command, courtesy of the procps package. The watch command automatically updates the information on the screen in the command that follows the binary on the shell. For example, the command:

watch cat /proc/mdstat

will update the file exactly like the loop does. But watch does it even better, as it prints a clock in the corner and lets you know how often it is updating. Plus, watch doesn’t make the screen flicker for a millisecond like the shell clear does. The default delay in updating is 2.0 seconds, but you can change that easily via the -n flag. For example, to update every second, as in the custom loop above, try the command:

watch -n 1 cat /proc/mdstat

and be amazed. It would seem at first glance that the delay can be set as low as 0.1 seconds. Pretty neat. It’s an interesting tool, and certainly one that is very useful for these sorts of things. Check out the man page for more information on the command.

STFU!!!

Quick tip. You’re working on setting up a server late at night. It’s dark out. Your roommate is sleeping. And every time you push the damn tab button, the computer makes a beeping sound. WHAT THE HELL?!

Silence the PC Speaker with “rmmod pcspkr”. Make it loud again with “modprobe pcspkr”.

Your roommate will thank me for this… whether he/she knows it or not 😀