Yee Wei Law's Homepage

Recent site activity

All things Gentoo

Extremely terse installation guide

Objective: Get up to speed fast (i.e. by using Universal LiveCD, starting with Stage2, and using a readily configured kernel) and yet not sacrificing a lot of performance.

Prerequisite: Have a working network connection, know how to use fdisk.

Organization: Follows that of Gentoo Linux x86 Handbook.

Choosing the Right Installation Medium

  1. Get the CD image install-x86-universal-<release>.iso from one of these mirrors.

Configuring your network

  1. If DHCP doesn't just work, read this.

Preparing the disks

  1. Partition hard disk using
    # fdisk /dev/hda
    making sure to create a swap space that is as large as the size of the RAM, and a Linux partition with possibly one of the following filesystems: ext3, reiserfs etc. Details are omitted here.

Installing the Gentoo Installation Files

  1. Install Stage3 from the LiveCD
    # mount /dev/cdroms/cdrom0 /mnt/cdrom
    # cd /mnt/gentoo
    # tar -xvjpf /mnt/cdrom/stages/stage3-<subarch>-2004.3.tar.bz2
    Note the -p option preserves permissions.
  2. Install Portage from the Internet
    Download a Portage snapshot from one of the mirrors, using the links2 browser or wget if you know the URL. Unpack the portage snapshot:
    # tar -xvjf /mnt/gentoo/portage-<date>.tar.bz2 -C /mnt/gentoo/usr
    Note the -C option changes current directory to the specified directory.

Installing the Gentoo Base System

  1. Select the mirrors
    # mirrorselect -a -s4 -o | grep 'GENTOO_MIRRORS=' >> /mnt/gentoo/etc/make.conf
    Note the -a prompts you with a GUI, -s4 saves 4 of your selections, -o outputs to stdout.
  2. Copy DNS info
    # cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
  3. Mount the proc filesystem
    # mount -t proc none /mnt/gentoo/proc
  4. Enter the new environment
    # chroot /mnt/gentoo /bin/bash
    # env-update
    * Caching service dependencies...
    # source /etc/profile
  5. Update the Portage tree
    # emerge --sync
  6. Configure the USE variable
    Set the USE variable to some of the flags described in /usr/portage/profiles/use.desc.
    # echo USE=\"aac alsa avi cdr cjk gnome gpm gtk2 hardened \
    mmx mysql nls nptl pam perl php posix python quicktime \
    samba sse ssl tcltk tetex truetype yahoo zlib\" >> /etc/make.conf
    Note -gtk means no GTK support. Note that if you are doing development work, you are advised not to specify hardened, because you will have trouble debugging your programs with GDB, despite the tip here.
  7. Configure GLIBC locales
    First activate userlocales USE flag:
    # mkdir /etc/portage
    # echo "sys-libs/glibc userlocales" >> /etc/portage/package.use
    Then specify your intended locale in /etc/locales.build. For example, my intended locale is:
    zh_CN/UTF-8	
  8. Progress from Stage2 to Stage3
    Assuming you chose to start with Stage2, and you want to download all the sources first before building,
    # emerge --fetchonly system
    # emerge system

Configuring the Kernel

  1. Configure timezone
    # ln -sf /usr/share/zoneinfo/<time-zone> /etc/localtime	
    For me, <time-zone> is Europe/Amsterdam.
  2. Install the sources
    Assuming you want kernel 2.6,
    # emerge gentoo-dev-sources	
  3. Use genkernel
    # emerge genkernel
    # genkernel --menuconfig all
    Note the --menuconfig switch allows you to manually configure the kernel before building it! The following have to be selected, although the handbook only mentions this for the manual configuration of the kernel:
    Code maturity level options --->
    [*] Prompt for development and/or incomplete code/drivers

    Processor type and features --->
    (Change according to your system)

    File systems --->
    (Select one or more of the following options as needed by your system)
    <*> Reiserfs support
    <*> Ext3 journalling file system support
    <*> JFS filesystem support
    <*> Second extended fs support
    <*> XFS filesystem support

    Pseudo Filesystems --->
    [*] /proc file system support
    [*] /dev file system support (OBSOLETE)
    [*] Automatically mount at boot
    [*] Virtual memory file system support (former shm fs)

    USB Support --->
    <*> USB Human Interface Device (full HID) support
    The other things that need attention are the graphics card support, NLS support, DOS/Windows filesystem support, netfilter etc. After quite some time, the kernel would have been built, then check that the kernel has been built:
    # ls /boot/kernel* /boot/initrd*	
    and finally emerge coldplug and hotplug:
    # emerge coldplug
    # rc-update add coldplug boot
    # emerge hotplug
    # rc-update add hotplug default

Configuring your System

  1. Configure filesystem information
    Edit /etc/fstab, e.g.
    /dev/hda2           /windows/C      ntfs        ro,users,gid=users,umask=0002,nls=utf8   0 0
    /dev/hda5 none swap sw 0 0
    /dev/hda6 / reiserfs noatime,acl,user_xattr 0 1
    /dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
    /dev/fd0 /mnt/floppy auto noauto 0 0
    none /proc proc defaults 0 0
    none /dev/shm tmpfs defaults 0 0
    none /proc/bus/usb usbfs defaults 0 0
    For more information about /etc/fstab, read this.
  2. Configure networking information
    Set the host name:
    # echo <name> > /etc/hostname
    Edit /etc/conf.d/net, assuming you are using DHCP:
    iface_eth0="dhcp"
    # Some network admins require that you use the
    # hostname and domainname provided by the DHCP server.
    # In that case, add the following to let dhcpcd use them.
    # That will override your own hostname and domainname definitions.
    dhcpcd_eth0="-HD"
    # If you intend on using NTP to keep your machine clock synchronized, use
    # the -N option to prevent dhcpcd from overwriting your /etc/ntp.conf file
    dhcpcd_eth0="-N"
    To have your network interfaces activated at boot, you need to add them to the default runlevel:
    # rc-update add net.eth0 default	
  3. Configure system information
    Set root password:
    # passwd	
    Edit general system-wide information:
    # nano -w /etc/rc.conf	

Installing Necessary System Tools

  1. System logger
    # emerge syslog-ng
    # rc-update add syslog-ng default
  2. Filesystem tools
    # emerge reiserfsprogs	
  3. Networking tools
    # emerge dhcpcd	

Configuring the Bootloader

  1. Emerge and configure GRUB
    # emerge grub
    # nano -w /boot/grub/grub.conf
    Note that there's an example at /boot/grub/grub.conf.sample. My grub.conf looks like
    default 0
    timeout 8

    title=Gentoo Linux 2.6.10-gentoo-r6
    root (hd0,5)
    kernel (hd0,5)/boot/kernel-2.6.10-gentoo-r6 root=/dev/ram0 real_root=/dev/hda6 init=/linuxrc ramdisk_size=8192
    initrd (hd0,5)/boot/initrd-2.6.10-gentoo-r6

    title=Windows XP Professional
    rootnoverify (hd0,1)
    makeactive
    chainloader +1
    Note how the paths to kernel and initrd are specified, the handbook got them wrong -- it took me a while to figure out why my first installation failed to boot.
  2. Install GRUB in the MBR
    First start GRUB:
    # grub	
    then type the following commands:
    grub> root (hd0,5)          (Specify where your /boot partition resides)
    grub> setup (hd0) (Install GRUB in the MBR)
    grub> quit (Exit the GRUB shell)
  3. Reboot

Finalizing your Gentoo Installation

  1. User administration
    # useradd -m -G users,audio,cdrom,floppy,usb,video,wheel -s /bin/bash john
    # passwd john

Making it more complete

(The Gentoo Handbook doesn't have the rest starting from here)
  1. Setting up firewall
    I choose Shorewall because (1) it is recommended by the Gentoo Linux Security Guide, and (2) it is easy to use.
    # emerge shorewall	
    Then in /etc/shorewall, we have to modify a few files. For my simple case, my Gentoo box is directly connected to the Internet. In its default installation, Shorewall defines 3 zones: Internet, local network and the demilitarized zone (DMZ). So only the Internet zone makes sense to me, and in /etc/shorewall/zone, I have
    #ZONE   DISPLAY         COMMENTS
    net Net Internet
    In /etc/shorewall/interfaces, I have
    #ZONE    INTERFACE      BROADCAST       OPTIONS
    net eth0 detect dhcp
    In /etc/shorewall/policy, I have
    #SOURCE         DEST            POLICY          LOG
    # LEVEL
    fw net ACCEPT
    net all DROP info
    # THE FOLLOWING POLICY MUST BE LAST
    all all REJECT info
    by changing the default "loc" zone to "fw" which stands for firewall. In /etc/shorewall/rules, I have
    #ACTION  SOURCE         DEST            PROTO   
    AllowPing net:130.89.0.0/16 fw
    AllowSSH net:130.89.0.0/16 fw
    so that I can ping and and ssh to my Gentoo box from this subnet: 130.89.0.0/16. Note that when accessing an FTP server, you have to use passive mode by entering the "passive" command. Now make sure the configuration works with
    # shorewall check	
    Lastly, make sure it starts up in the default runlevel.
    # rc-update add shorewall default	
  2. Synchronizing the clock with a NTP server
    First emerge the NTP package:
    # emerge ntp
    Then edit /etc/conf.d/ntp-client:
    NTPDATE_CMD="ntpdate"
    NTPDATE_OPTS="-b your.server.here"
    And finally add ntp-client to the list of services started at runlevel default:
    # rc-update add ntp-client default	
    As a side note, the command "rdate -s server" sets the system time with the time from server.
  3. Enable SSH access Note SSH should have been installed by now.
    # rc-update add sshd default

Package Management

The equery tool from the gentoolkit packages allows you to query what packages have been installed, amongst other things. Type the following command to check for broken dependencies:
revdep-rebuild -p	
The -p option means "pretend" -- leave it out to fix the dependencies, for real.

The source files downloaded by emerge are stored in /usr/portage/distfiles. Delete the unwanted ones there to make space.

runlevel

Detail is here. In general, the numbering of runlevels maybe different from distribution to distribution, but it is documented in /etc/inittab. For example, the default runlevel is specified by the line with initdefault. Usually the mapping is as follows:
  1. 0: shutdown
  2. 1: single-user
  3. 2: no network
  4. 3: with network, i.e. the default
  5. 4: not used
  6. 5: X11
  7. 6: reboot

X

Setting up

Full information available at The X Server Configuration HOWTO

As of Gentoo 2004.3, the stable xorg-x11 release 6.8.0-r4 has a "duplicate symbol __i686.get_pc_thunk.bx" bug. This has been fixed in release 6.8.2, but as of 21 Feb 2005, release 6.8.2 is masked, meaning that if you want to emerge it, you'd have to use the following command:


# ACCEPT_KEYWORDS="~x86" emerge =x11-base/xorg-x11-6.8.2
# env-update
# source /etc/profile
Auto-generate and test a config file:
# Xorg -configure
# X -config /root/xorg.conf.new
The auto-detection works like magic for me, and I think it would for you too. So if the generated config works, then try startx for real:
# cp /root/xorg/conf.new /etc/X11/xorg.conf	
# startx
Configuration info is available with this command:
# man 5 xorg.conf