Setting up bootable RAID 1 in a safe way By Harakiri - July 06 2005 (updated Feb 16 2006) /// click here for the printable PDF version |
|||
I 've set up this document because there is no recent documentation on how to set up a bootable RAID 1 system (mirror). Or at least it 's hard to find. Using bits and pieces from other documents and a preinstalled Mandrake RAID 1 system on a VMWare, I 've setup this Mini-Howto, which is nothing more than an exemplary procedure for myself, which I 'm glad to share with the rest of the world. 1. Before you begin Compile a kernel with all your necessary device drivers compiled in so you don 't need an initrd. Initrds only complicate life
2. Layout of our disk to mirror Device Boot Start End Blocks Id System This is our /etc/fstab /dev/sda6 / ext2 defaults 1 1
| Sponsored links: |
||
|
-We 're going to mirror /, /boot and /var. The safest way to mirror is to setup a broken mirror and first copy the data to it, boot from it and add the original disk to the mirror, overwriting its data with its own copy. Still with me? Ok, pratically this means copying /, /boot and /var to the other disk, sdb, mounted somewhere as a half mirror. Do this in runlevel 1 so no data changes meanwhile. Next boot from it, sfdisk /dev/sdb to /dev/sda and add the raid partitions from sda to the mirrors. This will copy back the data from sdb paritions to the sda partitions. More on that later on. 3. Get on with mdadm -Zero out any superblock still existing from previous mirror attempts mdadm --zero-superblock /dev/sdb1 mdadm --zero-superblock /dev/sdb6 mdadm --zero-superblock /dev/sdb7 -Copy partition information from sda to sdb using sfdisk sfdisk -d /dev/sda > sda.out Dump layout of sda to a file edit file with vi and replace sda entries by sdb -Change partition types of partitions to mirror with fdisk. This is very important, otherwise Linux won 't boot from it! fdisk /dev/sdb -Set up a broken mirror on /dev/sdb partitions mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing This will start the raid devices. Dump this information to mdadm.conf for later use
I like editing this file manually afterwards. "DEVICE /dev/sda1 /dev/sdb1 /sdev/sda6 /dev/sdb6 /dev/sda7 /dev/sdb7" This will make your kernel complain about missing devices when you restart from your broken mirror, but this way this file is already what it should be -Next, create filesystems on it. I 'm gonna take the opportunity to make them ext3 instead of the original ext2 mkfs.ext3 /dev/md0
4. Offline operations -Better than switching to runlevel 1, boot from a bootable Linux CD that supports raid and your harddisk controller. Make dirs to mount your stuff on mkdir /sda1 -Mount /dev/sda partitions in read-only and copy mdadm.conf from /sda6/etc/mdadm.conf to your current /etc from your bootcd mount -o ro /dev/sda1 /sda1 -Start your RAID devices mdadm -As -Mount your RAID devices mount /dev/md0 /md0 -Copy all your data You can check the progress of this copy in another console with "df" -Once the data is copied, we 're gonna modify the fstab, next lilo The fstab on /md1/etc/ should become something like this: /dev/md1 / ext3 defaults 1 1 5. Lilo The easiest way for lilo not to complain is to chroot to the mounted raid root, but first submount its /boot partition to it umount /md0 -System Rescue CD specific: copy zsh to your soon to be chrooted /bin cp /bin/zsh /md1/bin -Chroot, run bash and edit lilo.conf chroot /md1 -Here 's what the original lilo.conf looks like: # File generated by DrakX/drakboot default="linux" -Here 's the new one: default="linux-md" My newly compiled kernel is called /boot/vmlinuz-2.6.11custom, my boot device is /dev/md0. Now run lilo If your system is unable to boot from a secondary drive from BIOS, copy lilo.conf to lilo.conf.md, remodify lilo.conf, comment out the "raid-extra-boot=mbr" and change boot back to "boot=/dev/sda" I left an old entry in case the new kernel won 't boot from the mirror. 6. Running from a broken mirror and hotadd devices -Restart and boot "linux-md" Your system should be running on a broken raid 1. -Once you 've made sure of that, sfdisk your /dev/sdb information to /dev/sda sfdisk -d /dev/sdb > sdb.out Check with fdisk that /dev/sda contains exactly the same partitions as /dev/sdb -Once you 've done all that, you can add your inactive sda partitions to your running raid1 devices, making your system redundant. mdadm /dev/md0 --add /dev/sda1 Your disks should be synching now. Check the progress in /proc/mdstat -Copy /etc/lilo.conf.md back to /etc/lilo.conf and run lilo again -You might need to initiate the second swap on /dev/sdb5 swapon /dev/sdb5 That 's it, you 're running Linux from RAID 1
|