Install Gentoo on a bootable USB stick/zh-cn

从U盘启动Gentoo真的很简单. 主要的挑战是设置一个初始的ramdisk，并囊括所有要启动的机器的驱动程序. 本文将介绍如何将Gentoo安装到可以在任何计算机上启动的U盘上. 这种安装就像一般的桌面安装一样. changes will be persistent.

准备
Start by installing a couple of necessary packages. Most importantly these are a kernel and the package:

To add package-specific useflags, create a new file in :

接下来安装 包：

编译内核
Make the required changes to the kernel and compile it. Please see 配置内核 and the 内核配置向导 for more detail on this step. Importantly remember that a general kernel is better here because the more general it is the more machines will boot with it.

During the configuration, it is of course possible to compile modules as these will be included in the initramfs and loaded at boot.

The above command will take some time as it will build the default kernel, create a ramdisk and then copy all files into.

准备U盘
Create 2 partitions on the drive (assuming the installation will have a and a  (root) partition). We assume that the USB stick is at (run  immediately after plugging in the USB stick to see which device is being used).

Make sure that the first partition is bootable (a command toggles the boot flag).

Now format the new partitions. In the example we use the ext2 file system but another file system for the partition can be used if it is supported in the kernel. Notice that during the formatting operation, a label is assigned to the partitions. This is important because it will be how the root file system is detected later as the USB stick can be booted on systems where the drive letter allocation is completely different. This is related to the  option of the  command line earlier.

Gentoo stage 3安装
With the kernel, ramdisk and file systems ready, we now need the minimal installation to be performed. This includes a fresh stage3 as well as a Portage tree snapshot.


 * current-stage3
 * portage-latest

For this example and  are used. This next bit is the same as in the handbook for installing Gentoo.

The sections below cover those aspects of a Gentoo Linux installation that are specific to installing on an USB stick. It is recommended to use the Gentoo handbook instructions while keeping an eye on this article.

Bootloader
In order to boot the new system, install a bootloader on the USB stick.

The below sections give example configurations for either using grub or using lilo together with syslinux.

grub
Emerge grub (from within the chroot):

Install grub to corresponding place with your platform information. Suppose you are running x86_64 machine with EFI partition mounted to, the following command will install grub into the USB stick:

If nothing bad happens, run  to generate grub configuration.

Change the target directory accordingly if you use a different grub config directory.

lilo
Emerge lilo (from within the chroot):

Edit so that it has the correct information in it.

The lines after image are all easy but the append line contains some interesting options.


 * will use the label of the disk instead of which is important because these device numbers move around depending on the number of hard disks in the computer or number of USB disk drives.
 * Also important for USB booting is the  option, as USB devices need a little time to be detected by the kernel; that is what this option is for. When there are lots of modules booting takes a long time so it probably does not matter, but if there are only a few modules loaded then it is important, because the system could have booted before the kernel detects the USB device. Also, on newer machines with USB3 controllers it is necessary to add the   driver (built into the kernel or as a module).

Now install LILO (with the configuration) on the USB stick:

The first warning is to be expected as we are not installing the boot loader onto the hard disk in the computer. The second warning will only cause a problem on machines that are old; if it is a problem try cutting down the kernel by removing modules.

syslinux
Put the boot sector onto the USB stick.

Now to configure the bootloader.

Next install syslinux onto the USB stick. The  option is not absolutely necessary though.

提示与技巧
Although it is possible to use the system just made as a standard Gentoo system, it might be worthwhile to compile binary packages on a host and then installing them on the USB stick. Or if the system has enough memory just mount to a tmpfs, as compilation will be much quicker that way anyway!