http://www.gentoo-wiki.info/HOWTO_LiveUSB_Key
HOWTO_LiveUSB_Key
This is the perfect project for that spare 1GB usb key you have laying dormant in your desk drawer.
Contents |
Purpose
This HOWTO makes puts the latest Gentoo release onto a USB key and makes it bootable.
Sample reasons to follow this HOWTO include:
- The latest 2008.0 LiveCD ISO images, at just over 800MB, are larger than the regular CDs you have available.
- Your computer does not have an optical drive.
The Gentoo Linux LiveUSB HOWTO documents how to emulate a Gentoo Linux 2007.0 LiveCD using a USB flash drive. With 2008.0, Gentoo started to use GRUB as the bootloader for installation media so an updated procedure is required.
For this HOWTO we choose to use the FAT filesytem and the GRUB bootloader. GRUB because it was chosen by Gentoo Release Engineering for their latest releases, and because it allows for the simplest procedure. We choose FAT because it is ubiquitous on these devices, see Wikipedia
The HOWTO LiveUSB uses the ext3 filesystem and the extlinux bootloader.
Instructions
We will check the partition table, reformat the device, mount it and the install media, copy some files, unmount both, install the bootloader and then test the finished product!
Check Partition Table
To read the partition table use:
fdisk -l /dev/sdc
Code: Sample fdisk Output |
Disk /dev/sdc: 2063 MB, 2063597056 bytes |
The key should contain a single partition using all of the available space. For a key smaller than 4GB the System column should read FAT16; set the type to 6. If your key is 4GB or larger it should be W95 FAT32; partition type b.
Running the fdisk command without the -l switch modifies the partition table:
fdisk /dev/sdc
Format
Formatting the disk ensures a blank slate for the rest of the procedure. Depending on the size of your device, a slightly different filesystem is required. Note that you will need sys-fs/dosfstools emerged to have the mkdosfs command available.
Create a blank FAT file system on your device, if smaller than 4GB:
mkdosfs -F 16 /dev/sdc1
If 4GB or larger, create a blank FAT file system:
mkdosfs -F 32 /dev/sdc1
Mount Devices
You will need a copy of a 2008.0 ISO image which you can download from the Get Gentoo! page. Here we mount this image and the target USB key onto the local file hierarchy. Replace image.iso below with the filename of your download.
mkdir -p /mnt/cdrom /mnt/usb
mount -o loop image.iso /mnt/cdrom
mount /dev/sdc1 /mnt/usb
Copy Files
The sys-boot/grub package includes GRUB stages which we now copy onto the USB key, later we will install them into the key's MBR.
Copy over the ISO contents and GRUB stages:
cp -r /mnt/cdrom/* /mnt/usb
cp /lib/grub/i386-pc/stage1 /mnt/usb/boot/grub/
cp /lib/grub/i386-pc/stage2 /mnt/usb/boot/grub/
cp /lib/grub/i386-pc/fat_stage1_5 /mnt/usb/boot/grub/
Unmount Devices
All of the required files are now on the USB key, so we can detach the disc image and the USB key from the directory tree.
umount /mnt/cdrom
umount /mnt/usb
Install GRUB
GRUB can be installed onto the USB key in either of two ways: using grub-install or manually. grub-install needs to probe devices so will not work in a chroot.
The Gentoo Grub Error Collection documents some common problems installing GRUB.
Using grub-install
grub-install /dev/sdc1
Manually
grub
Then at the GRUB command line:
grub> root (hd1,0)
grub> setup (hd1)
grub> quit
Test
You should now have a USB key which will run the latest Gentoo release media. Insert it and turn on the the target computer, making sure the BIOS is set to boot from USB. You should now have booted your favorite operating system.