Quick and dirty Gentoo install

From RSWiki
Jump to: navigation, search




This article was originally written in December 2007 and may be depreceated

Step 1 - Download the live CD

Download the live CD from a mirror close to you. This list can be found on this page.

Step 2 - Boot from the CD

Burn the iso file that you just downloaded onto CD and boot from it using all the defaults.

Once you get to a shell prompt you need to test to see if you have network connectivity. Ping any host of your choice. If you do not get a reply then you need to manually configure the ethernet adapter using this command:

# net-setup eth0

Of course that is assuming that eth0 is your network adapter.

Step 3 - Prepare your partitions

For this example I am going to assume that you have a hard disk of 8GB in size. You can of course modify my example to cater for your own needs.

Create three partitions using fdisk. so assuming that your hard drive is /dev/hda enter the following at the prompt:

 # fdisk /dev/hda

you will now see this prompt:

Command (m for help):

To make this easier enter the following sequence of commands to create the boot partition:

n <enter>
p <enter>
1 <enter>
<enter>
+100M <enter>

While still in fdisk enter the following sequence to create a 1GB swap partition:

n <enter>
p <enter>
2 <enter>
<enter>
+1024M <enter>

We need to change the partition type to linux swap so enter the following in to fdisk:

t <enter>
2 <enter>
82 <enter>

Now again while still in fdisk we will create the root partition by using this sequence:

n <enter>
p <enter>
3 <enter>
<enter>
<enter>

Now the creation of the partitions is complete so exit and save changes to your partitions by entering the following into fdisk:

w <enter>

For reference your partition table should now look like this:

/dev/hda1 - boot partition
/dev/hda2 - swap partition
/dev/hda2 - root partition

Step 4 - Create the file systems

With the partition setup complete we now need to create the filesystems. we are going to format the boot partition as ext2 and the root partition as ext3 and obviously we need to configure the swap partitions also.

At the command prompt enter the following to initialise the boot partition:

# mke2fs /dev/hda1

Now enter the following to initialise the root partition:

# mke2fs -j /dev/hda3

And finally enter the following commands to prepare and use the swap partition:

# mkswap /dev/hda2
# swapon /dev/hda2

Step 5 - Mount your new partitions

With partitions filesystems complete we are now ready to mount them. At the command prompt enter the following:

# mount /dev/hda3 /mnt/gentoo
# mkdir /mnt/gentoo/boot
# mount /dev/hda1 /mnt/gentoo/boot

Step 6 - Download the Stage tarball and the Portage tree

Change directory into the newly created root partition by entering the following in the command prompt:

# cd /mnt/gentoo

Now we need to download the stage3 tarball from your nearest mirror. For this we can use the wget command. So for my closest mirror I would enter the following:

# wget http://ftp.heanet.ie/pub/gentoo/releases/x86/2006.1/stages/stage3-i586-2006.1.tar.bz2

We can now also download the latest Portage snapshot also using wget.

# wget http://ftp.heanet.ie/pub/gentoo/releases/snapshots/2006.1/portage-2006.1.tar.bz2

Now we can extract the Stage3 tarball:

# tar xvjpf stage3-i586-2006.1.tar.bz2

Once the stage3 tarball has been extracted we can now extract the portage snapshot by entering the following:

# tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr

For the purposes of this tutorial I will be using the default make options.

Step 7 - Entering your new Gentoo environment

Now we will initialise our basic installstion using chroot but first we need to configure our DNS and mirrors.

The following is an interactive menu to allow you to choose your default mirror and add it to make.conf:

# mirrorselect -i -r -o >> /mnt/gentoo/etc/make.conf

Now we need to copy our DNS settings over to the new environment and this is done by entering the following:

# cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

Next up is mounting the /proc and /dev filesystems. You can do this by entering the following:

# mount -t proc none /mnt/gentoo/proc
# mount -o bind /dev /mnt/gentoo/dev

Now we are ready to enter the new environment. Type in the following into the command prompt:

# chroot /mnt/gentoo /bin/bash
# env-update

and

# source /etc/profile
# export PS1="(chroot) $PS1"

Step 8 - Configuring Portage

before we continue any further we need to update Portage to the latest version. This is time consuming so once you enter the following command it would be an opportune time to grab a cup of coffee.

# emerge --sync

when this step is complete you may get a notice informing you that a new version of emerge is available. if this is the case then enter the following command:

#emerge portage

Step 9 - configuring your timezone

we now need to set a timezone for our new system. so enter the following at the command prompt to see the available timezones:

# ls /usr/share/zoneinfo

As an example I am based in Ireland so I would enter the following command to set my timezone:

# cp /usr/share/zoneinfo/Eire /etc/localtime

Step 10 - Installing the Kernel

Now we have to configure and install our kernel. So enter the following to download the kernel source:

# USE="-doc symlink" emerge gentoo-sources

This will download and unpack the kernel source in /usr/src. It will also create a symlink so that the unpacked kernel source is available in /usr/src/linux

Next we come to what most people would consider to be the most difficult part of the installation and that is configuring the kernel itself. In fact it is not at all that difficult but it does require that you know as much as possible about the hardware that you have in your machine.

At this stage of the install we have no choice but to use the ncurses based configuration editor and this can be executed by entering the following:

# cd /usr/src/linux
# make menuconfig

As this is a time consuming and machine individual process I am going to assume that you have configured the kernel and are now ready to compile and install it.

To compile all you need to do is enter the following:

# make && make modules_install

Once the kernel is compiled we need to copy it to our boot partition and give it a meaningful name. so enter the following:

# cd /usr/src/linux
# cp arch/i386/boot/bzImage /boot/gentookernel

Step 11 - Prepare our mountpoints

Now the kernel has been compiled and copied to our future system we now need to configure various system options such as the mount points for file systems.

First up is FSTAB. Under Linux all filesystems that are to be mounted by the file system must be listed in /etc/fstab. The listings in this file also give various mount point options and tell the Linux kernel how they should be mounted, what filesystem type they are etc.

So if you have followed the partition scheme in this tutorial you can use your favourite editor once again and edit /etc/fstab so that it contains the following lines:

/dev/hda1   /boot        ext2    defaults,noatime     1 2
/dev/hda2   none         swap    sw                   0 0
/dev/hda3   /            ext3    noatime              0 1

proc        /proc        proc    defaults             0 0
shm         /dev/shm     tmpfs   nodev,nosuid,noexec  0 0

/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0

Step 12 - Configure networking

Now we need to setup our networking options. Hostname, domain name, dns etc.

First up edit /etc/conf.d/hostname and enter your chosen hostname as in the example here:

HOSTNAME="tux"

Next we will add the domain name so edit /etc/conf.d/net and enter your domain as in this example:

dns_domain_lo="mydomain"

For the purposes of this tutorial we will use DHCP to configure our IP address To do this we need to edit /etc/conf.d/net and add the following lines to it:

config_eth0=( "dhcp" )
dhcp_eth0="nodns nontp nonis"

Of course this is not much good without installing a DHCP client so we can now install a DHCP client by using emerge. So at the command prompt enter the following:

emerge dhcpcd

Once the DHCP client is installed we need to configure networking to automatically start on boot. To enable this, enter the following into the command prompt:

rc-update add net.eth0 default

And finally we need to write out the hosts file. To do this we need to edit /etc/hosts so that it contains the following line:

127.0.0.1     yourhostname.domainname yourhostname localhost

Step 13 - Adding various system information

First up we need to add the root password so at the command prompt enter the following to change it:

passwd

Next we need to add the terminals to /etc/securetty to enable loggin in via the serial console. Ehter the following into the command prompt:

echo "tts/0" >> /etc/securetty

At this stage in the official Gentoo handbook are options to configure /etc/rc.conf and options to configure the default keymap. As the defaults will suffice we will omit these steps from this tutorial.

Step 14 - Installing necessary system tools

In order to have a fully functioning Linux system there are several tools and utilities that we need to install. The first of these that we will install is a system logger so we will now install syslog-ng by entering the following into the command prompt:

# emerge syslog-ng

Once syslog is compiled and installed we need to ensure that it runs on system startup by entering the following:

# rc-update add syslog-ng default

To enable scheduled commands we need to install a cron daemon so enter the following to install vixie-cron:

# emerge vixie-cron

Once this is compiled and installed we need to ensure that it runs on system startup by entering the following:

# rc-update add vixie-cron default

Now we will install some filesystem tools. So enter the following into the command prompt:

# USE="-gtk" emerge evms

Step 15 - Installing a boot loader

You may be aware that there are two main boot loaders available for linux. Grub and Lilo. There are various reasons to use one or the other but for this tutorial I will use lilo

First we need to install lilo using emerge so at the command prompt enter the following:

# emerge lilo

Next we need to configure /etc/lilo.conf and ensure that the correct partition layout is entered so if you used the default partition table earlier in this turorial it should look as follows:

boot=/dev/hda             # Install LILO in the MBR
prompt                    # Give the user the chance to select another section
timeout=50                # Wait 5 (five) seconds before booting the default section
default=gentoo            # When the timeout has passed, boot the "gentoo" section

image=/boot/gentookernel
label=gentoo            # Name we give to this section
read-only               # Start with a read-only root. Do not alter!
root=/dev/hda3          # Location of the root filesystem

Now we need to install lilo on the master boot record by entering the following at the command line:

# /sbin/lilo

Step 16 - Restarting and booting up your new install

Finally the moment is here! We are now almost ready to shutdown and boot into our new system but there are a few steps first so enter the following command:

# exit
# cd
# umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
# reboot

And thats it! You should now have a basic install of Gentoo. All that is left to do is to use emerge to install your required packages. Best of luck.