Install Gentoo using Ubuntu

Introduction

If you have ever installed Gentoo, this should be no news to you. However, new users who want to try out the distribution often hesitate, because of its complexity. In this tutorial, I will try to mention enough information (on their current distribution part), so the users wanting to try Gentoo can do so using the comfort of their existing distribution e.g Ubuntu (since that is what I have used in this tutorial).

Should I install Gentoo?

Gentoo is not everyday distro, which you install in an hour. Here are things you should consider before installing Gentoo.

  • Most packages are source based, so it takes long (I mean really long) time to install Gentoo and its packages.
  • If you are installing it on a laptop, the amount of heat dissipation is huge (due to long compilation time). It is just like playing a resource intensive game for a whole day in your laptop.
  • Gentoo is configurable. That does not mean you will be able to get it right the first time (or many times at the beginning). It requires continuous tweaking and experimenting.
  • It requires you to commit many hours, at the beginning. Since it is a rolling release, things can break.

Installing Gentoo using another distribution

  • You will be out of your computer, at least for a day. If this is your only computer, it is good to use this method.
  • New users, could easily follow the installation wiki from their current distribution, rather than a terminal from Gentoo installation disk.
  • If some hardware drivers don’t work, it is much easier to install Gentoo using another distribution and enable the drivers later (even copy one from the current distro).
  • If something breaks, you still have a working distro to go on.

Benefits of Gentoo

  • By compulsion, you will have to run and learn many commands, that you otherwise might have escaped.
  • Final output could be what you intended, made just for your hardware.

Disk preparation

For this tutorial, let us assume we will install Gentoo on /dev/sda1. I hope you have formatted the drive using following commands

mkfs.ext4 /dev/sda1
grub-install /dev/sda  # Above command might have removed MBR information, we need to restore that
mkdir /media/gentoo
mount /dev/sda1 /media/gentoo

Using http://www.gentoo.org/main/en/mirrors2.xml download a stage3 tarball. Go to one of the links -> releases/<architecture>/autobuilds/<date>/stage3-amd64-<date>.tar.bz2

Replace architecture and date with correct values. Use latest date for <date> and amd64 or x32 for the <architecture>.

Unarchive (unzip) the stage3 tarball to /media/gentoo, so that the directory looks like this.

$ ls /media/gentoo
 bin dev home lib32 media opt root sbin tmp var
 boot etc lib lib64 mnt proc run sys usr

Chroot

We need to execute commands, as if we were using Gentoo. In your existing distribution, execute following commands.

sudo su
cp -L /etc/resolv.conf /media/gentoo/etc/
mount -t proc none /media/gentoo/proc
mount --rbind /sys /media/gentoo/sys
mount --rbind /dev /media/gentoo/dev
chroot /media/gentoo /bin/bash
env-update
export PS1="(ch) $PS1"

Note: From next time onward,  if you need to change some files or install some packages from inside Ubuntu, you only need to execute above commands (expect the one that copied /etc/resolv.conf).

Add GENTOO_MIRRORS and SYNC to /etc/portage/make.conf

nano -w /etc/portage/make.conf
GENTOO_MIRRORS="ftp://ftp.twaren.net/Linux/Gentoo/"
SYNC="rsync://rsync3.jp.gentoo.org/gentoo-portage"

I have used one from Taiwan and Japan. Use the one that is near to you using http://www.gentoo.org/main/en/mirrors2.xml.

Check Network

ping -c 3 google.com

If you encounter following error message

ping: icmp open socket: Operation not permitted

Change the permission of /bin/ping using following command

chmod 755 /bin/ping

It should start working for now on.

After configuring make.conf, we need to update the portage

mkdir /usr/portage
emerge --sync

or

emerge --sync --quiet

Follow the handbook (http://www.gentoo.org/doc/en/handbook/) for rest of the installation. For AMD64, you can follow http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?full=1. At this stage, we are at 6.b in the official handbook.

Kernel compilation

For your first installation, I don’t recommend trying to enable individual components (related to your hardware). For easier  installation, you could use emerge genkernel. The downside is, it could load more than needed.

Since we already have a working kernel (your current distribution), you can copy kernel configuration file from your current distribution (/boot/config*). Copy one of the config files to /media/gentoo/usr/src/linux/.config, using another terminal. Since each distributions patch the kernel heavily, you might not get all the drivers installed in your distribution just by copying the configuration file.

If you want to install only the necessary packages (the hard way), in your current distribution run following commands to find the hardware and loaded modules.

$ lsmod
$ lspci

If you are sure you have enabled necessary modules during kernel compilation, reboot to Gentoo, and see the output of dmesg, to determine if the drivers were installed properly.

$ dmesg | grep -i error

Grub

First, find UUID of all the partitions (you could use /dev/sda1 as parameter as well)

sudo blkid

In Ubuntu, sudo update-grub command should recognize Gentoo. If not, add following text to /etc/grub.d/40_custom. Use the value inside UUID (that we found using blkid, without quotes) and replace <UUID> below. E.g 2535abc3-321a-badb-ba1e-a1bd2356434.

 # Gentoo
 menuentry 'Gentoo Linux' {
 recordfail
 gfxmode $linux_gfx_mode
 insmod gzio
 insmod part_msdos
 insmod ext2
 set root='(hd0,msdos1)'
 search --no-floppy --fs-uuid --set=root <UUID>
 linux /boot/kernel root=UUID=<UUID> ro quiet splash $vt_handoff rootfsype=ext4
 initrd /boot/initramfs
 }

If you now run sudo update-grub, it should add Gentoo to the grub list.

Conclusion

I think this is all that is needed in Ubuntu or your current distribution part. You still have to go through all the learning curve, needed to setup Gentoo. For some, the final output is fruitful, for some it is a waste of time. At least, you will know it yourself. 

Good Luck !!

About these ads

Leave a comment

Filed under Uncategorized

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s