Wednesday, November 12, 2008

Removing a RAID partition

To remove a RAID device that consists of 2 partitions (sda7 and sdb7) that has an LVM2 VG on top:
- lvremove to remove all LVs
- vgremove to remove all VGs
- pvremove to remove all PVs
- mdadm --stop to stop the device
- mdadm --remove to remove the device
- mdadm --zero-superblock to erase the md superblock on each of the 2 partitions
- update /etc/mdadm.conf to remove the md device

Migrating /tmp to another partition

I decided to remove the 80G RAID-0 partition in my PC, and migrate the data inside to other LVM partitions. Currently, the partition has 1 LVM2 vg which contains 3 lvs. One of them contains files I downloaded and the other 2 are /tmp filesystems in my Slackware and Ubuntu installations respectively. I simply copied the files in the first lv to another lv (non-RAID LVM). For /tmp filesystems, I did the following steps for each of them:

- Create a new lv (RAID-1 LVM) of 4G. (lvcreate)
- Format it as reiserfs. (mkfs.reiserfs)
- Mount it to a temporary mount point.
- Copy files in /tmp over using rsync -av
- Go to single user mode and unmount /tmp
- Edit /etc/fstab to change /tmp to use the new lv.
- Remount /tmp and go into multi-user mode.

Note: the device to be put into fstab should be /dev/<vg>/<lv>, not /dev/mapper/<vg>-<lv>.