$Id: debian_raid1.html,v 1.8 2004/03/18 22:04:22 calicant Exp $

Debian Software RAID-1 (without recompiling) Mini Howto


Copyright (c) 2004 calicant (calicant at ferrara dot linux dot it)
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Some notes to explain how to make a software raid-1 (mirror) in Debian *without* linux kernel recompiling.
We will use a standard debian distribution kernel and a Gentoo live cd to make the raid.
Debian release: sarge net install (testing).
Linux kernel version: 2.4.22


  1. Install a minimal GNU/Linux Debian system

    (e.g. http://www.debian.org/CD/netinst)

    Fig. 1

    Partition table (sda)

    Fig. 2

    Debian fresh install
  2. Install raidtools2 debian package

    Choose to start RAID array automatically on startup beacause we will use the md driver as a module.

    Fig. 3

    raidtools2
  3. Booting Gentoo Live CD...

    http://www.gentoo.org

    Fig. 4

    Gentoo Live CD
  4. Create md devices

    cdimage root # mknod /dev/md0 b 9 0
    cdimage root # mknod /dev/md1 b 9 1
    cdimage root # mknod /dev/md2 b 9 2
    
  5. Create /etc/raidtab

    raiddev /dev/md0
        raid-level 1
        nr-raid-disks 2
        nr-spare-disks 0
        chunk-size 16
        persistent-superblock 1
        device /dev/sda1
        raid-disk 0
        device /dev/sdb1
        raid-disk 1
    
    raiddev /dev/md1 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 chunk-size 16 persistent-superblock 1 device /dev/sda3 raid-disk 0 device /dev/sdb3 raid-disk 1
    raiddev /dev/md2 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 chunk-size 16 persistent-superblock 1 device /dev/sda4 raid-disk 0 device /dev/sdb4 raid-disk 1
  6. Start RAID devices

    cdimage root # mkdraid --really-force /dev/md0
    cdimage root # mkdraid --really-force /dev/md1
    cdimage root # mkdraid --really-force /dev/md2
    

    You can check the completion progress by cat'ing the /proc/mdstat file

    cdimage root # watch cat /proc/mdstat
    
  7. Mount, copy raidtab and chroot debian root

    cdimage root # cdimage root # mkdir -p /mnt/debian
    cdimage root # mount -t ext3 /dev/md0 /mnt/debian
    cdimage root # cp /etc/raidtab /mnt/debian/etc
    cdimage root # chroot /mnt/debian
    cdimage:/# mount -t ext3 /dev/sda1 /boot
    cdimage:/# mount -t ext3 /dev/sda4 /var
    cdimage:/# mount -t proc proc /proc
    
  8. Edit /etc/fstab

    # /etc/fstab: static file system information.
    #
    #                
    /dev/md1        /       ext3    defaults,errors=remount-ro      0 1
    /dev/md0        /boot   ext3    defaults        0 2
    /dev/md2        /var    ext3    defaults        0 2
    /dev/sda2       none    swap    sw      0 0
    /dev/fd0        /floppy auto    rw,user,noauto  0 0
    /dev/hda        /cdrom  auto    ro,user,noauto  0 0
    proc    /proc   proc    defaults        0 0
    
  9. Set root partition via mkinitrd

    cdimage:/# mkinitrd -r /dev/md1 -o /boot/initrd.img-2.4.22-1-386 /lib/modules/2.4.22-1-386/
    
  10. Edit /etc/lilo.conf and run lilo

    boot=/dev/md0
    root=/dev/md1
    raid-extra-boot=mbr-only
    install=/boot/boot.b
    map=/boot/map
    image=/vmlinuz
      label=Linux
      initrd=/initrd.img
    
  11. Unmount, exit chroot and unmount

    cdimage:/# unmount /boot
    cdimage:/# unmount /var
    cdimage:/# unmount /proc
    cdimage root # unmount /mnt/debian
    
  12. Check and resize filesystems

    cdimage:/# e2fsck -f /dev/md0
    cdimage:/# e2fsck -f /dev/md1
    cdimage:/# e2fsck -f /dev/md2
    cdimage:/# resize2fs /dev/md0
    cdimage:/# resize2fs /dev/md1
    cdimage:/# resize2fs /dev/md2
    

    This will generate an error about inconsistent sizes and possibly corrupted superblock. Say N to 'Abort?'.
  13. Stop RAID and reboot

    cdimage:/# raidstop /dev/md0
    cdimage:/# raidstop /dev/md1
    cdimage:/# raidstop /dev/md2
    cdimage:/# reboot
    
  14. Debian RAID-1 up and running


    Fig. 5

    Debian software RAID1
  15. Caveats

    You may encounter filesystem errors in /dev/md0, /dev/md2 at first boots.
    I have had to do:

    debian:~# raidstop /dev/md0
    debian:~# raidstop /dev/md2
    debian:~# mkraid -R /dev/md0
    debian:~# mkraid -R /dev/md2
    debian:~# mount -t ext3 /dev/md0 /boot
    debian:~# mount -t ext3 /dev/md2 /var
    
  16. GNU Free Documentation

    Please, see fdl.txt