Gentoo software raid installation guide

OS Used: Gentoo
First written: 2006
Last updated: Jan 2007

This howto assumes a few things...
1. You have a copy of the Gentoo handbook readily available as I will not cover all the steps involved.
2. You've installed Gentoo before. If not, you might find attempting to do a raid install rather difficult to say the least.

Download, burn and boot the Gentoo install CD. Once it's on the network and able to resolve continue.

Load the required modules.

bash# modprobe raid0
bash# modprobe raid1

Next, create the partition structure you want to use on 1 of the 2 drives.

NOTE: /boot MUST be mirrored (raid1) and can NOT be striped (raid0)

My setup looks like this:

/sda1 + /sdb1 = md1     /boot    raid1
/sda2                    SWAP    none
/sdb2                    SWAP    none
/sda3 + /sdb4 = md4     /        raid1
/sda5 + /sdb5 = md5     /usr     raid0
/sda6 + /sdb6 = md6     /var     raid0
/sda7 + /sdb7 = md7     /opt     raid0
/sda8 + /sdb8 = md8     /tmp     raid0
/sda9 + /sdb9 = md9     /home    raid0

I used quite an in depth partition system. whereby I kept / along with /etc on a raid-1 system so that if I lost a drive along with all my data, at least I don't lose all my configuration.

bash# fdisk -l /dev/sda

Disk /dev/sda: 203.9 GB, 203928109056 bytes
255 heads, 63 sectors/track, 24792 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          24      192748+  fd  Linux raid autodetect
/dev/sda2              25         149     1004062+  82  Linux swap / Solaris
/dev/sda3             150        2581    19535040   fd  Linux raid autodetect
/dev/sda4            2582       24792   178409857+   5  Extended
/dev/sda5            2582        5013    19535008+  fd  Linux raid autodetect
/dev/sda6            5014        6229     9767488+  fd  Linux raid autodetect
/dev/sda7            6230        6837     4883728+  fd  Linux raid autodetect
/dev/sda8            6838        7080     1951866   fd  Linux raid autodetect
/dev/sda9            7081       24792   142271608+  fd  Linux raid autodetect

Once your first disk is partitioned, you can easily copy the partition structure accross to the second drive.

bash# sfdisk -d /dev/sda | sfdisk /dev/sdb

Now create the blocks to mount the raid arrays.

bash# cd /dev
bash# MAKEDEV md

Now create the raid arrays.

bash# mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
bash# mdadm --create --verbose /dev/md3 --level=1 --raid-devices=2 /dev/sda3 /dev/sdb3
bash# mdadm --create --verbose /dev/md5 --level=0 --raid-devices=2 /dev/sda5 /dev/sdb5
bash# mdadm --create --verbose /dev/md6 --level=0 --raid-devices=2 /dev/sda6 /dev/sdb6
bash# mdadm --create --verbose /dev/md7 --level=0 --raid-devices=2 /dev/sda7 /dev/sdb7
bash# mdadm --create --verbose /dev/md8 --level=0 --raid-devices=2 /dev/sda8 /dev/sdb8
bash# mdadm --create --verbose /dev/md9 --level=0 --raid-devices=2 /dev/sda9 /dev/sdb9

Raid-1 arrays take a while to sync. You can follow the progress of the sync by checking /proc/mdstat

bash# cat /proc/mdstat
Personalities : [raid1]
md3 : active raid1 sdb3[1] sda3[0]
      184859840 blocks [2/2] [UU]
      [======>..............]  resync = 33.1% (61296896/184859840) finish=34.3min  speed=59895K/sec

Now that the file system has been create, update the mdadm config file.

bash# mdadm --detail --scan >> /etc/mdadm.conf

Technically you can create the filesystem before the sync is complete, but I didn't.

bash# mke2fs /dev/md1
bash# mke2fs -j /dev/md3
bash# mkreiserfs /dev/md5
bash# mkreiserfs /dev/md6
bash# mkreiserfs /dev/md7
bash# mkreiserfs /dev/md8
bash# mkreiserfs /dev/md9
bash# mkswap /dev/sda2
bash# mkswap /dev/sdb2
bash# swapon -p 1 /dev/sda2
bash# swapon -p 1 /dev/sdb2

Now mount

bash# mount /dev/md3 /mnt/gentoo
bash# cd /mnt/gentoo
bash# mkdir boot usr var opt tmp home
bash# mount /dev/md1 /mnt/gentoo/boot
bash# mount /dev/md5 /mnt/gentoo/usr
bash# mount /dev/md6 /mnt/gentoo/var
bash# mount /dev/md7 /mnt/gentoo/opt
bash# mount /dev/md8 /mnt/gentoo/tmp
bash# mount /dev/md9 /mnt/gentoo/home
bash# mount -t proc none /mnt/gentoo/proc
bash# mount -o bind /dev /mnt/gentoo/dev

Download and extract Stage3 file to /mnt/gentoo
Use a console based browser "links2"

bash# tar xvjpf stage3-*.tar.bz2
...

Now cd to /mnt/gentoo/usr download the latest portage snapshot to the same location and extract.

bash# tar xvjf portage-latest.tar.bz2
...

Copy some files from your livecd environment onto your newly extracted hdd install.

bash# cp -Lfv /etc/resolv.conf /mnt/gentoo/etc/
bash# cp -Lfv /etc/mdadm.conf /mnt/gentoo/etc/

Edit /mnt/gentoo/etc/make.conf (Personally I do this once the system is bootable and then reemerge EVERYTHING effectively making my install a stage-1 install.

Change root

bash# chroot /mnt/gentoo /bin/bash
bash# env-update
>> Regenerating /etc/ld.so.cache...
bash# source /etc/profile
bash# export PS1="(chroot) $PS1"

Follow the Gentoo handbook from here.

When you get to the kernel configuration, be sure to include the following so that your system can boot.

Multi-device support (RAID and LVM)  --->
[*] Multiple devices driver support (RAID and LVM)
  <*>   RAID support
  < >     Linear (append) mode (NEW)
  <*>     RAID-0 (striping) mode
  <*>     RAID-1 (mirroring) mode
  < >     RAID-10 (mirrored striping) mode (EXPERIMENTAL) (NEW)
  < >     RAID-4/RAID-5 mode (NEW)
  < >     RAID-6 mode (NEW)
  < >     Multipath I/O support (NEW)
  < >     Faulty test module for MD (NEW)
  <*>   Device mapper support
  < >     Crypt target support (NEW)
  < >     Snapshot target (EXPERIMENTAL) (NEW)
  < >     Mirror target (EXPERIMENTAL) (NEW)
  < >     Zero target (EXPERIMENTAL) (NEW)
  < >     Multipath target (EXPERIMENTAL) (NEW)
  < >     Bad Block Relocation Device Target (EXPERIMENTAL) (NEW)

/etc/fstab

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.
/dev/md1                /boot           ext2            noauto,noatime  1 2
/dev/md3                /               ext3            noatime         0 1
/dev/sda2               none            swap            sw,pri=1        0 0
/dev/sdb2               none            swap            sw,pri=1        0 0
/dev/md5                /usr            reiserfs        noatime         1 2
/dev/md6                /var            reiserfs        noatime         1 2
/dev/md7                /opt            reiserfs        noatime         1 2
/dev/md8                /tmp            reiserfs        noatime         1 2
/dev/md9                /home           reiserfs        noatime         1 2
/dev/sdd1               /export         reiserfs        noatime         0 0
/dev/cdrom              /mnt/cdrom      audo            noauto,ro       0 0

Be sure to install mdadm and add it to boot runlevel.

(chroot) bash# emerge mdadm
(chroot) bash# rc-update add mdadm boot

GRUB. Very important that you install grub to all the drives in your array

To find which drives to install to

grub> find /boot/grub/stage1
 (hd0,0)
 (hd1,0)
grub>

Install to drive 1

grub> device (hd0) /dev/sda
grub> root (hd0,0)
grub> setup (hd0)

Install to drive 2

grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)

/boot/grub/grub.conf

default 0
timeout 10

title=Gentoo
root (hd0,0)
kernel /boot/vanilla-2.6.21.6 root=/dev/md3