The super-quick way to RAID a non-boot linux drive
I’ve found several how-tos on the net for converting a single drive to a raid setup, but they all involved the boot partition, and changing the boot loader, and so on. I’ve got a hardware RAID setup already for the actual OS, but I wanted a cheap raid for dumping low-usage files (like MP3s and backups) to. In retrospect, this is kinda obvious, but here it is anyhow.
I already had a 500 GB SATA drive hung off the mainboard (as /dev/sda - important later). I set it up as a single partition, and used LVM to create four logical volumes (which is completely unimportant, I just wanted to type that.)
So, there’s a way to use LVM to do RAID, but since there was no way to specify which drive the mirror belonged on, I didn’t do it. I don’t trust it to be sensible about where it puts the mirror, as I have encountered systems where two parts of a RAID volume in LVM were on the same physical drive - which then failed. It was on HP-UX, which supposedly has the most robust LVM around, and it still didn’t prevent feet from being shot.
Anyhow, these instructions are a modified and mixed version of other stuff you’ll find on the net. It uses Linux MD for the RAID, and doesn’t require any mucking about in /etc/fstab or the /boot directory.
This assumes that you already have an LVM setup running on your drive, it takes up the whole drive, and you are mirroring to another drive that is the same size. Yes, it ends up copying the data twice, and there’s some risk of loss during the first copy if you have a hardware failure. So, if you don’t have a backup of your data and you lose it, don’t come crying to me. It also assumes that you’ve already got the second drive physically installed but not partitioned.
Without further ado - the method.
Assumptions: The existing drive is on /dev/sda, the volume group is called VolGroup01, the new drive is recognized as /dev/sdb.
- Unmount all the filesystems in the volume group. If you have them shared with NFS or Samba, you will need to stop those services.
- Partition the new drive with
fdisk /dev/sdb
Set the partition type to 0xfd (Linux MD Auto).
- Using mdadm, create the MD device:
mdadm -C /dev/md0 -l 1 -n 2 missing /dev/sdb1
- Create a physical volume for LVM on the MD device:
pvcreate /dev/md0
- Extend the volume group to the new device:
vgextend VolGroup01 /dev/md0
- Move the physical extents to the new drive:
pvmove -v /dev/sda1 /dev/md0
- Wait a long damn while.
- Verify that the extents have moved:
pvdisplay
- If the Free PE and Total PE numbers do not match on /dev/sda1, something has gone wrong. I don’t know how to help you at that point, you’re on your own.
- Remove the old drive from the volume group:
vgreduce VolGroup01 /dev/sda
- Change the type of the partition on /dev/sda1 to 0xfd:
fdisk /dev/sda
- Initiate the repair of the RAID on md0 by adding the old drive into the mirror as a spare:
mdadm /dev/md0 -a /dev/sda1
- You can re-mount the filesystems at this time (and restart NFS and Samba if you stopped them), although access will be slow while rebuilding. You can check the status with
mdadm --detail /dev/md0
- When the State from step 13 shows”clean”, you’re now running with full RAID. Check the man pages for mdadm to see how to get it to inform you if something goes horribly wrong.