As more and more important data resides on my harddisk and jocexperience tells that hard disks like to fail — especially at the worst possible moment — I thougt it was the time to move my whole system onto a RAID1 array.
My current hard disk is a 160GB SATA drive so I bought another 200GB SATA drive for the RAID array. So I also have some spare space for less important stuff.
Basically I was just following the description from here http://www.debianforum.de/wiki/?pag... with the slight modification that I used mdadm instead of the raidtools2 (which aren’t available in Sarge any more)
Okay how to proceed? The main idea to do a on-the-fly migration is to take the new additional hard drive with the same partition table as your current drive and start it as a degraded RAID array. Then copy the data over from one place to the other, boot from the newborn RAID and hotadd the old drive.
- You need RAID support hardwired in your Kernel:
...
Multi-device Support (RAID and LVM)
[x] Raid support
[x] Linear support
[ ] raid-0 (striping) mode
[x] raid-1 (mirroring) mode
[x] raid-4 / raid-5 mode
[x] Multipath I/O support
[ ] Logical volume manager (LVM) support
... - Done that, you need to copy your existing partition table to the new drive. In my case /dev/sda is my current hard disk and /dev/sdb is the new one to build the RAID:
sfdisk -d /dev/sda | sed s/sda/sdb/ > /tmp/sdb
sfdisk -f /dev/sdb < /tmp/sdbYou might want to change the Id=83 field to Id=FD (which is Linux raid autodetect) before writing the partition table to the new disk. If the kernel is unable to reread the partiton table you will have to reboot now. The advantages of "Linux raid autodetect" are that you don’t need a raid config file and the kernel assembles the raid devices upon boot automatically. This can be quite handy if you e.g. plug in another SCSI/SATA controller which messes up the device names, so e.g. the former sda becomes sdg. But then still e.g. /dev/md0 will be the same raid array no matter what the physical disks are named.
- Next it is time to create the RAID arrays
The situation on my hard disk looks as follows:
Device Mount point /dev/sda1 / /dev/sda2 swap /dev/sda3 /home /dev/sda4 /space For each of your partitions you want to have running as RAID1 create an array consisting of two raid disks with one missing (which is the current hard disk with all the data on it)
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missingIf you should encounter messages like: mdadm: error opening /dev/md1: No such file or directory when you try to create several arrays you will have to create the devices on your own using
mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2
...Later on due to the kernel autoconfiguration of the RAID arrays those device nodes will be created automatically. Besides I’ve also found the following interesting udev config sniplet on http://ubuntuforums.org/archive/ind...
/etc/udev/links.conf
M md0 b 9 0
M md1 b 9 1
M md2 b 9 2
M md3 b 9 3
M md4 b 9 4Okay, if the creation of the RAID devices went okay, a cat /proc/mdstat should now look similar like this:
rainer@marvin:~$ cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid5]
md2 : active raid1 sdb3[0]
120021504 blocks [2/1] [U_]
md1 : active raid1 sdb2[0]
995904 blocks [2/1] [U_]
md0 : active raid1 sdb1[0]
9767424 blocks [2/1] [U_]
unused devices: <none> - Once all your data is copied on the new RAID disks, adjust the fstab such that the partitions now point to the appropriate RAID devices. Next edit the lilo.conf and set root=/dev/sda1 to root=/dev/md0 (or whatever it is in your case). Be aware that the boot device (boot=...) must not be changed. Then re-run lilo for the new root disk.
- Now it’s time to cross your fingers and reboot :) If everything went fine, you should now have the same system running as before with the only difference that everything resides now on some /dev/md?
- Finally if you’re sure that you didn’t forget to copy something on the new hard disk, open your favourite partition tool and change the partiton type on the old hard disk to FD and add it to your RAID array using
mdadm /dev/md0 --manage --add /dev/sda1etc.

