Category Archives: Linux Software

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

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”.

Installing Adobe Acrobat Reader on x86_64 Fedora

I recently found myself in a situation where xpdf and evince couldn’t open a PDF document from my great state of Texas, both said to download Adobe Acrobat Reader. The only problem is that there is no 64 bit version of Reader, so the i486 version supplied by Adobe links to all sorts of non 64 bit libraries. After much consternation and ‘rpm -qf <file>’, I was able to get it working by installing a few (hundred..) packages. The following command will install all necessary libraries:

yum install glibc.i686 libxml2.i686 gdk-pixbuf2.i686 gtk2.i686 mesa-libGLU.i686 libidn.i686 pangox-compat.i686 libXt.i686

After that you can install the Adobe Acrobat Reader RPM:

Download from
rpm -ivh AdbeRdr9.5.5-1_i486linux_enu.rpm

Installing Nixnote on Fedora

I’ve recently installed Fedora 18 on my systems after the latest several Ubuntus proved to be incompatible with my laptop. I missed having a good evernote client though. I’ve ran nixnote before and found it quite satisfactory, but it wasn’t available in the Fedora repository. Have no fear though, to install it you would do:

1. Download the RPM at Install with ‘rpm -ivh <downloaded file> –force’   # force is necessary, without it rpm warns about ‘/’ being a conflicting file..
3. Install the older libpng library – ‘yum install libpng12’
4. Install the static openssl – ‘yum install openssl-static’
5. Run nixnote and you can then go to Tools and input your username/password.
6. Go to your desktop settings and configure nixnote to start upon login

Add “open with DOSBox” option in Nautilus

I was looking for a way to add a custom “open with” option so that I could use nautilus to navigate to my game folder then open a .conf file with DOSBox and have it exit when finished. To do that you would create /home/user/.local/share/applications/dosbox.desktop then add the following contents:

[Desktop Entry]
GenericName=DOSBox DOS Emulator
Comment=Play the moldy oldies
Exec=gnome-terminal -e dosbox -conf %U -exit

[Desktop Action Window]
Name=Open a New Window
Exec=gedit --new-window

[Desktop Action Document]
Name=Open a New Document
Exec=gedit --new-window


Adding -exit in the command string enables DOSBox to exit properly when launched this way. I had tried just having "exit" added to the .conf but that didn't actually close the parent window. The reason to execute it from gnome-terminal is two fold, the first reason is that you have a terminal you can see dosbox backend info in case of a problem, the second reason is that when using Unity in Ubuntu if you don't execute through gnome-terminal then you don't get an icon on the launch bar.

Accessing a Windows share from Ubuntu

Before when I had accessed smb shares I had to come up with my own script to umount the shares when rebooting. Step 3 shows  an Ubuntu way of doing the same thing.

sudo update-rc.d -f remove
sudo update-rc.d stop 15 0 6 .

ProxMox VE Virtualization

If you haven’t seen it by now, ProxMox VE is a very nice easy to use virtualization solution based on Debian Linux and KVM/OpenVZ. KVM is used to provide full virtualization where you can take an ISO and make a complete virtual server. OpenVZ is a virtual container solution which essentially provides an OS environment without the overhead of full virtualization. ProxMox has an AJAX based web GUI and is GPL. Other solutions I’ve looked at are segways into their enterprise product, so their community (GPL) version is limited.

Rather than reinvent the wheel here and write up my own tutorial, check out this one at Griffon’s IT Library!

Working with .deb and .rpm packages

To list all packages installed on the system, from a terminal prompt enter:

dpkg -l
rpm -qa

Depending on the amount of packages on your system, this can generate a large amount of output. Pipe the output through grep to see if a specific package is installed:

dpkg -l | grep apache2
rpm -q httpd  or  rpm -qa | grep httpd

To list the files installed by a package, in this case the ufw package, enter:

dpkg -L ufw
rpm -qpl ufw

If you are not sure which package installed a file:

dpkg -S /etc/host.conf
base-files: /etc/host.conf

rpm -qf /etc/host.conf

To show information about an installed package:

dpkg -p {package}
rpm -qi {package}

To show information about a package file:

dpkg -l {package.rpm}
rpm -qpi {package.rpm}
yum info {package}

To show information about an installable package:

apt-cache show {package}
yum list {package}

To see what license an installed package uses:

rpm -qi {package} | grep License

To see what license a downloaded (not installed) package uses:

rpm -qip {package} | grep License

To get a package list so you can install the same packages on a different machine:

For .deb systems:

On first machine:
sudo dpkg -l | egrep -v ‘(rc|Desired|Status,Err|\+\+\+)’ | cut -f3 -d” ” > ~/packagelist

Then transfer ~/packagelist to your second machine to ~/ and you’ll need to setup the same repositories on the second machine as the first.

On second machine:
sudo apt-get install $(cat ~/packagelist)

To get a package list so you can install the same packages on a different machine:

For .deb systems:

On first machine:
sudo dpkg -l | egrep -v ‘(rc|Desired|Status,Err|\+\+\+)’ | cut -f3 -d” ” > ~/packagelist

Then transfer ~/packagelist to your second machine to ~/ and you’ll need to setup the same repositories on the second machine as the first.

On second machine:
sudo apt-get install $(cat ~/packagelist)