Boot the System 
When booting make sure the system will boot from CD and insert the Gentoo 2007.0 minimal boot CD, the GUI is good but we have a lot more control for our installation procedures.
To boot the system we need to have 3 options in the boot command:
* docache – This will cache the contents of the CD
* doraid – This will load the RAID kernel modules
* dolvm2 – This loads the logical volume manager kernel modules
gentoo docache doraid dolvm2
When the system is booting accept the default language of US English, this will load the correct keymaps for us to continue.
Network Setup
Most likely our network already loaded correct but to be sure we will run the net-setup command, it is a pretty straightforward dialog based installer.
livecd ~ # net-setup eth0
Setup Remote Access (optional at this point)
For those of you who prefer not to do your work from the an inconvenient location, feel free to start remote access early.
livecd ~ # passwd
livecd ~ # /etc/init.d/sshd start
Setup Filesystems
This will be one of the more complicated parts of the installation procedure, there is a lot of commands that need to be run in the correct sequence.
Load Kernel Modules
The following kernel modules should already be loaded due to our boot options, however, just to be on the safe side we will manually run the commands.
livecd ~ # modprobe raid1
livecd ~ # modprobe dm-mod
Filesystem Scheme
We will be using a fairly standard default scheme for all our systems. The following layout will be mostly suitable for all possible servers, the only exception will be swap which as a general rule of thumb should be twice the size of the available physical memory.
Mount Point Size Partition Type
/boot 100M /dev/sda1 Linux raid autodetect (fd)
swap 1024M /dev/sda2 Linux swap / Solaris (82)
/ 2048M /dev/sda3 Linux raid autodetect (fd)
lvm2 Remaining space /dev/sda4 Linux raid autodetect (fd)
Setup Partitions and RAID
Our next step is to create the disk layout, we will use cfdisk to do this, it is a lot easier to use than fdisk. Once we have the partition layout setup on the primary drive we can go ahead and duplicate it on the second disk, we want to avoid possible mistakes by duplicating it by blocks rather than using cfdisk again.
Next we will create the block devices and setup the raid arrays, the block devices would be setup automatically, however, it is always a good idea to avoid potential problems by doing the task manually just to be certain.
cfdisk /dev/sda (previous scheme)
mkdir /mnt/sda
dd if=/dev/sda of=/mnt/sda/my-sda.mbr count=1 bs=512
sfdisk -d /dev/sda > /mnt/sda/my-sda.sf
dd if=/mnt/sda/my-sda.mbr of=/dev/sdb
sfdisk /dev/sdb < /mnt/sda/my-sda.sf
mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2
mknod /dev/md3 b 9 3
mknod /dev/md4 b 9 4
mdadm –create /dev/md1 –level=1 –raid-devices=2 /dev/sda1 /dev/sdb1
mdadm –create /dev/md2 –level=1 –raid-devices=2 /dev/sda2 /dev/sdb2
mdadm –create /dev/md3 –level=1 –raid-devices=2 /dev/sda3 /dev/sdb3
mdadm –create /dev/md4 –level=1 –raid-devices=2 /dev/sda4 /dev/sdb4
The array builds may take quite a long time and we need it to finish before we can proceed to the next step, we can monitor the build process by watching /proc/mdstat, warning, this can take quite a long time to finish so get a coffee, go for a smoke anything.
livecd ~ # cat /proc/mdstat
”Note”: Technically you don’t have to wait before you start using the RAID, once you’ve finished the above commands and the RAID has written its configuration, it is from that point accessible and perfectly safe to work with, but while it’s striping speed will be diminished significantly. Make your own choice for what is suitable.
Create the logical volumes
The logical volume step is pretty straightforward when you know the processes that are happening, initially we scan and check for any existing volume groups, once again there shouldn’t be any, however, best to be certain, next we enable volume group alterations, then we create our physical volume using /dev/md4 this is a mirrored disk. Finally we do a vgcreate to create our volume group.
Now that we have our volume group created we just need to create the logical volumes, we have a predefined format for this:
* /usr – 8G
* /usr/portage – 2G
* /usr/portage/distfiles – 4G
* /home – 10G
* /opt – 4G
* /var – 4G
* /var/tmp – 6G
vgscan
vgchange -a y
pvcreate /dev/md4
vgcreate vg /dev/md4
lvcreate -L8G -nusr vg
lvcreate -L2G -nportage vg
lvcreate -L4G -ndistfiles vg
lvcreate -L10G -nhome vg
lvcreate -L4G -nopt vg
lvcreate -L4G -nvar vg
lvcreate -L6G -nvartmp vg
lvcreate -L2G -ntmp vg
vgs
lvs
Setup Filesystems
Our next step is to create the filesystems themselves, we are using two different filesystem types, firstly for /tmp, /var/tmp and /boot we are using ext2, ext2 is a very quick filesystem, however, it can be risky since it is not journaled therefore we only use it for filesystems we can afford to loose or in the case of /boot a filesystem that is usually not mounted and therefore not at risk in the event of a power outage.
The second filesystem we use is JFS this is IBM’s journaled filesystem, in total across most benchmarks it averages a higher performance than most other filesystem types, it also has a major advantage that you can set your log device to be on a different physical device than your filesystem, which would aid in recovery in the event of a very serious outage.
mke2fs /dev/md1
mkfs.jfs /dev/md3
mkfs.jfs /dev/vg/distfiles
mkfs.jfs /dev/vg/home
mkfs.jfs /dev/vg/opt
mkfs.jfs /dev/vg/portage
mke2fs /dev/vg/tmp
mkfs.jfs /dev/vg/usr
mkfs.jfs /dev/vg/var
mke2fs /dev/vg/vartmp
mkswap /dev/md2
swapon -p 1 /dev/md2
swapon -v -s
Mount Filesystems
Next we mount all our filesystems so we can proceed with the installation process, it is simple, however, don’t make any mistakes accidentally mounting the the wrong filesystem in the wrong place could lead to serious problems.
mount /dev/md3 /mnt/gentoo
cd /mnt/gentoo
mkdir boot home usr opt var tmp
mount /dev/md1 /mnt/gentoo/boot
mount /dev/vg/usr /mnt/gentoo/usr
mount /dev/vg/home /mnt/gentoo/home
mount /dev/vg/opt /mnt/gentoo/opt
mount /dev/vg/tmp /mnt/gentoo/tmp
mount /dev/vg/var /mnt/gentoo/var
mkdir usr/portage var/tmp
mount /dev/vg/vartmp /mnt/gentoo/var/tmp
mount /dev/vg/portage /mnt/gentoo/usr/portage
mkdir usr/portage/distfiles
mount /dev/vg/distfiles /mnt/gentoo/usr/portage/distfiles
chmod 1777 /mnt/gentoo/tmp /mnt/gentoo/var/tmp
Portage and Stages
Set the System Date
Now we need to ensure our date is set correctly, we do this using the date command:
livecd gentoo # date 112615222007
Stages and Snapshot
Our next step is to get the stage file and the portage snapshots.
cd /mnt/gentoo
links gentoo.org
time tar xjpf stage3*
cd /mnt/gentoo/usr
time tar xjf ../portage-lat*
Setup Environment
Chroot
Now we get to the start of the real installation, we do this by chrooting to our new environment, it is pretty easy to do.
Firstly we mount the proc filesystem on the new mountpoints, and copy our /etc/resolv.conf file across, /etc/resolv.conf is what is used to resolve DNS information, then we change our root to the new root filesystem, finally we update all our libraries and paths to the new filesystems.
cd /
mount -t proc proc /mnt/gentoo/proc
(optional for LILO instead of GRUB install) livecd / # mount -o bind /dev /mnt/gentoo/dev
cp -L /etc/resolv.conf /mnt/gentoo/etc/
chroot /mnt/gentoo /bin/bash
env-update && source /etc/profile
Zone Information
Next we need to set up our zone information, we just need to copy across our correct zone information file.
ls /usr/share/zoneinfo
cp /usr/share/zoneinfo/US/Eastern /etc/localtime
Hostname
Now we need to set up our correct hostname, please remember to substitute the the example name and IP address to the actual name you will be using.
livecd / # nano -w /etc/hosts
(Update 127.0.0.1 to be 127.0.0.1 localhost.localdomain localhost
add 192.168.1.25 subversion.dmm subversion
note change the ip address to the one you are actually using and the hostname
to be the hostname to the name you are using)
Install the Kernel
Installing the kernel can be a very difficult process if you are not sure what you are doing, however, we will make it as easy as possible, by following these simple steps.
livecd etc # emerge gentoo-sources
livecd etc # cd /usr/src/linux
livecd linux # time make -j2
livecd linux # make modules_install
livecd linux # cp arch/i386/boot/bzImage /boot/bzImage
genkernel:
livecd linux # emerge genkernel
livecd linux # genkernel –lvm2 –dmraid –menuconfig all
Configure the System
Edit /etc/fstab
/etc/fstab is where we define all of our filesystems to be used on our new system.
livecd linux # cd /etc
livecd etc # nano -w fstab
/dev/md1 /boot ext2 noauto,noatime 1 2
/dev/md3 / jfs noatime 0 1
/dev/md2 none swap sw,pri=1 0 0
/dev/vg/usr /usr jfs noatime 1 2
/dev/vg/portage /usr/portage jfs noatime 1 2
/dev/vg/distfiles /usr/portage/distfiles jfs noatime 1 2
/dev/vg/home /home jfs noatime 1 2
/dev/vg/opt /opt jfs noatime 1 2
/dev/vg/tmp /tmp ext2 noatime 1 2
/dev/vg/var /var jfs noatime 1 2
/dev/vg/vartmp /var/tmp ext2 noatime 1 2
Configure Network
livecd etc # cd conf.d
livecd conf.d # echo ‘config_eth0=( “192.168.1.25/24″ )’ >> net
livecd conf.d # echo ‘routes_eth0=( “default via 192.168.1.16″ )’ >> net
livecd conf.d # rc-update add net.eth0 default
livecd conf.d # rc-update add sshd default
Setup Root Password
livecd conf.d # passwd
New UNIX password: type_the_password
Retype new UNIX password: type_the_password_again
passwd: password updated successfully
Setup Clock
livecd conf.d # nano -w /etc/conf.d/clock
CLOCK=”EST”
TIMEZONE=”US/Eastern”
CLOCK_SYSTOHC=”yes”
Edit Additional Configuration Files
livecd conf.d # nano -w /etc/rc.conf
EDITOR=”/usr/bin/vim”
livecd conf.d # nano -w /etc/conf.d/rc
RC_PARALLEL_STARTUP=”yes”
RC_BOOTLOG=”yes”
Install System Tools
At the time of writing there was a bug that meant udev had to be uninstalled before mdadm and lvm2 could be installed so we account for this in the documentation, it may be fixed in the future.
emerge –unmerge udev
emerge udev mdadm lvm2
emerge sysklogd vixie-cron
rc-update add sysklogd default
rc-update add vixie-cron default
emerge jfsutils vim showconsole
Configure Bootloader
Install Grub
livecd conf.d # emerge grub
Configure Grub
livecd conf.d # nano -w /boot/grub/grub.conf
default 0
timeout 10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Gentoo
root (hd0,0)
kernel /boot/kernel-genkernel-x86-2.6.29-gentoo-r5 root=/dev/ram0 real_root=/dev/md3 domdadm
initrd /boot/initramfs-genkernel-x86-2.6.29-gentoo-r5
Sometimes it may be necessary to point the kernel to the correct root drive. In this case /dev/md3 by passing it ‘md=3,/dev/sda3,/dev/sdb3′
Setup Grub
livecd conf.d # grub –no-floppy
Probing devices to guess BIOS drives. This may take a long time.
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
Checking if “/boot/grub/stage1″ exists… yes
Checking if “/boot/grub/stage2″ exists… yes
Checking if “/boot/grub/e2fs_stage1_5″ exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 16 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/
grub/menu.lst”… succeeded
Done.
grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0×83
grub> setup (hd1)
grub> quit
(Optional) Use LILO instead of Grub
LILO in theory has better support for RAID boot devices and is a tried and true workhorse of linux bootloaders. Grub has been standardized across most distributions for many years, on the other hand. The differences for our purposes really come down to what is easier to use configuration wise. Grub has many powerful configuration settings compared to LILO, and also configurations can be changed on the fly without updating the MBR. On the other hand, LILO is small and mostly self-contained. This is being documented here in case there are any formal plans to use LILO as standard. For the time being continue to use Grub.
LILO Configuration
LILO Configuration is simple and easy. First edit the lilo.conf file.
/etc/lilo.conf:
boot=/dev/md1
raid-extra-boot=mbr
prompt
timeout=10
default=gentoo
image=/boot/bzImage
label=gentoo
read-only
root=/dev/md3
append=”ro”
After you’ve edited the configuration file run this command:
livecd / # lilo -v
You should see “Added gentoo *” if it worked correctly.
Reboot
We need to reboot now so we use our newly built system for the rest of the steps
exit
umount /mnt/gentoo/usr/portage/distfiles /mnt/gentoo/usr/portage /mnt/gentoo/usr
umount /mnt/gentoo/var/tmp /mnt/gentoo/tmp /mnt/gentoo/var /mnt/gentoo/opt
umount /mnt/gentoo/proc /mnt/gentoo/home /mnt/gentoo/boot /mnt/gentoo
init 6
Post Installation
Configure /etc/make.conf
linux / # vi /etc/make.conf
CFLAGS=”-O2 -mtune=i686 -pipe -fomit-frame-pointer”
CXXFLAGS=”${CFLAGS}”
CHOST=”i486-pc-linux-gnu”
FEATURES=”distcc parallel-fetch userfetch ccache”
MAKEOPTS=”-j2″
USE=”-X acl acpi apache2 bcmath berkdb bzip2 caps cracklib crypt curl emacs
expat ftp gd iconv imap java ldap maildir memlimit mhash mmap mysql nptl
pam pcntl pcre perl posix postgres readline session sharedmem soap sockets
snmp ssl syslog tcpd threads unicode xattr xml”
CCACHE_SIZE=”2G”
CCACHE_DIR=”/var/tmp/ccache”
PORTAGE_ELOG_CLASSES=”warn error log”
PORTAGE_ELOG_SYSTEM=”save”
Update /etc/dispatch.conf
linux / # vi /etc/dispatch.conf
use-rcs=yes
Update System
linux / # emerge distcc ccache
linux / # CCACHE_DIR=”/var/tmp/ccache” ccache -s
linux / # /usr/bin/distcc-config –set-hosts “192.168.1.11 192.168.1.25 localhost”
linux / # emerge –sync
linux / # emerge rcs
linux / # emerge -1 libstdc++-v3
linux / # emerge –newuse -uDav world
linux / # dispatch-conf
Install NTP
linux / # emerge ntp
linux / # vi /etc/ntp.conf
# NOTES:
# – you should only have to update the server line below
# – if you start getting lines like ‘restrict’ and ‘fudge’
# and you didnt add them, AND you run dhcpcd on your
# network interfaces, be sure to add ‘-Y -N’ to the
# dhcpcd_ethX variables in /etc/conf.d/net
# Name of the servers ntpd should sync with
# Please respect the access policy as stated by the responsible person.
#server ntp.example.tld iburst
server
server
server
# you should not need to modify the following paths
driftfile /var/lib/ntp/ntp.drift
#server ntplocal.example.com prefer
#server timeserver.example.org
# Warning: Using default NTP settings will leave your NTP
# server accessible to all hosts on the Internet.
# If you want to deny all machines (including your own)
# from accessing the NTP server, uncomment:
#restrict default ignore
# To deny other machines from changing the
# configuration but allow localhost:
restrict default nomodify nopeer
restrict 127.0.0.1
# To allow machines within your network to synchronize
# their clocks with your server, but ensure they are
# not allowed to configure the server or used as peers
# to synchronize against, uncomment this line.
#
#restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap
linux / # vi /etc/conf.d/ntp-client
NTPCLIENT_OPTS=”-b -u ”
linux / # /etc/init.d/ntp-client start
linux / # rc-update add ntp-client default
linux / # /etc/init.d/ntpd start
linux / # rc-update add ntpd default