Title: Howto migrat to Software RAID1 on Debian Subject: Complete notes for converting to software RAID1 on Debian Etch. By: John Stile Date: 2009-01-06 #-------------------------------------- Synopsys: Converting /dev/sda1 /boot /dev/sda2 / /dev/sda3 swap To: /dev/md0 /boot /dev/md1 / /dev/md2 swap using software Raid1 # # Install tools # apt-get install initramfs-tools mdadm rsync # # Load modules # modprobe md modprobe linear modprobe multipath modprobe raid0 modprobe raid1 modprobe raid5 modprobe raid6 modprobe raid10 # # Test that modules are loaded # cat /proc/mdstat Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] unused devices: # # Make sure modues are loaded at boot # echo md >>/etc/modules echo raid1 >>/etc/modules echo linear >>/etc/modules echo multipath >>/etc/modules # # Preparing /dev/sdb, by copying /dev/sda partition geometry to second disk # sfdisk -d /dev/sda | sfdisk /dev/sdb Checking that no-one is using this disk right now ... OK Disk /dev/sdb: 10011 cylinders, 255 heads, 63 sectors/track Old situation: Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sdb1 0 - 0 0 0 Empty /dev/sdb2 0 - 0 0 0 Empty /dev/sdb3 0 - 0 0 0 Empty /dev/sdb4 0 - 0 0 0 Empty New situation: Units = sectors of 512 bytes, counting from 0 Device Boot Start End #sectors Id System /dev/sdb1 * 63 417689 417627 83 Linux /dev/sdb2 417690 156649814 156232125 83 Linux /dev/sdb3 156649815 160826714 4176900 82 Linux swap / Solaris /dev/sdb4 0 - 0 0 Empty Successfully wrote the new partition table Re-reading the partition table ... If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1 (See fdisk(8).) # # verify that the partition tables now match # fdisk -l Disk /dev/sda: 82.3 GB, 82348277760 bytes 255 heads, 63 sectors/track, 10011 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 26 208813+ 83 Linux /dev/sda2 27 9751 78116062+ 83 Linux /dev/sda3 9752 10011 2088450 82 Linux swap / Solaris Disk /dev/sdb: 82.3 GB, 82348277760 bytes 255 heads, 63 sectors/track, 10011 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 26 208813+ 83 Linux /dev/sdb2 27 9751 78116062+ 83 Linux /dev/sdb3 9752 10011 2088450 82 Linux swap / Solaris # # change the partition type of our three partitions on /dev/sdb to Linux raid autodetect: # fdisk /dev/sdb t 1 fd t 2 fd t 3 fd p Device Boot Start End Blocks Id System /dev/sdb1 * 1 26 208813+ fd Linux raid autodetect /dev/sdb2 27 9751 78116062+ fd Linux raid autodetect /dev/sdb3 9752 10011 2088450 fd Linux raid autodetect w # # Remove previous remenents of previous raid # mdadm --zero-superblock /dev/sdb1 mdadm --zero-superblock /dev/sdb2 mdadm --zero-superblock /dev/sdb3 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. ######################################################## # First howto ended here. # Continue from this hwoto: # http://www.debian-administration.org/articles/238 ######################################################## # # Create the raid # mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdb1 mdadm --create /dev/md1 --level 1 --raid-devices=2 missing /dev/sdb2 mdadm --create /dev/md2 --level 1 --raid-devices=2 missing /dev/sdb3 mdadm: array /dev/md2 started. # this means the command was successful # # Make file syste on the raid # mkfs.reiserfs /dev/md0 mkfs.reiserfs /dev/md1 mkswap /dev/md2 # # Mount raid and copy over the contents from / # mount /dev/md1 /mnt mkdir /mnt/boot mount /dev/md0 /mnt/boot rsync -a --exclude /proc/* --exclude /sys/* --exclude /mnt/* / /mnt # # make the missing directories on the raid. # mkdir -p /mnt/{proc,sys/mnt} # # Edit fstab on raid to use the raid devices # vi /mnt/etc/fstab # /etc/fstab: static file system information. # # proc /proc proc defaults 0 0 /dev/md1 / reiserfs defaults 0 1 /dev/md0 /boot reiserfs notail 0 2 /dev/sda3 none swap sw,pri=1 0 0 /dev/sdb3 none swap sw,pri=1 0 0 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 # # Setup the bootloader: # - add an entry to boot using raid # - add an entry to recover if first drive fails. # Add these lines before: # "### BEGIN AUTOMAGIC KERNELS LIST" vi /mnt/boot/grub/menu.lst title Debian GNU/Linux, kernel 2.6.18-6-686 (RAID1) root (hd0,0) kernel /vmlinuz-2.6.18-6-686 root=/dev/md1 md=1,/dev/sda2,/dev/sdb2 ro initrd /initrd.img-2.6.18-6-686 savedefault title Debian GNU/Linux, kernel 2.6.18-6-686 (RAID1)(single-user mode) root (hd0,0) kernel /vmlinuz-2.6.18-6-686 root=/dev/md1 md=1,/dev/sda2,/dev/sdb2 ro single initrd /initrd.img-2.6.18-6-686 savedefault title Debian GNU/Linux, kernel 2.6.18-6-686 (RAID Recovery) root (hd0,0) kernel /vmlinuz-2.6.18-6-686 root=/dev/md1 md=1,/dev/sdb2 ro initrd /initrd.img-2.6.18-6-686 savedefault title Debian GNU/Linux, kernel 2.6.18-6-686 (RAID Recovery)(single-user mode) root (hd0,0) kernel /vmlinuz-2.6.18-6-686 root=/dev/md1 md=1,/dev/sdb2 ro single initrd /initrd.img-2.6.18-6-686 savedefault # # Edit line that controls what debian uses to prepare the kernel grub lines # vi /mnt/boot/grub/menu.lst Change: # kopt=root=/dev/sda2 ro To: # kopt=root=/dev/md1 ro # # Chroot so that you can run the grub install # chroot /mnt/ /bin/bash # # Install grub on the second drive # so if the first drive fails we can still boot. # grub-install /dev/sda grub grub: device (hd0) /dev/sdb grub: root (hd0,0) grub: setup (hd0) grub: quit # leave the chroot exit # # Backup pre-raid stuff and apply changes to main file system # cp -dp /etc/fstab /etc/fstab.pre_raid cp -dp /boot/grub/menu.lst /boot/grub/menu.lst.pre_raid # # Copy in new fstab and menu.lst # cp -dp /mnt/etc/fstab /etc/fstab cp -dp /mnt/boot/grub/menu.lst /boot/grub/ # # create configuration file for manageing the raid with mdadm # mdadm -E --scan > /mnt/etc/mdadm/mdadm.conf vi /mnt/etc/mdadm/mdadm.conf ARRAY /dev/md0 level=raid1 num-devices=2 UUID=5b0c0515:3d74dbc0:6cc4e3f1:5d3c8068 devices=/dev/sda1,/dev/sdb1 ARRAY /dev/md1 level=raid1 num-devices=2 UUID=68af66ae:f75ca8f3:6cc4e3f1:5d3c8068 devices=/dev/sda2,/dev/sdb2 ARRAY /dev/md2 level=raid1 num-devices=2 UUID=5bdc1fea:49016ffd:6cc4e3f1:5d3c8068 devices=/dev/sda3,/dev/sdb3 # # Add my self to the paging list # echo 'MAILADDR ----------@cingularme.com' >> /etc/mdadm/mdadm.conf # # Reboot # reboot # # Check that raid is active # cat /proc/mdstat Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sdb1[1] 208704 blocks [2/1] [_U] md1 : active raid1 sdb2[1] 78115968 blocks [2/1] [_U] md2 : active raid1 sdb3[1] 2088384 blocks [2/1] [_U] unused devices: # # Should see something like this # df -h Filesystem Size Used Avail Use% Mounted on /dev/md/1 75G 2.3G 73G 4% / tmpfs 248M 0 248M 0% /lib/init/rw udev 10M 56K 10M 1% /dev tmpfs 248M 0 248M 0% /dev/shm /dev/md/0 204M 44M 161M 22% /boot # # Add first drive partitions to appropriate raid device # mdadm --add /dev/md0 /dev/sda1 mdadm --add /dev/md1 /dev/sda2 mdadm --add /dev/md2 /dev/sda3 # # mdadm: Cannot open /dev/sda3: Device or resource busy # Swap must be disabled on /dev/sda3 before it can be added to /dev/md2 # If swap isn't on raid, processes will hang when the disk holding the swap partition dies. # so it's a trade off between reliability vs. performance. # # Look at the status # cat /proc/mdstat Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] md0 : active raid1 sda1[0] sdb1[1] 208704 blocks [2/2] [UU] md1 : active raid1 sda2[2] sdb2[1] 78115968 blocks [2/1] [_U] [>....................] recovery = 3.6% (2831104/78115968) finish=21.2min speed=59051K/sec md2 : active raid1 sdb3[1] 2088384 blocks [2/1] [_U] unused devices: # # Put swap on RAID1 # # Edit swap in /etc/fstab /dev/sda2 none swap sw,pri=1 0 0 #/dev/sda3 none swap sw,pri=1 0 0 #/dev/sdb3 none swap sw,pri=1 0 0 # # Trun off swap # swapoff -a # # Make swap on raid device # mkswap /dev/md2 Setting up swapspace version 1, size = 2138501 kB no label, UUID=f558a4ef-c819-4927-aa0b-a01b3ded61e2 # # Add /dev/sda3 to raid device # mdadm --add /dev/md2 /dev/sda3 # # Activeate swap # swapon /dev/md2 # # Fix partition types # fdisk /dev/sda t 1 fd t 2 fd t 3 fd w # # Finished. #