Portable USB Gentoo

Introduction
This document describe how to install Gentoo to an external USB hard disk as a portable operating system.

It assumes you have the experience of a manual Gentoo install, have followed the Gentoo handbook, and you know exactly what you did, oh you!

Now this article should be enough for an experienced user to install a bootable Gentoo Linux System on an external USB hard disk.

But it still lacks some important tasks like auto configuration for Xorg or OpenGL interface, so feel free to extend this.

If you find you could not get things to work by following this guide, you could ask your question in the discussion page, and I will see if I could tell you what is going wrong.

Since English is not my native language, and I did not study it hard in school (reprioritized after I discovered the opposite gender and linux), maybe there are lots of misspellings, grammatical errors and other delightfully horrible sentences, so it is welcome to correct these things directly.

Issues
There are some issues to be solved when we tried to make Gentoo Linux as a portable operating system. The following is the list of all issues.


 * How to handle swap partition.
 * How to make ROOT partition parameter in GRUB and fstab portable.
 * A portable kernel.

How to Read This
This HOWTO assume you are installing Gentoo to an external USB hard disk by following Gentoo Handbook and this HOWTO. Basically, you will just follow the Gentoo Handbook, and we will tell you when to pause and what to do.

Notation
In the very beginning of every section, we will have a tip box to tell you where you should stop and follow the process this HOWTO mentioned.

This means you should follow the instruction before continue to Gentoo Handbook x.y section.

This means you should follow the instruction after done Gentoo Handbook x.y section.

This means you should follow the instruction during Gentoo Handbook x.y section, and some instruction mentioned in Gentoo Handbook should be change

Preparing Root Partition
Just like the normal installation, you need prepare your disk partition first. We assume you have already create a root partition.

Remember that you do not need to create a swap partition, since we would use a swap file instead of swap partition, and we don't need /boot partition neither.

The following process, we assume your Portable USB Gentoo root partition is located at /dev/sdb1. Please change these device path according to your situation.

Create Filesystem with LABEL
After root partition is ready, we need creating a file system with disk label. Disk label is a identifier of your partition, which would not change when you use your USB hard disk from computers to computers.

You could create file system with label using the following commands.

If you decide to use ext3 filesystem:

If you want use ReiserFS:

Please remember the label use used here:USBLinux, we will use it later.

Now, please follow the Gentoo Handbook until section 6.a.

Preparing SWAP file
After installed the basic system, we need create a swap file.

Create SWAP file
The following command will create a 1G file at /mnt/SWAP as a swap file.

Active SWAP
Now, you could enable this swap file by the following command.

Install Kernel
We need a generic kernel which could boot on most X86 computers and auto-detect your hardware when boot, so you need use genkernel at Gentoo Handbook Chapter 7.

You need add a --disklabel argument when you run genkernel.

Now, continue the Gentoo Handkbook until chapter 8.

Filesystem Information
You have to use LABEL in your /etc/fstab, so your root partition and swap file could mount on any computer, even the device path is different.

Your /etc/fstab should contain at least two lines: root partition and swap file.

These two line should look like the following:

Now continue Gentoo Handbook until chapter 10.

Install Bootloader (GRUB)
Replace the value of real_root parameter from something like /dev/XXX to LABEL=USBLinux, so the config file of Code Listing 2.4 in handbook should look like the following now:

Of course remember change the root (hd0,0) stuff according to your disk partition plan.

Now follow the handbook to install GRUB as your bootloader, also remember you should install your GRUB on the MBR of your USB HD.

After install GRUB on your USB HD MBR, remember modify this config file and make sure you use "root (hd0,X)", because on most BIOS, if you boot from USB disk, then your USB disk will be (hd0) in GRUB.

Clean UUID/LABEL Cache
We need delete blkid cache when we turn off computer. Open /etc/conf.d/local and add the following line in local_stop function.

Now continue the handbook chapter 11, and you should have a bootable a Portable Gentoo Linux on external USB hard disk.