Tag Archives: Live

Gentoo Live USB

1. Introduction

The LiveUSB

This HOWTO explains how to create a Gentoo Linux LiveUSB or, in other words, how to emulate an x86 or AMD64 Gentoo Linux LiveCD using a USB flash drive. This is particularly useful for installing Gentoo Linux on a modern laptop with no CD-ROM drive.

Note: The sys-boot/unetbootin package provides a much easier alternative to create a bootable USB stick from any bootable CD image.

Although the instructions found in this document aim at emulating a Gentoo Linux LiveCD using a USB flash drive, they should work for any arbitrary block device as long as you adjust the device names accordingly.

Prerequisites

In order to use a Gentoo Linux LiveUSB you need the following:

  • Bootable USB flash drive with at least 1GB
  • i686 or x86_64 computer with support for booting from USB

You will also need access to the following for creating the LiveUSB:

  • A computer running Gentoo Linux (or alternatively another Linux distribution)
Note: If you want to use the minimal CD on a smaller key or boot a <i686 system, you need to follow the procedure described in this document with a 2006.0 minimal CD image because of a bug in more recent releases.

2. Preparing the USB flash drive

Partitioning the drive

Warning: These instructions will erase all data from the USB flash drive. Make sure to backup your data first.
Important: This HOWTO assumes that the /dev/sdc device node corresponds to your USB flash drive. If you have other SCSI-like devices make sure to use the correct device node.

Create a FAT16 partition on your USB flash drive and mark it bootable using fdisk. An example partitioning scheme can be seen below:

Note: If your key is 4GB or larger, use partition type b (W95 FAT32).

Code Listing 2.1: Example partitioning scheme
# fdisk -l /dev/sdc

Disk /dev/sdc: 2063 MB, 2063597056 bytes
255 heads, 63 sectors/track, 250 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1         250     2008124+   6  FAT16

Creating the filesystem

Create a FAT16 filesystem on the USB flash drive using mkdosfs:

Note: If your key is 4GB or larger, use -F 32 to create a FAT32 filesystem.

Code Listing 2.2: Running mkdosfs
(Make sure you have sys-fs/dosfstools installed)
# emerge -av sys-fs/dosfstools
# mkdosfs -F 16 /dev/sdc1
mkdosfs 2.11 (12 Mar 2005)

Installing a Master Boot Record

Install the precompiled Master Boot Record (MBR) from syslinux on the USB flash drive:

Code Listing 2.3: Installing a master boot record
(Make sure you have sys-boot/syslinux-3.00 or later installed)
# emerge -av '>sys-boot/syslinux-3'
# dd if=/usr/share/syslinux/mbr.bin of=/dev/sdc
0+1 records in
0+1 records out
304 bytes (304 B) copied, 0.0162317 s, 18.7 kB/s

3. Copying the files to your key

Mounting the Gentoo Linux Installation CD

Download either livecd-i686-installer-2007.0.iso or livecd-amd64-installer-2007.0.iso from your local Gentoo Linux mirror site and mount the ISO image on /mnt/cdrom as shown below:

Code Listing 3.1: Mounting the Gentoo Linux Installation CD ISO image
(Create the /mnt/cdrom mount point if needed)
# mkdir -p /mnt/cdrom
# mount -o loop,ro -t iso9660 livecd-i686-installer-2007.0.iso /mnt/cdrom
Note: If you receive a Could not find any loop device error message when mounting the iso, you need to enable the Loopback device support option in your kernel configuration.

Mounting the LiveUSB

Mount the newly formatted USB flash drive on /mnt/usb as shown below:

Code Listing 3.2: Mounting the USB flash drive
(Create the /mnt/usb mount point if needed)
# mkdir -p /mnt/usb
# mount -t vfat /dev/sdc1 /mnt/usb

Copying the files

Copy the files from the Gentoo Linux Installation CD to the LiveUSB. The files need to be reordered a bit as we will be using the syslinux bootloader instead of isolinux:

Code Listing 3.3: Copying the files
# cp -r /mnt/cdrom/* /mnt/usb
# mv /mnt/usb/isolinux/* /mnt/usb
# mv /mnt/usb/isolinux.cfg /mnt/usb/syslinux.cfg
# rm -rf /mnt/usb/isolinux*

(The memtest86 kernel needs to be renamed for loading it via syslinux)
# mv /mnt/usb/memtest86 /mnt/usb/memtest

You can now unmount the ISO image:

Code Listing 3.4: Unmounting the ISO image
# umount /mnt/cdrom

Adjusting the bootloader configuration

Adjust the syslinux configuration file using sed as shown below. The slowusb parameter will introduce some extra delays before attempting to mount the filesystem. This is needed to allow the USB flash drive to settle upon detection.

Code Listing 3.5: Adjusting the boot parameters
# sed -i \
    -e "s:cdroot:cdroot slowusb:" \
    -e "s:kernel memtest86:kernel memtest:" \
    /mnt/usb/syslinux.cfg

4. Installing a bootloader

Unmounting the drive

Make sure you unmount the USB flash drive before installing the bootloader:

Code Listing 4.1: Unmounting the USB flash drive
# umount /mnt/usb

Installing syslinux

Finally install the syslinux bootloader on the USB flash drive:

Code Listing 4.2: Running syslinux
# syslinux /dev/sdc1
Important: You will need to rerun syslinux /dev/sdc1 each time you modify the syslinux.cfg file for the configuration changes to take affect.

5. Using the LiveUSB

Booting

Insert the USB flash drive and turn on the computer, making sure the BIOS is set to boot from USB. If all goes well you should be presented with a standard syslinux prompt.

You should be able to follow the generic installation instructions found in the Gentoo Handbook from here on.

The contents of this document are licensed under the Creative Commons - Attribution / Share Alike license.