# http://www.debian-administration.org/articles/238 # # /dev/sda == original drive with data # /dev/sdb == new 2nd drive. # apt-get install mdadm # Ansers during install: # Arrays needed to boot system: # all # Should mdadm run monthly redundancy checks of the MD arrays? # yes # Do you want to start the MD monitoring daemon? # yes # Recipient for email notifications: # 5103053800@mobile.mycingular.com # Config file: /etc/mdadm/mdadm.conf # change the system types on partitions to fd sfdisk -l /dev/sda # Device Boot Start End #cyls #blocks Id System # /dev/sda1 * 0+ 11 12- 96358+ 83 Linux # /dev/sda2 12 38672 38661 310544482+ 83 Linux # /dev/sda3 38673 38912 240 1927800 82 Linux swap / Solaris # /dev/sda4 0 - 0 0 0 Empty # # change partion type of sda1 and sda2 to fd # fdisk /dev/sda p t 1 fd # Linux raid auto 2 fd # Linux raid auto w # List sfdisk -l /dev/sda # Device Boot Start End #cyls #blocks Id System # /dev/sda1 * 0+ 11 12- 96358+ fd Linux raid autodetect # /dev/sda2 12 38672 38661 310544482+ fd Linux raid autodetect # /dev/sda3 38673 38912 240 1927800 82 Linux swap / Solaris # /dev/sda4 0 - 0 0 0 Empty # use sfdisk to duplicate partitions from old drive to new drive: sfdisk -d /dev/sda | sfdisk /dev/sdb sfdisk -l /dev/sdb # Device Boot Start End #cyls #blocks Id System # /dev/sdb1 * 0+ 11 12- 96358+ fd Linux raid autodetect # /dev/sdb2 12 38672 38661 310544482+ fd Linux raid autodetect # /dev/sdb3 38673 38912 240 1927800 82 Linux swap / Solaris # /dev/sdb4 0 - 0 0 0 Empty # Load raid1 module modprobe raid1 echo 'raid1' >> /etc/modules # Create device nodes mknod /dev/md0 b 9 0 mknod /dev/md1 b 9 1 # create the raid arrays. mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdb1 mdadm --create /dev/md1 --level 1 --raid-devices=2 missing /dev/sdb2 cat /proc/mdstat # # Personalities : [raid1] # md1 : active raid1 sdb2[1] # 310544384 blocks [2/1] [_U] # # md0 : active raid1 sdb1[1] # 96256 blocks [2/1] [_U] # # unused devices: # # create filesystems for the raid devices. mkfs.ext3 /dev/md0 mkfs.reiserfs /dev/md1 # make mount points # mount the file systems # copy over the data # umount /boot mkdir /mnt/md1 mount /dev/md1 /mnt/md1 cp -dpRx / /mnt/md1 mkdir /mnt/md0 mount /dev/sda1 /boot/ rsync -az /boot/ /mnt/md0 ln -s ./ /mnt/md0/boot umount /boot # Make swap partition mkswap -v1 /dev/sdb3 # # Edit /mnt/sdb2/etc/fstab # sed -i -e 's/sda1/md0/' -e 's/sda2/md1/' /mnt/md1/etc/fstab echo '/dev/sdb3 none swap sw,pri=1 0 0' >> /mnt/md1/etc/fstab # Should look like this at the end. # /dev/md1 / reiserfs notail 0 1 # /dev/sda3 none swap sw,pri=1 0 0 # /dev/sdb3 none swap sw,pri=1 0 0 # The "pri=1" for each of the swap partitions makes them the same # priority so the kernel does striping and that speeds up vm. # # Edit Grub on the mirror # vi /mnt/md0/grub/menu.lst # ############################################################# # RAID1 Config ############################################################# title Debian GNU/Linux, kernel 2.6.18-4-686 ( RAID1 ) root (hd0,0) kernel /vmlinuz-2.6.18-4-686 root=/dev/md1 md=0,/dev/sda1,/dev/sdb1 ro initrd /initrd.img-2.6.18-4-686 savedefault title Debian GNU/Linux, kernel 2.6.18-4-686 ( RAID1 Recovery ) root (hd0,0) kernel /vmlinuz-2.6.18-4-686 root=/dev/md1 md=0,/dev/sdb1 ro single initrd /initrd.img-2.6.18-4-686 savedefault ############################################################## # # Install grub on the second drive so if the first drive fails we can still boot. # # grub-install --no-floppy --root-directory=/mnt/hdc1 /dev/hdc grub-install --no-floppy --recheck /dev/sdb grub --no-floppy grub grub: device (hd0) /dev/sdb grub: root (hd0,0) grub: setup (hd0) grub: quit grub-install --no-floppy --root-directory=/mnt/md0 /dev/sdb grub-install --no-floppy --root-directory=/mnt/md0 /dev/sda # /dev/sdb does not have any corresponding BIOS drive. grub-install --recheck /dev/sdb grub-install --no-floppy --recheck grub-install --no-floppy /dev/sda grub --no-floppy # # Copy grub and fstab to old system. # mount /dev/sda1 /boot cp /boot/grub/menu.lst /boot/grub/menu.lst.non_raid cp /etc/fstab /etc/fstab.non_raid cp /mnt/md1/etc/fstab /etc/fstab cp /mnt/md0/grub/menu.lst /boot/grub/menu.lst