Converting an existing system

From Linux Raid Wiki
Revision as of 20:49, 4 October 2016 by Anthony Youngman (Talk | contribs)

Jump to: navigation, search

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. he 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 move your system across to the array, you will add the existing drive to get a fully functional array.

Contents

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' {
      load_video
      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
      else
        search --no-floppy --fs-uuid --set=root ab538350-d249-413b-86ef-4bd5280600b8
      fi
      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

Adding back the old drive

Personal tools