Throughout this guide, /dev/sda
will be referred to as the old drive and /dev/sdb
will be referred to as the new drive. If possible, I suggest disconnecting all other disks attached to the system while performing this maintenance.
apt-get install mdadm rsync
sfdisk -d /dev/sda | sfdisk /dev/sdb
sfdisk --change-id /dev/sdb 1 DA # change partition-type to, "0xDA" aka "non-fs data" as "linux raid auto" is deprecated
mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1 # md/v1.x metadata okay if grub-pc version is 1.98+20100720-1 or later [3]
mkfs.ext4 /dev/md0
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
dpkg-reconfigure mdadm
mkdir /tmp/destroot
mount /dev/md0 /tmp/destroot
rsync -auHxv --exclude=/proc/* --exclude=/sys/* --exclude=/tmp/* /* /tmp/destroot/
mount -o bind /dev /tmp/destroot/dev
mount -t proc none /tmp/destroot/proc
mount -t sysfs none /tmp/destroot/sys
chroot /tmp/destroot /bin/bash
update-initramfs -u -k all
rm /boot/grub/device.map
update-grub
grub-install /dev/sda
grub-install /dev/sdb
blkid /dev/md0 # replace UUID line in /etc/fstab (in chroot)
exit
reboot # Pivot bios boot order to boot to new drive (/dev/sdb)
mount | grep $(blkid -o value /dev/md0 | head -n1) # verify booted from "/dev/md0".
sfdisk --change-id /dev/sda 1 DA # change partition-type to, "0xDA" aka "non-fs data" as "linux raid auto" is deprecated
mdadm /dev/md0 -a /dev/sda1
watch -n1 cat /proc/mdstat
7. Test booting off of the old drive (/dev/sda). Simulate failure by disconnecting new drive (/dev/sdb).
poweroff # Verify bios boot to old drive (/dev/sda). Preferably BIOS handles this failover automatically.
mount | grep $(blkid -o value /dev/md0 | head -n1) # verify booted from "/dev/md0".
poweroff
mdadm /dev/md0 -a /dev/sdb1
watch -n1 cat /proc/mdstat
9. Test booting off of the new drive (/dev/sdb). Simulate failure by disconnecting old drive (/dev/sda).
poweroff # Verify bios boot to "/dev/sdb". Preferably BIOS handles this failover automatically.
mount | grep $(blkid -o value /dev/md0 | head -n1) # verify booted from "/dev/md0".
poweroff
mdadm /dev/md0 -a /dev/sda1
watch -n1 cat /proc/mdstat
reboot
mount | grep $(blkid -o value /dev/md0 | head -n1) # verify booted from "/dev/md0"
- http://feeding.cloud.geek.nz/2011/03/setting-up-raid-on-existing.html
- http://wiki.xtronics.com/index.php/Raid
- http://www.debian.org/releases/stable/i386/release-notes/ch-information.en.html#mdadm-metadata
- https://raid.wiki.kernel.org/index.php/RAID_Boot
- https://raid.wiki.kernel.org/index.php/Growing#Extending_an_existing_RAID_array