Friday, February 18, 2011

Gentoo Install (Not live) on a USB stick

Here is a quick tutorial of how to install Gentoo on a USB stick, using the gentoo minimal cd. We start out installing the live cd onto the USB, then migrate it to a proper installation. You don't need to be running any particular distribution, you don't need a cdrom drive, but what you will need is:

1. unetbootin
2. extlinux
3. A usb stick
4. Something to partition the usb stick with
5. The usb minimal iso

First of all, partition your usb stick (using gparted or similar). As we are going to start installing straight from the usb, you need to set this up now, so make room for a swap partition and your root partition. I created one root partition EXT4, and one swap partition, without bothering for a boot partition.

Use unetbootin to install the live cd onto the usb, and specify the root partition that you created just before. When thats done, mount the usb, go to the mount point and run these commands:
mv isolinux extlinux
mv extlinux/isolinux.cfg extlinux/extlinux.conf
rm extlinux/isolinux.bin
rsync -av extlinux
extlinux -i extlinux
Unmount the USB. You should now be able to boot with it.

The USB will boot to the livecd console. If your running DHCP everything should be working (if not, look at gentoo.org), and you can now begin setting up your operating system.

If you check fdisk, your root partition should be mounted in /mnt/cdrom, as readonly. Remount it as read/write.
mount -n -o remount,rw /mnt/cdrom
Now, chroot there.
chroot /mnt/cdrom
mount -t proc none /proc
mount -o bind dev /dev
mount -t devpts devpts /dev/pts
env-update
source /etc/profile
You will need to put in a nameserver in /etc/resolv.conf, as the live cd doesn't have anything in there. Once your done, you should now be able to continue with section 5 of the gentoo handbook, "Installing the Gentoo Installation files". That is, download the stage 3 file, untar in the root directory, and extract portage into /usr.

When its time to compile your kernel, make sure you have all the drivers required for USB (i.e SATA). In this example I have not created a boot partition, so, you will need grub to mount the boot partition rw, and enable Support for large (2TB) block devices (Under enable block devices) EVEN if your USB is no where near that size.

Also, you will need to add another parameter into grub on your kernel line, otherwise risk the error "cannot find root". This delays the kernel from accessing the root partition, allowing your usb drivers to setup properly. Heres an example grub.conf
title Gentoo Linux 2.6.34
root (hd0, 1)
kernel /boot/kernel-2.6.34-gentoo-r1 root/dev/hda2 rw rootdelay=10
If its still not detected, try making it longer.

All thats left to do is remove all the old live cd install files, such as the ones I've listed below in the root directory, and your ready to go.
extlinux           livecd               ubninit
extlinux.conf           menu.c32             ubnkern
gentoo.efimg            stage3-i686-20110215.tar.bz2  
gentoo.efimg.mountPoint syslinux.cfg         ubnpathl.txt
image.squashfs          ubnfilel.txt
Finally, be careful about the USB devices you have; your usb stick may not be always /dev/hda!

Good Luck!

2 comments:

desta said...

hai, this tutorial work with other distro's? like debian or ubuntu?

thx.

Ben Leov said...

Hi,

If I was doing it for Ubuntu, I would probably just use the installer and select the USB drive to install to.