Gentoo OS Installation from Minimal Disk
This artlicle will show you how to install Gentoo OS from a minimal installation CD on your computer. Before proceeding, please ensure that you have the following:
Obtaining the Minimal Installation Disk
The first thing you need to do is to download the minimal installation disk available from the Gentoo official website. The filename depends on the version you are going to download. The current version (as of writing this article) can be downloaded from:
| http://bouncer.gentoo.org/fetch/gentoo-2007.0-minimal/x86/ |
After obtaining the installation disk, burn it on a CD and plug it into your computer CDROM drive.
Booting from the CD
Ensure that your BIOS settings allows you to boot from the CD. Usually, you can enter BIOS at boot time by pressing the ‘DEL’ key on you keyboard. From there navigate to your boot manager and set the boot options. Recommended boot configuration order is:
After the correct boot order is set, go ahead and reboot to the Gentoo Minimal CD. After a short period, during which various modules and components are initialized you will be provided with a command prompt, which should look like this:
| livecd ~ # |
Network Configuration
Since a large part of the OS will be downloaded from Internet we will need your network setup at the beginning. To set it up we will use the ifconfig command:
| livecd ~ # ifconfig eth0 192.168.4.140/24 livecd ~ # route add default gw 192.168.4.1 livecd ~ # echo nameserver 192.168.4.1 > /etc/resolv.conf |
The above commands brings up the eth0 interface, assigns the 192.168.4.140 private IP address, adds the default gateway as 192.168.4.1 and sets the nameserver to 192.168.4.1. Obviously, you would need to edit those values to match your network configuration. Another, alternative way to setup the network (and the one that is described in the Gentoo handbook) is to use the net-setup command. Doing a net-setup will bring a couple of dialog boxes on your monitor asking for various network options – just answer them and you should be all setup.
Starting the SSHd
Once the network is up and running, we can now run the SSH server. This will allow us to connect remotely from another machine and complete the installation from there. To start the SSH server simply run:
| livecd ~ # /etc/init.d/sshd start |
Now, set the root password on the liveCD so that you can connect to it from another PC. Please note that allowing root to connect over ssh is not recommended under normal circumstances. If you can’t trust your local network, use a long and complex password, you should use it only once as it will disappear and you will have to set it once again after your first reboot. To change the password do:
| livecd ~ # passwd New UNIX password: (Type the password here) Retype new UNIX password: (Type the same password here) passwd: password updated successfully |
Create Partitions
The next step of the Gentoo install is to create the hdd partitions where it will reside. To do so you will need to use the fdisk utility:
| livecd ~ # fdisk /dev/sda |
NOTE: Depending on your hardware the device name (i.e /dev/sda) might have a different name. For SATA and SCSI discs the devide name is usually /dev/sda, while for IDE it should be /dev/hda
Using the fdisk you will be asked to enter a command name. What we need to achieve is to:
You might want a different architecture ofcourse and you are free to implement it, but for the purpose of this tutorial we will use the above schema.
In order to create a new partition, enter ‘n’ when asked for a command. The ‘n’ command will create a brand new partition for you. Select primary and then setup a number for the partition (from 1 to 4). Repeat that for each of the three partitions. At the end it should look like:
| livecd ~ # fdisk -lDisk /dev/sda: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 cylinders Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System /dev/sda1 1 12 96358+ 83 Linux /dev/sda2 13 72 481950 82 Linux swap / Solaris /dev/sda3 73 522 3614625 83 Linux livecd ~ # |
Next, we have to actually create the partitions and activate the swap:
| livecd ~ # mke2fs /dev/sda1 livecd ~ # mke2fs -j /dev/sda3 mkswap /dev/sda2 && swapon /dev/sda2 |
Mount the freshly created file systems on /mnt/gentoo. Create directories for the other mount points (like /mnt/gentoo/boot) if you need them and mount them too.
| livecd ~ # mount /dev/sda3 /mnt/gentoo livecd ~ # mkdir /mnt/gentoo/boot livecd ~ # mount /dev/sda1 /mnt/gentoo/boot |
Setting up the Stage
To setup the stage, we will need to download it first from Internet and then unpack it, as shown here:
| livecd ~ # cd /mnt/gentoo livecd gentoo # wget ftp://gentoo.osuosl.org/pub/gentoo/releases/x86/current/stages/stage3-i686*tar.bz2 livecd gentoo # tar -xjpf stage3* |
The stage archive file should be near 100MB and might take a while to download and extract, so please be patient.
Next on the install task list is to fetch the latest portage snapshot. To do so:
| livecd ~ # cd /mnt/gentoo/usr livecd gentoo #wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2 livecd gentoo # tar -xjf portage* |
The portage archive file should be around 40MB big and shouldn’t take too much time to extract. Once the portage is set all we need to do is to chroot the environment:
| livecd usr # cd / livecd / # mount -t proc proc /mnt/gentoo/proc livecd / # cp -L /etc/resolv.conf /mnt/gentoo/etc/ livecd / # chroot /mnt/gentoo /bin/bash livecd / # env-update && source /etc/profile |
This should return something like: “>>> Regenerating /etc/ld.so.cache…” which is a sign of success.
Making the Kernel
Now that we have the portage installed and we have chrooted into the target installation system, we need to build the new kernel. On Gentoo, this is really an easy task – all we need is to fetch the kernel sources from the portage and configure it. To fetch the source files:
| livecd usr # emerge -av gentoo-sources |
After calculating the dependencies, the portage system will attempt to download and extract the gentoo sources package. Once extracted, we can start building the new kernel:
| livecd usr # cd /usr/src/linux livecd linux # make menuconfig livecd linux # make -j2 |
Since this is just a short tutorial on how to install the minimal build of Gentoo, I won’t go further into Kernel configurations. If you would like to learn more about it, please have a look at the Gentoo handbook.
Depending on the options you have selected and your system architecture the actual process of linking the new kernel can get from 5 to …. many minutes, so be patient :-) To finalize the kernel build we need to copy the files into their places:
| livecd usr # make modules_install livecd linux # cp arch/i386/boot/bzImage /boot/kernel |
That’s it for the kernel. Lets move to the next step.
Installing vi
Since this is a brand new system, the only available editor would be nano/pico. I personally am used to use vi and I’m feeling rather uncomfortable when I have to deal with nano. So … the next step would be to install vi (actually vim, which stands for ‘vi improved’):
| livecd usr # emerge -av vim |
That would get us VIM installed (and will make us happy).
Configuring the System Files
Although we have installed the Kernel we are far from done yet. The /etc/fstab file is the default one and we need to edit it to suit our system architecture. That is – we need to edit the BOOT, ROOT and SWAP and replace them with our actual partition names:
| livecd usr # vi /etc/fstab /dev/sda1 /boot ext2 noauto,noatime 1 2 /dev/sda3 / ext3 noatime 0 1 /dev/sda2 none swap sw 0 0 |
Again, on your system, it might be /dev/hda rather than /dev/sda. Configuring the default network – we don’t want to do it manually everytime the system boots:
| livecd etc # cd conf.d livecd conf.d # echo ‘config_eth0=( “192.168.1.10/24″ )’ >> net livecd conf.d # echo ‘routes_eth0=( “default via 192.168.1.1″ )’ >> net livecd conf.d # rc-update add net.eth0 default |
If that would be a server installation, you might want to add the SSH Daemon to the startup. Doing so will enable the SSH on boot time automatically:
| livecd conf.d # rc-update add sshd default |
Set the root password again
We already set the password once at the beginning of the tutorial, but that password was the one used by the livecd. We need to setup the root password for the newly installed system as well:
| livecd ~ # passwd New UNIX password: (Type the password here) Retype new UNIX password: (Type the same password here) passwd: password updated successfully |
Optional step – add syslogd and cron daemons
Install a system logger like syslog-ng and a cron daemon like vixie-cron, and add them to the default run level.
| livecd conf.d # emerge syslog-ng vixie-cron livecd conf.d # rc-update add syslog-ng default livecd conf.d # rc-update add vixie-cron default |
Finalizing the installation and adding the Bootloader
For the purpose of the tutorial we will install the GRUB loader. If you would like to install LILO instead, please have a look at the Gentoo Handbook for details on how to do it. To install the GRUB Loader, we need to get it source files first. We do that the same way as the Kernel source files – using emerge:
| livecd conf.d # emerge -av grub |
Once installed we need to configure and tailor it to our own system:
| livecd conf.d # cp /boot/grub/grub.conf.sample /boot/grub/grub.conf livecd conf.d # vi /boot/grub/grub.conf |
| # Boot automatically after 5 secs. timeout 5# By default, boot the first entry. default 0# Splash image to show behind grub. splashimage=(hd0,0)/boot/grub/splash.xpm.gz# For booting Gentoo with the static rescue shell title Gentoo root (hd0,0) kernel /boot/kernel root=/dev/sda3 |
Now install it:
| livecd conf.d # grub grub> root (hd0,0) grub> setup (hd0) grub> quit |
That’s it. We should have a fully working system now. The last thing left is to actually:
Reboot
Exit the chrooted environment, unmount all file systems and reboot:
| livecd conf.d # exit livecd / # umount /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo livecd / # reboot |
That’s it! Your new Gentoo install is completed, although you have probably no use of it as it is at the moment. The next step will be to emerge some software or even a graphical interface (such as Gnome).
Thank you for the wonderful information, it helped me a lot installing gentoo in virtual box.
http://www.virtualbox.org/
I would like to add some notes:
1. Virtual box’s default HD size is 2gb. This causes problems even if it isn’t dynamic, it runs out of space while the portage is un-compressing. Even if virtual box’s HD is dynamic. This causes the tar to output errors like “tar: portage/path/to/file cannot be found”
(a gajillion of them)
2. In fdisk it asks about cylinders as well, so here is a link from the handbook that has all the information on fdisk you should need.
http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?chap=4&part=1