[ -x /sbin/nash ] && echo "raidautorun /dev/md0" | nash –quiet
dd if=/dev/sda of=/dev/sdb bs=512 count=1
and check if it is equal (via fdisk -l /dev/sd[a,b])
echo -e "\nt\n1\nfd\nt\n3\nfd\nw\nx" | fdisk /dev/sdb
echo -e "\nt\n3\nfd\nt\n3\nfd\nw\nx" | fdisk /dev/sdb
Create the degraded softraid devices:
mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md3 --level=1 --raid-devices=2 missing /dev/sdb3
Now we should mirror rootfs to newly created raid (/dev/md0)
mkfs.ext3 /dev/md0
cd / && mount /dev/md0 /mnt && rsync -a --progress --exclude=/sys --exclude=/proc --exclude=/dev/shm --exclude=/dev/pts --exclude=/var/run/sr-mount / /mnt
mkdir /mnt/sys
mkdir /mnt/proc
And prepare system to boot from RAID.
sed -r -i 's,LABEL=root-\w+ ,/dev/md0 ,g' /mnt/etc/fstab
Next, we should fix
initrd to correctly boot from /dev/md0
mkdir /root/initrd && cd /root/initrd
zcat /boot/initrd-`uname -r`.img | cpio -i && cp /lib/modules/`uname -r`/kernel/drivers/md/raid1.ko lib
q="echo Waiting for driver initialization."
sed -r -i "s,^${q}$,\n\necho Loading raid1.ko module\ninsmod /lib/raid1.ko\n${q}\n,g" init
q="resume /var/swap/swap.001"
sed -r -i "s,^${q}$,${q}\necho Running raidautorun\nraidautorun /dev/md0\nraidautorun /dev/md1\nraidautorun /dev/md3,g" init
r=`grep mkroot /root/initrd/init`
sed -r -i "s|^${r}$|${r/sda1/md0}|g" init
You could complete this step by hand using any preffered text editor, VI or nano:
find . -print | cpio -o -c | gzip -c > /mnt/boot/initrd-`uname -r`.img
sed -r -i 's,root=LABEL=root-\w+ ,root=/dev/md0 ,g' /mnt/boot/extlinux.conf
cat /usr/lib/syslinux/mbr.bin > /dev/sdb
cd /mnt && extlinux -i boot/
Next we have to reboot and boot from secondary hard drive (/dev/sdb)
cd ; umount /mnt || umount /dev/md0
sync
reboot
If you made everything correctly after boot you should see that rootfs located on /dev/md0
cd / && mount /dev/sda1 /mnt && rsync -a --progress --exclude=/sys --exclude=/proc --exclude=/dev/shm --exclude=/dev/pts --exclude=/var/run/sr-mount / /mnt
umount /mnt
echo -e "\nt\n1\nfd\nt\n3\nfd\nw\nx" | fdisk /dev/sda
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md3 /dev/sda3
This will cause raid-resync, you could watch it via
watch cat /proc/mdstat
Now we have clean system on softraid :)
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (5)
Commented:
Although there is a typo in adding of the /dev/sda3 into raid, it should be actually /dev/md3 and not /dev/md1 .
So correct line number 4 should look like this:
mdadm -a /dev/md3 /dev/sda3
Author
Commented:Commented:
Commented:
Author
Commented: