Gentoo - base installation guide

By: John McFarlane <john.mcfarlane@rockfloat.com>
Last updated: 04/08/2007 @ 18:53

Abstract:
This document is a simplified version of the official gentoo installation guide, with my personal choices.



1. Download installation media

Download the appropriate installation media: livecd-i686-installer-2006.1.iso
Here are a few solid links for the Cincinnati, Ohio area:
  1. Indiana University
I'm finished with this step

2. Create a bootable cd from the installation media

root# cdrecord dev=/dev/hdc livecd-i686-installer-2006.1.iso
I'm finished with this step

3. Boot from the universal cd

Booting from the universal cd is really straightforward. Stick the cd in, and turn restart your computer. Sometimes you need to update the bios to specify the cdom to boot prior to the disk drive, this prevents the bios from simply skipping the cdrom.
Tip If you're install involves SCSI devices, you need to boot the livecd with the doscsi argument. To do this boot off the livecd as usual, and when you get to the prompt, type: gentoo doscsi.
I'm finished with this step

4. Start sshd if you want to work from another computer

Sometimes it's nice to perform the installation from another computer that has a graphical desktop for reading the documentation. To do this start up sshd:

# passwd
New password: (Enter your new password)
Re-enter password: (Re-enter your password)
# /etc/init.d/sshd start
# ifconfig | grep inet
    	
Now you can connect from another computer using (xterm, rxvt, putty, etc):

user# ssh root@IP-ADDRESS
    	
using the IP address you saw in the previous step, something like 1.2.3.4
Tip If you don't have a "hot" network cable connected, you will not see the network device eth0 in the output of ifconfig. So make sure your network cable is hot before you pull your head out trying to debug network card drivers.
I'm finished with this step

5. Use fdisk to setup your partitions

This is the step where data will be destroyed from your disk. Please stop if you are unsure that you want to continue.

At the console prompt startup fdisk

livecd# fdisk /dev/sda
        
If for some reason fdisk doesn't work (happend to me with the 2005.1 Livecd you might want to try cfdisk. It's a menu driven alternative, it's actually quite nice!

livecd# cfdisk /dev/sda
        
  1. Type p to view the current partitions.
  2. Use d to delete each of the existing partitions
  3. Do each of the following (each has # explanation of command):
    
    n       # Create a new partition
    p       # This is a primary partition
    1       # It's to be the first partition
            # Just hit enter to start at the first cylinder
    +64m    # This partition is to be 64 megs large
    a       # Set the bootable flag
    1       # On the first partition
    
    n       # Create a new partition
    p       # This is a primary partition
    2       # It's to be the second partition
            # Just hit enter to start at the first cylinder
    +512m   # This partition is to be 512 megs large
    t       # Alter the type of this partition
    2       # Select the swap partition
    82      # Set the type to "Linux Swap"
    
    n       # Create a new partition
    p       # This is a primary partition
    3       # It's to be the second partition
            # Just hit enter to start at the first cylinder
            # Just hit enter to take all available space
            
    w       # Write to disk
    q       # Quit to exit fdisk
                    
Now you have a shiney clean disk drive, ready to be formatted (yes, technically there is still data on the drive, it's just inaccessable as the partitions were re-written.
I'm finished with this step

6. Create the file systems on the new partitions


livecd# mkfs /dev/sda1        # Make boot ext2
livecd# mkreiserfs /dev/sda3  # Make root reiserfs
livecd# mkswap /dev/sda2      # Create the swap signature
        
I'm finished with this step

7. Get the disk drive ready for use


livecd# swapon /dev/sda2
livecd# mount /dev/sda3 /mnt/gentoo
livecd# mkdir /mnt/gentoo/boot
livecd# mount /dev/sda1 /mnt/gentoo/boot
livecd# date mmddhhmmyyyy   #Month Day Hour Minute Year
	
I'm finished with this step

8. Setup the raw gentoo system on the new disk


livecd# cd /mnt/gentoo
		
  1. For an AMD Athlon, P3, P4, or Xeon processor:
    
    livecd# wget ftp://ftp.ussg.iu.edu/pub/linux/gentoo/releases/x86/current/stages/stage3-i686-2006.1.tar.bz2
    livecd# tar -xvjpf stage3-i686-2006.1.tar.bz2
    				
  2. For other arches, you'll need to get the appropriate stage3
Next download a fresh snapshot of portage

livecd# wget http://gentoo.mirrors.pair.com/snapshots/portage-latest.tar.bz2
livecd# tar -xvjf portage-latest.tar.bz2 -C /mnt/gentoo/usr
        
I'm finished with this step

9. Tweak /etc/make.conf to set compiler and packages settings

Verify the following settings in nano -w /mnt/gentoo/etc/make.conf
  1. For an AMD Athlon processor:
    
    CHOST="i686-pc-linux-gnu"
    CFLAGS="-march=athlon-tbird -O2 -pipe -fomit-frame-pointer"
    				
  2. For an Intel Xeon or P4 processor:
    
    CHOST="i686-pc-linux-gnu"
    CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
    
    				
Verify the following:

CXXFLAGS="${CFLAGS}"
USE="-X -gtk -kde -qt python postgres gd png jpeg xml truetype unicode"
        
See here for a list of available USE flags.

Tip Once you have portage >= 2.1 you can compile and download at the same time. Add this to make.conf: FEATURES="parallel-fetch"
I'm finished with this step

10. Set GENTOO_MIRRORS variable, SYNC server, and DNS server(s)


livecd# mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
livecd# mirrorselect -i -r -o >> /mnt/gentoo/etc/make.conf
livecd# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
        
Tip If you need a unique /etc/resolv.conf make sure it looks something like this:

nameserver 10.0.0.1
search hostname.com
domain hostname.com
        	
I'm finished with this step

11. Mount the new gentoo system


livecd# mount -t proc none /mnt/gentoo/proc
livecd# mount -o bind /dev /mnt/gentoo/dev
livecd# chroot /mnt/gentoo /bin/bash
root# env-update
root# source /etc/profile
root# export PS1="(chroot) $PS1"
        
I'm finished with this step

12. Set the time and install stuff you will want


root# cp /usr/share/zoneinfo/EST5EDT /etc/localtime
root# emerge --sync
root# emerge -a gentoo-sources \
        grub \
        dhcp \
        hotplug \
        vixie-cron \
        syslog-ng \
        reiserfsprogs \
        gentoolkit \
        ntp \
        screen \
        vim
	
For anyone who's interested, I also keep a list of recommended ebuilds .
I'm finished with this step

13. Compile a new kernel

See the dedicated Kernel howto here
I'm finished with this step

14. Configure networking

Edit /etc/conf.d/net and add one of these:

# For DHCP
config_eth0=( "dhcp" )

# For static IP using CIDR notation
config_eth0=( "192.168.0.7/24" )
routes_eth0=( "default via 192.168.0.1" )

# For static IP using netmask notation
config_eth0=( "192.168.0.7 netmask 255.255.255.0" )
routes_eth0=( "default gw 192.168.0.1" )
		
I'm finished with this step

15. Setup machine specific settings, set startup options


root# rc-update add hostname default
root# rc-update add net.eth0 default
root# rc-update add hotplug default
root# rc-update add vixie-cron default
root# rc-update add sshd default
root# rc-update add syslog-ng default
root# rc-update add ntpd default
root# rc-update add ntp-client default
	
Tip It's highly recommended to add an entry into Root's crontab to run daily to make sure your clock doesn't drift.

# min   hour     day     month   dow     script-to-execute
0       4,16     *       *       *       /etc/init.d/ntp-client restart > /dev/null 2>&1


Populate the computer's hostname to reflect your setup

root# nano -w /etc/conf.d/hostname

# Set to the hostname of this machine
HOSTNAME="monkey"
	

root# nano -w /etc/conf.d/domainname

# When setting up resolv.conf, what should take precedence?
# If you wish to always override DHCP/whatever, set this to 1.
OVERRIDE=1

# To have a proper FQDN, you need to setup /etc/hosts and /etc/resolv.conf
# properly (domain entry in /etc/resolv.conf, and FQDN in /etc/hosts).
# 
DNSDOMAIN="rockfloat.com"

	


Tell gentoo to load any necessary kernel modules at startup:

root# nano -w /etc/modules.autoload.d/kernel-2.6

# Make the bottom look like this
# For example:
# 3c59x

e100

root# modules-update	# This is similar to env-update, or rc-update kinda
	
I'm finished with this step

16. Set the root password and add normal users


root# passwd root

root# useradd -m -G users,audio -s /bin/bash foouser
root# passwd foouser

root# useradd -m -G users,audio,wheel,portage -s /bin/bash barsuperuser
root# passwd barsuperuser
	
If you want any users to be able to admin the computer, you might wanna use sudo:

root# emerge app-admin/sudo
root# visudo

# Uncomment this line:
%wheel ALL=(ALL)	   ALL
	
This will let anyone in the wheel group execute any command as root without being prompted for the root password.
I'm finished with this step

17. Finish up


root# exit
livecd# cd
livecd# umount -l /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo
livecd# reboot
	
I'm finished with this step

18. TIP: Instructions to get into a broken system

If you happen to wind up with a broken system:
  1. You forgot something critical in the kernel, and thus it won't boot
  2. You forgot the root password
In these sad times, it's really handy to have a gentoo live-cd laying around. Simply boot to the cdrom, and perform the following:

livecd# swapon /dev/sda2
livecd# mount /dev/sda3 /mnt/gentoo
livecd# mount /dev/sda1 /mnt/gentoo/boot
livecd# mount -t proc none /mnt/gentoo/proc
livecd# mount -o bind /dev /mnt/gentoo/dev
livecd# chroot /mnt/gentoo /bin/bash
root# env-update
root# source /etc/profile
root# export PS1="(chroot) $PS1"

*** Do whatever you need, such as fix your kernel or reset root's password ***

root# exit 
livecd# cd
livecd# umount /mnt/gentoo/boot /mnt/gentoo/proc /mnt/gentoo
livecd# reboot

        
I'm finished with this step

19. TIP: Extra stuff that might be handy

Here are some common things you might look for:

/etc/conf.d/net                             # Network settings, like DHCP
/etc/modules.autoload.d/kernel-2.6          # Specify nic driver to load
/etc/conf.d/local.start                     # Arbitrary commands to execute at startup
/etc/init.d/net.eth0 restart                # Restart networking
/etc/make.conf                              # USE variables
/etc/conf.d/hostname                        # Computer hostname
/etc/conf.d/domainname                      # Computer domainname
/etc/exports                                # NFS shares
/etc/make.profile                           # Profiles: /usr/portage/profiles/default-linux/...
/etc/portage/package.keywords               # Set one ebuild to always install ~x86 or something
/etc/portage/package.mask                   # Prevent emerge -u world from upgrading something
/etc/apache2/*                              # Apache configuration settings
/var/log/emerge.log                         # Log file used by portage (what was last emerged)
~/.bashrc                                   # Bash settings per user

emerge -s wget                              # Search for wget
emerge -a wget                              # Install something, like wget
emerge -C wget                              # Uninstall something like wget
eix -s wget                                 # Search for wget (superior to emerge -s)
update-eix                                  # Update the eix index
equery files wget | grep bin                # Find binary for something installed, like wget
vipw                                        # Edit /etc/passwd
vigr                                        # Edit /etc/group
useradd                                     # Add new users
userdel                                     # Delete users and related files
usermod                                     # Modify a users account
rc-update                                   # Add/delete something like apache to startup
etc-update                                  # Update config files after a package upgrade
modules-update                              # Update modules after changing modules.autoload.d
visudo                                      # Edit the sudo config, who can do what basically
    	
I'm finished with this step

Changelog: Date Description
07/04/2005 @ 15:00 Overall rework for updates with 2005.0
07/06/2005 @ 20:49 Fixed nasty typo, in grub.conf I had root=/dev/sda1 (should be sda3)
07/06/2005 @ 21:00 Added steps for modules.autoload.d, installing dhcpcd, and sudo
11/02/2005 @ 22:00 Updated formatting a bit, added cfdisk as an fdisk alternative
11/02/2005 @ 22:15 Made use flags more realistic, removed quicktime - no clue how that got there
11/23/2005 @ 13:07 Changed fstab to noauto for /boot
12/11/2005 @ 14:00 Moved the kernel stuff to a dedicated howto
12/12/2005 @ 23:30 Separated Athlon/Xeon, networking, formatting tweaks
01/03/2006 @ 12:09 Added ntp-client to the default runlevel
06/24/2006 @ 01:21 Updates for 2006.0
09/03/2006 @ 00:40 Added lspci, dhclient, recommended ebuilds, updated for 2006.1
04/08/2007 @ 18:53 Added dev mount per change in the Gentoo handbook

This document was originally created on 01/17/2004


Conventions and tips for this howto document:
  1. This howto assumes you are installing on an IDE disk drive
  2. This howto assumes you will be using the grub boot manager
  3. This howto assumes that reiserfs is your preferred file system
  4. This howto assumes you are very patient
  5. This howto assumes you realize that knowing how to install gentoo drives chics wild!

Disclaimer:
This page is not endorsed by gentoo.org or any other cool cats. Any information provided in this document is to be used at your own risk.