Gentoo Linux x86 with Software Raid and LVM2 Quick Install Guide yes /dev/md3 Steven Wagner The Quick Install guide covers the Gentoo install process in a non-verbose manner. Its purpose is to allow users to perform a stage3 install with software RAID and LVM2 in no time. Users should already have prior experience with installing Gentoo Linux if they want to follow this guide. 18 2011-05-09 Introduction

This guide contains all commands you should use to complete a stage3 installation including LVM2 on top of software RAID. This guide is targeted at experienced users. You need a connection to the Internet to download the stage3 and Portage snapshots.

New users should read the Handbook as it gives a better overview about the installation process. The Quick Install guide is designed for experienced users who just need a checklist to follow.

Timing output follows all commands that take more than a couple of seconds to finish. Commands were timed on an AMD 2000 1.66 Ghz PC with 512 Mb of RAM and two SATA disks connected to a hardware controller configured as JBOD (i.e. two separate hard disks are seen by Gentoo). If you have a "hardware" RAID controller on your motherboard, it is most likely not a hardware controller.

(The following specs and the timing information should help you determine
a rough estimate of the time you need to complete your install)

# grep bogo /proc/cpuinfo
bogomips       : 3337.81

# hdparm -tT /dev/sda /dev/sdb
/dev/sda:
reads:   1048 MB in  2.00 seconds = 524.00 MB/sec
 Timing buffered disk reads:  152 MB in  3.01 seconds =  50.50 MB/sec

/dev/sdb:
 Timing cached reads:   1048 MB in  2.00 seconds = 524.00 MB/sec
 Timing buffered disk reads:  152 MB in  3.01 seconds =  50.50 MB/sec

# grep MemTotal /proc/meminfo
MemTotal:       509248 kB
Quick Install Guide
Preparing the Disks

Load the software RAID and LVM2 modules.

livecd ~ # modprobe raid0
livecd ~ # modprobe raid1
(raid5, raid6 and raid10 are also available)

livecd ~ # modprobe dm-mod

Use fdisk or cfdisk to create your partition layout. The device names are likely to be either /dev/sda and /dev/sdb for a SATA or SCSI disks, or /dev/hda and /dev/hdb for IDE disks. The following layout will be used in this guide:

Raid-1 (mirroring)Normal partitionsRaid-1 (mirroring)Raid-0 (striped)
/dev/sda /dev/sdb Type
/dev/md1 /boot /boot
swap swap
/dev/md3 / /
/dev/md4 LVM2 volumes
The partition you boot from must not be striped. It may not be raid-5 or raid-0. On the one hand, if you want extra stability, consider using raid-1 (or even raid-5) for your swap partition(s) so that a drive failure would not corrupt your swap space and crash applications that are using it. On the other hand, if you want extra performance, just let the kernel use distinct swap partitions as it does striping by default.
livecd ~ # fdisk /dev/sda
(Make sure you use type fd and set the bootable flag)

(The rest of this guide uses the following partitioning scheme)
livecd ~ # fdisk -l /dev/sda

Disk /dev/sda: 299.9 GB, 299989204992 bytes
255 heads, 63 sectors/track, 36471 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          11       88326   fd  Linux raid autodetect
/dev/sda2              12          61      401625   82  Linux swap / Solaris
/dev/sda3              62         311     2008125   fd  Linux raid autodetect
/dev/sda4             312       36471   290455200   fd  Linux raid autodetect

(Partition the second disk exactly as the first)
livecd ~ # fdisk /dev/sdb

Then create the RAID device nodes and devices. Please bear in mind that the /boot and / mount points should use an older metadata format which can be specified by the --metadata=0.90 flag:

livecd ~ # mknod /dev/md1 b 9 1
livecd ~ # mknod /dev/md3 b 9 3
livecd ~ # mknod /dev/md4 b 9 4

livecd ~ # mdadm --create /dev/md1 --level=1 --raid-devices=2 --metadata=0.90 /dev/sda1 /dev/sdb1
mdadm: array /dev/md1 started.
livecd ~ # mdadm --create /dev/md3 --level=1 --raid-devices=2 --metadata=0.90 /dev/sda3 /dev/sdb3
mdadm: array /dev/md3 started.
livecd ~ # mdadm --create /dev/md4 --level=0 --raid-devices=2 /dev/sda4 /dev/sdb4
mdadm: array /dev/md4 started.

(Wait until all units are ready)
livecd ~ # cat /proc/mdstat
Personalities : [raid0] [raid1]
md4 : active raid0 sdb4[1] sda4[0]
581006592 blocks 64k chunks

md3 : active raid1 sdb3[1] sda3[0]
1959808 blocks [2/2] [UU]

md1 : active raid1 sdb1[1] sda1[0]
88256 blocks [2/2] [UU]

Then create the LVM2 volumes in /dev/md4. The following scheme is used as an example:

/usr8 GBext3/usr/portage2 GBext2, small block size, many inodes/usr/portage/distfiles4 GBext2, large block size, less inodes/home10 GBext3/opt4 GBext3/var4 GBext3/var/tmp6 GBext2/tmp2 GBext2
Directory Size File system
livecd ~ # vgscan
  Reading all physical volumes.  This may take a while...
  No volume groups found
livecd ~ # vgchange -a y
  No volume groups found

(Create physical volumes, we have only one in our example)
livecd ~ # pvcreate /dev/md4
  Physical volume "/dev/md4" successfully created

(Create volume groups, again, we have only one in our example)
livecd ~ # vgcreate vg /dev/md4
  Volume group "vg" successfully created

(Create logical volumes)
livecd ~ # lvcreate -L8G -nusr vg
  /dev/cdrom: open failed: Read-only file system
  Logical volume "usr" created (Further similar messages not displayed)
livecd ~ # lvcreate -L2G -nportage vg
livecd ~ # lvcreate -L4G -ndistfiles vg
livecd ~ # lvcreate -L10G -nhome vg
livecd ~ # lvcreate -L4G -nopt vg
livecd ~ # lvcreate -L4G -nvar vg
livecd ~ # lvcreate -L6G -nvartmp vg
livecd ~ # lvcreate -L2G -ntmp vg

(Display volume groups and logical volumes)
livecd ~ # vgs
  VG   #PV #LV #SN Attr  VSize   VFree
  vg     1   8   0 wz--n 554.09G 514.09G
livecd ~ # lvs
  LV        VG   Attr   LSize  Origin Snap%  Move Copy%
  distfiles vg   -wi-a-  4.00G
  home      vg   -wi-a- 10.00G
  opt       vg   -wi-a-  4.00G
  portage   vg   -wi-a-  2.00G
  tmp       vg   -wi-a-  2.00G
  usr       vg   -wi-a-  8.00G
  var       vg   -wi-a-  4.00G
  vartmp    vg   -wi-a-  6.00G

Use mke2fs, mke2fs -j, mkreiserfs, mkfs.xfs and mkfs.jfs to create file systems. Initialize swap using mkswap and swapon.

(ext2 is all you need on the /boot partition)
livecd ~ # mke2fs /dev/md1

(Let's use ext3 on the root partition)
livecd ~ # mke2fs -j /dev/md3

(Create file systems on logical volumes)
livecd ~ # mke2fs -b 4096 -T largefile /dev/vg/distfiles
livecd ~ # mke2fs -j /dev/vg/home
livecd ~ # mke2fs -j /dev/vg/opt
livecd ~ # mke2fs -b 1024 -N 200000 /dev/vg/portage
livecd ~ # mke2fs /dev/vg/tmp
livecd ~ # mke2fs -j /dev/vg/usr
livecd ~ # mke2fs -j /dev/vg/var
livecd ~ # mke2fs /dev/vg/vartmp

(Create and activate swap)
livecd ~ # mkswap /dev/sda2 && mkswap /dev/sdb2
livecd ~ # swapon -p 1 /dev/sda2 && swapon -p 1 /dev/sdb2
(Check that all swap partitions use the same priority)
livecd ~ # swapon -v -s
Filename                   Type            Size    Used    Priority
/dev/sda2                  partition       401616  0       1
/dev/sdb2                  partition       401616  0       1

Mount the freshly created file systems on /mnt/gentoo. Create directories for the other mount points and mount them too.

livecd ~ # mount /dev/md3 /mnt/gentoo
livecd ~ # cd /mnt/gentoo
livecd gentoo # mkdir boot home usr opt var tmp
livecd gentoo # mount /dev/md1 /mnt/gentoo/boot
livecd gentoo # mount /dev/vg/usr /mnt/gentoo/usr
livecd gentoo # mount /dev/vg/home /mnt/gentoo/home
livecd gentoo # mount /dev/vg/opt /mnt/gentoo/opt
livecd gentoo # mount /dev/vg/tmp /mnt/gentoo/tmp
livecd gentoo # mount /dev/vg/var /mnt/gentoo/var
livecd gentoo # mkdir usr/portage var/tmp
livecd gentoo # mount /dev/vg/vartmp /mnt/gentoo/var/tmp
livecd gentoo # mount /dev/vg/portage /mnt/gentoo/usr/portage
livecd gentoo # mkdir usr/portage/distfiles
livecd gentoo # mount /dev/vg/distfiles /mnt/gentoo/usr/portage/distfiles

(Set proper perms on tmp directories)
livecd gentoo # chmod 1777 /mnt/gentoo/tmp /mnt/gentoo/var/tmp
Kernel Configuration

Install a kernel source (usually gentoo-sources), configure it, compile it and copy the arch/i386/boot/bzImage file to /boot.

livecd etc # time emerge gentoo-sources

real  3m3.110s
user  1m2.320s
sys   0m34.990s
livecd etc # cd /usr/src/linux
livecd linux # make menuconfig

(Configure your kernel as usual and make sure the raid and lvm modules you need are
compiled in, i.e. not as modules. The same applies to the disk drivers and filesystems.)
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)

livecd linux # time make -j2

(Elapsed time depends highly on the options you selected)
real  5m5.869s
user  4m32.320s
sys   0m32.930s

livecd linux # make modules_install
livecd linux # cp arch/i386/boot/bzImage /boot/kernel
Reboot

Exit the chrooted environment, unmount all file systems and reboot:

livecd conf.d # exit
livecd / # umount -l /mnt/gentoo/usr{/portage/distfiles,/portage,}
livecd / # umount -l /mnt/gentoo/dev{/pts,/shm,}
livecd / # umount -l /mnt/gentoo{/usr,/var/tmp,/tmp,/var,/opt,/dev,/proc,/home,/boot,}
livecd / # reboot
(Don't forget to remove the CD)