Move swap partitions off of RAID1 array

After upgrading my new server from Lenny to Squeeze, I noticed that the iWeb default install on this machine had the swap partition on a mirror.  Not that I expect this machine to be doing much swapping, but I figured I should fix it anyways.  To destroy the array and make those partitions “plain” swap partitions, follow these steps:

### find out which array is the swap partition and see who the members are
cat /etc/fstab
cat /proc/mdstat
### fstab told us md1 is the swap partition and xvda5 and xvdb5 are the member partitions in that array
### turn off swap
swapoff -a
### stop the array and delete the superblocks.  without zeroing the superblocks the array will still be auto-assembled at boot and we'll get no swap
mdadm --stop /dev/md1
mdadm --zero-superblock /dev/xvda5
mdadm --zero-superblock /dev/xvdb5
### use fdisk to change the partition types for xvda5 and xvdb5 to "82  Linux swap / Solaris"
fdisk /dev/xvda #(t, 5, 82, w)
fdisk /dev/xvdb #(t, 5, 82, w)
mkswap /dev/xvda5
mkswap /dev/xvdb5
swapon /dev/xvdb5
swapon /dev/xvda5
### take the reference to /dev/md1 out of mdadm.conf (1 less error message at boot)
vi /etc/mdadm/mdadm.conf
### modify fstab - change the reference to /dev/md1 to /dev/xvda5, then add another line for /dev/xvdb5
vi /etc/fstab
### reboot if you want to make sure it's all happy at boot time
reboot

I mainly wanted to do this so that if the swap space is ever actually being used, the system won’t have to mirror every write to the other drive.  I’ve also read that linux is smart enough to distribute writes to swap space between partitions if more than one are available, which makes sense to me but I’d have to confirm that rumor.  This change will potentially cut down on a bunch of CPU usage and IO at some point in the future, and a side benefit to doing this is that we have increased the amount of swap space from 2GB on this system to 4GB.

Still don’t want to ever use it though…  😉

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply to Alex Cancel reply

Your email address will not be published. Required fields are marked *