Perl module to interface with S.M.A.R.T. on Linux

I have released a Perl module (Disk::SMART) to interface with smartctl on Linux. This module will return health values for the specified device(s) as will as the result of a short offline test. It can be found on GitHub or through CPAN. If you have any ideas to make it better please contact me with your idea, or download the code and make the changes, then create a pull request on github.

cPanel dynamic DNS update script

I have released a Perl script that you can run through cron that will do dynamic DNS updates to a cPanel hosted domain. It can be run through cron and will update an entry on a cPanel DNS zone when the internet facing IP of the machine running the script changes. This script is useful for people who have a cPanel account hosting their domain name and want to have an entry like home.domain.tld pointing to their DHCP home network IP (like me!). It will accept an IP as one of the parameter values, or it will autodetect the internet facing IP. You can find at, or the raw download here.

How to replace drives in software raid 1 and grow the filesystem on CentOS

In my setup I have two drives, /dev/sda and /dev/sdb with three partitions each. The first partition is /, the 2nd is swap, and the third is home. You may need to adjust things below for your setup if different.

1. On the booted system the first thing is to remove the 2nd drive from the array, remember your may have more or less partitions to have to remove than me, but the thing to remember is to map the md device number with the partition number like below:

mdadm -f /dev/md0 /dev/sdb1
mdadm -r /dev/md0 /dev/sdb1
mdadm -f /dev/md1 /dev/sdb3
mdadm -r /dev/md1 /dev/sdb3

2. Next shut down the server, replace 2nd drive with the new drive, boot server.

3. Next copy the parition table from the 1st drive to the new drive. You can do this manually but the easiest way is to do it with dd:

dd if=/dev/sda of=/dev/sdb bs=512 count=1

4. In my setup, the third partition is the last partition and the one that can be grown once the drives ae replaced. I changed the size of the last partition by using fdisk to delete sdb3 and recreate it with the max space and type ‘fd’ for raid auto-detect. Now the problem is that the partition device files haven’t been created in /dev yet (e.g. /dev/sdb1). The easiest way to create these is to use fdisk and the ‘w’ option to write out the paritition table, then q to exit.

5. Now you need to add the new drive’s partitions to the raid array, remembering again to correctly map the drive partition numbers to the raid araray device number:

mdadm --add /dev/md0 /dev/sdb1
mdadm --add /dev/md1 /dev/sdb3

Then Verify raid is rebuilding with:

cat /proc/mdstat

6. Once teh sync finishes you need to install the grub boot loader on the new drive:

grub-install /dev/sdb

7. The shutdown server, move the new drive to the primary position and replace the 2nd original drive with the 2nd new drive.

8. Repeat the copy of the parition table like we did earlier:

# You won’t have to remove/create any partitions if you’re using two of the same drive, however you will need to go into fdisk and do ‘w to write changes so the device files in /etc are created correctly for /dev/sdb.
dd if=/dev/sda of=/dev/sdb bs=512 count=1
fdisk /dev/sdb

9. If you have swap partitions on your drives then those need to be formatted for swap and enabled:

mkswap /dev/sda2
mkswap /dev/sdb2
swapon /dev/sda2
swapon /dev/sdb2

10. Now add the new 2nd drive’s partitions to the raid array and verify the raid is rebuilding:

mdadm --add /dev/md0 /dev/sdb1
mdadm --add /dev/md1 /dev/sdb3
cat /proc/mdstat

11. Install the grub boot loader on the new 2nd drive:

grub-install /dev/sdb

12. Now, you need to grow the array to use the rest of the space on the new drives, again you can use cat /proc/mdstat to keep an eye on the sync process that will happen again.

mdadm --grow /dev/md1 --size=max
cat /proc/mdstat

13. Next you resize the filesystem in order for your fs (ext2, ext3, ext4, etc..) to use the space.

resize2fs /dev/md1

Clearing Linux’s Memory Cache

I saw the following command today posted on a Linux related website:

sudo sh -c “sync; echo 3 > /proc/sys/vm/drop_caches”

While yes, it will clear the memory cache, I question the wisdom of doing this. Linux has really good memory and cache management already, swapping pages in and out as needed. If your system is running low on physical memory it will appropriate memory back from the cache as needed. In 14 years of using Linux I’ve never felt the need to clear the cache.

Fixing Laptop re-suspend issue in Fedora 18

I recently switched to Fedora 18 with XFCE and couldn’t be happier. I did have a hiccup on my Dell laptop. It would suspend when I closed the lid but when opening the lid it would unsuspend and quickly re-suspend again. To fix it I edited /etc/systemd/logind.conf and changed “#HandleLidSwitch=suspend” to “HandleLidSwitch=ignore”.

Recipes for Linux