Title: Howto Software RAID1 from scratch on Debian. Subject: boot from livecd, create raid1, copy system to raid, and setup grub. # Boot from gentoo livecd 2008.0, set root passwd, generate ssh key, start sshd. boot: gentoo nox passwd root ssh-keygen -t dsa /etc/init.d/sshd start # load modules for raid modprobe md modprobe linear modprobe multipath modprobe raid0 modprobe raid1 modprobe raid5 modprobe raid6 modprobe raid10 # check loaded modules cat /proc/mdstat Personalities : [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] [linear] [multipath] unused devices: # Check partitions on Origninal_System Origninal_System:~# fdisk -l /dev/sda Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 9470 76067743+ fd Linux raid autodetect /dev/sda2 9471 9729 2080417+ fd Linux raid autodetect # Check partitions on New_System fdisk -l /dev/sda Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 * 1 9470 76067743+ 83 Linux /dev/sda2 9471 9729 2080417+ 83 Linux parted -s -- /dev/sda1 set 1 raid on parted -s -- /dev/sda2 set 1 raid on # # change the partition type of our three partitions on /dev/sdb to Linux raid autodetect: # fdisk /dev/sdb t 1 fd t 2 fd p Device Boot Start End Blocks Id System /dev/sda1 * 1 9470 76067743+ fd Linux raid autodetect /dev/sda2 9471 9729 2080417+ fd Linux raid autodetect w # # make sure we are cloned correctly # sfdisk -d /dev/sda | sfdisk /dev/sdb # # Check the partitions # livecd ~ # fdisk -l Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x000bc128 Device Boot Start End Blocks Id System /dev/sda1 * 1 9470 76067743+ fd Linux raid autodetect /dev/sda2 9471 9729 2080417+ fd Linux raid autodetect Disk /dev/sdb: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sdb1 * 1 9470 76067743+ fd Linux raid autodetect /dev/sdb2 9471 9729 2080417+ fd Linux raid autodetect # # Remove previous remenents of previous raid # mdadm --zero-superblock /dev/sda1 mdadm --zero-superblock /dev/sda2 mdadm --zero-superblock /dev/sdb1 mdadm --zero-superblock /dev/sdb2 mdadm: Unrecognised md component device - /dev/sdb1 # This means there is no raid on the device # Otherwise the commands will not display anything at all. # # On Origninal_System the raid is: # cat /pro/mdstat Personalities : [raid1] md1 : active raid1 sda2[0] sdb2[1] 2080320 blocks [2/2] [UU] md0 : active raid1 sdb1[0] sda1[1] 76067648 blocks [2/2] [UU] unused devices: # # Create equivilent raid on New_System # mdadm --create /dev/md0 --level 1 --raid-devices=2 /dev/sda1 /dev/sdb1 mdadm: /dev/sda1 appears to contain an ext2fs file system size=76067740K mtime=Thu Dec 18 10:07:29 2008 mdadm: /dev/sdb1 appears to contain an ext2fs file system size=76067740K mtime=Thu Apr 26 13:34:47 2007 Continue creating array? yes mdadm: array /dev/md0 started. mdadm --create /dev/md1 --level 1 --raid-devices=2 /dev/sda2 /dev/sdb2 mdadm: array /dev/md1 started. # # Make file system on md0 # mkfs.reiserfs /dev/md0 # # Mount file system # mkdir /mnt/md0 mount /dev/md0 /mnt/md0 # # Copy Origninal_System to /mnt/md0 # rsync -avz -e ssh --exclude=lost+found/ --exclude /proc/* --exclude /sys/* root@Origninal_System:/ /mnt/md0 # # Create missing directories (added by john) # mkdir -p /mnt/md0/{proc,sys,mnt} # # Make the swap partition on raid partition # mkswap -v1 /dev/md1 Setting up swapspace version 1, size = 2130243 kB no label, UUID=fe73acd9-2069-4196-9a57-2be627923810 # # Edit fstab from ext3 to reiserfs # vi /mnt/md0/etc/fstab /dev/md0 / reiserfs defaults 0 1 /dev/md1 none swap sw,pri=1 0 0 /dev/hdc /media/cdrom iso9660 ro,user,noauto 0 0 proc /proc proc defaults 0 0 # # Prepare raid configuration # mdadm --examine --scan ARRAY /dev/md0 level=raid1 num-devices=2 UUID=19666703:8e59ff55:cfb11a08:229d8d98 ARRAY /dev/md1 level=raid1 num-devices=2 UUID=6daae446:32daad4c:5792118e:6a074d63 # # Store the UUID's into the raid config file # mdadm --examine --scan >> /mnt/md0/etc/mdadm/mdadm.conf # # Edit, replace old uuid's with new ones # Set the email account in case of a failure # vi /mnt/md0/etc/mdadm/mdadm.conf # Chroot and install grub AND new initrd (or boot won't see raid) # Install grub on the second drive # so if the first drive fails we can still boot. # mount -o bind /proc /mnt/md0/proc chroot /mnt/md0 grub-install /dev/sda grub-install /dev/sdb zcat /usr/share/doc/mdadm/README.upgrading-2.5.3.gz |less rm -f /var/lib/mdadm/CONF-UNCHECKED update-initramfs -k all -u exit # exit chroot umount /mnt/md0/proc # # If this is a clone, but not a replacement machine, # search and replace Origninal_System -> New_System # hostname and IP. # egrep -rl -Dskip 'Origninal_System|192.168.0.50' /mnt/md0/ 2> /dev/null # # If that list looks good, store, search, and replace. # Files=`egrep -rl -Dskip 'Origninal_System|192.168.0.50' /mnt/md0/ 2> /dev/null` sed -i \ -e 's/Origninal_System/New_System/g' \ -e 's/192.168.0.50/192.168.0.51/g' \ $Files # # Udev will store persistant rules for nics based on mac addresses. # This will mess up a clone, so remove them # rm -rf /mnt/md0/etc/udev/rules.d/z25_persistent-net.rules ############################################################## # clone complete # Reboot #############################################################