Converting an existing system

From Linux Raid Wiki
Revision as of 22:54, 16 November 2016 by Anthony Youngman (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Back to Setting up a (new) system Forward to A guide to mdadm

Much of the work converting a system is very similar to setting it up. The big question is: are you upgrading all the drives, or are you adding a similar drive to the existing one, and you want to make it a mirror? The approach is similar in both cases. You have read Setting up a (new) system?

Plan your new drive layout, install your new drives, and create the filesystems, mirrors, and lvms the same way as setting up a new system. The only real difference is that if you are only adding one new drive, you haven't got two drives to create your raid, so the command to create the array(s) is slightly different:

mdadm --create /dev/md/root --level=1 --raid-devices=2 /dev/sdb3 missing

Note the use of "missing" in the place of a device to build the array on. This tells mdadm to reserve a place, but that you don't yet have a drive to put there, and it will create the array in degraded mode. Obviously, once you've moved your system across to the array, you will add the existing drive to get a fully functional array.


Do you want to upgrade your distro?

Possibly the easiest way to do this is just upgrade your distro. Your kernel needs to support raid, then just set up the new drive and copy your data across. Disable the old drive by removing the power or data cable, then reboot from an install CD and upgrade instead of messing about with grub.

You then need to make sure that your new drive is moved in front of the old one before you reboot with the old drive in place, and you can add it back in.

If you go down this route, just ignore the section about grub - your install CD will sort out all that for you.

Checking your kernel

The first thing to check is, does your kernel support raid? Most modern distro kernels will support it out-of-the-box. The easy way to check is

anthony@ashdown ~ $ cat /proc/mdstat 
Personalities : [linear] [raid0] [raid1] 
md125 : active raid1 sda3[0] sdb3[1]
      100597632 blocks super 1.2 [2/2] [UU]
md126 : active raid1 sdb4[0] sda4[2]
      100597632 blocks super 1.2 [2/2] [UU]
md127 : active raid1 sdb5[0] sda5[2]
      2694204672 blocks super 1.2 [2/2] [UU]
unused devices: <none>
anthony@ashdown ~ $ 

Look at the "personalities" line - this kernel supports linear, raid0 and raid1. A distro kernel should also support raid4/5/6 - this is gentoo and 4/5/6 wasn't compiled in. If your kernel doesn't support raid, it's easy to download the distro kernel source and compile it in, but you will have to watch out that an update does not remove it again.

Secondly, check your boot configuration. Most distros no longer boot straight into linux, but boot into an initramfs. This is mandatory if you want to boot off a modern superblock. The last few lines of your menuentry in grub.cfg should look something like this:

       echo    'Loading Linux 4.4.6-gentoo ...'
       linux   /boot/vmlinuz-4.4.6-gentoo root=UUID=ab538350-d249-413b-86ef-4bd5280600b8 ro  domdadm
       echo    'Loading initial ramdisk ...'
       initrd  /boot/initramfs-genkernel-x86_64-4.4.6-gentoo

Note the initrd line - if this is missing and your last line is similar to the "linux" line, then your system will not boot off raid. You will need to configure your distro to use an initramfs.

Copying your partitions

(Before you do this, make sure you have edited /etc/default/grub as per the previous page)

This is pretty simple to do. It's best done booted from a rescue CD, but can be done logged in as root if you are the only user. What you do NOT want is processes modifying the data behind your back - beware of daemons running in the background. Format and mount the arrays and copy the data across with cp or rsync.

mkfs.ext4 /dev/md/root
mount /dev/md/root /mnt/newroot
cp -ax / /mnt/newroot

The a option to cp does an absolute copy preserving attributes, links etc, while the x option stops it following mount points.

Installing grub

Now run grub-mkconfig. It should detect your array and come up with a entry something like this. Edit it into your grub.cfg, both the original and on the mirror. Make sure "domdadm" is on the linux boot line.

menuentry 'Gentoo GNU/Linux, with Linux 4.4.6-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.6-gentoo-advanced-ab538350-d249-413b-86ef-4bd5280600b8' {
      insmod gzio
      insmod part_gpt
      insmod diskfilter
      insmod mdraid1x
      insmod ext2
      set root='mduuid/69270eaca840f6e70199064bd5863c5d'
      if [ x$feature_platform_search_hint = xy ]; then
        search --no-floppy --fs-uuid --set=root --hint='mduuid/69270eaca840f6e70199064bd5863c5d'  ab538350-d249-413b-86ef-4bd5280600b8
        search --no-floppy --fs-uuid --set=root ab538350-d249-413b-86ef-4bd5280600b8
      echo    'Loading Linux 4.4.6-gentoo ...'
      linux   /boot/vmlinuz-4.4.6-gentoo root=UUID=ab538350-d249-413b-86ef-4bd5280600b8 ro  domdadm
      echo    'Loading initial ramdisk ...'
      initrd  /boot/initramfs-genkernel-x86_64-4.4.6-gentoo

Now install grub on the mirrored drives.

grub-install /dev/sdb

Booting the new system

Shut down and reboot. You may want to temporarily disconnect the network until you are happy with the new set-up, so that daemons don't get your two versions out of sync. You should be able to select the new grub entry and bring the system up on the mirror. If this works, and you are replacing the original drive, you can now remove it and keep it as a backup.

Adding back the old drive

If you are planning to re-use the old drive, you MUST make sure it is completely wiped. One of the biggest problems with recovering a raid (should you be unfortunate and have a problem) is debris left over from the disk's previous life. My preferred option is

dd if=/dev/zero of=/dev/sda

If you do this it will take a long time on modern drives! But it is secure, and will give you a clean drive. If you don't want to afford the time, then wipe the MBR with

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

and the GPT with gdisk - use the "z" option in the expert menu to wipe all traces of any GPT.

Now set up the old disk the same way as the new, and add the new partitions into the arrays. MAKE SURE that the partitions on the drive you are adding back are the same size or larger than on the new disk, or the array will not expand properly.

mdadm /dev/md/root --add /dev/sda3

This will then cause the new sdb to mirror across onto sda. You can add the "new" partitions to the arrays all at the same time - mdadm will throttle the resync, and if you reboot at any point, the resyncs will be paused and restart when the system is rebooted.

Make sure that you install grub on this drive too!

Back to Setting up a (new) system Forward to A guide to mdadm
Personal tools