HOWTO: Bootable USB with persistance

From Sabayon Wiki
Jump to: navigation, search
The procedure in this article is obsolete. Use UNetbootin instead!
Look here If you want to install Sabayon on EeePc or iBook

Making a Bootable USB from DVD image

One of the big problems of making a bootable USB is file size. Almost all of the how-to's out there that allow to pass kernel commands during the boot process require the use of syslinux, which uses FAT16/FAT32 formated partitions. This comes with the drawback of limiting your maximum file size to 2 Gigabyte if using FAT32. A DVD release has it's main file, livecd.squashfs it can run up to nearly 4 Gigabyte, twice the maximum allowable size. In other words, Epic Fail.

This How-To will be covering use of a variation of a syslinux bootable USB drive, extlinux. As you might figure from it's name it allows you to use ext2/ext3 to format your partitions, thereby removing the 2 Gigabyte limit and allowing you to fit that monster livecd.squashfs onto your thumbdrive. For this example I will be using a 4 Gigabyte thumbdrive and Sabayon Linux 3.5 32 bit.

You might as well go root and stay there. Yes, lots of this can be accomplished via GUI apps, and there are a plethora out there that you can use to accomplish a good chunk of these tasks. Command line though brings us to a common point that all your GUI apps are bolted on to anyway. That and because it's my preferance. From here on out its assumed that you are root.

The first step to this is making sure you have syslinux installed.


# equo install syslinux


# emerge syslinux

I know I said we will be working with extlinux, however extlinux is part of the syslinux package.

Getting it Working

The next step to this is formatting the USB drive. First identify your thumbdrive.

# fdisk -l 

If you read the output of this the first line of each device will tell you the size of the device, which makes it pretty easy to see which is a hard drive and which is not.

Substitue the device path for your USB drive!!!
# fdisk /dev/sdb 
# mkfs.ext2 -j /dev/sdb1 /dev/sdb 

Next is to install the syslinux boot sector, I know we said we were going to be using extlinux, but bear with it for a few. Thumbdrives don't come with a boot sector, so we have to make one and that's what we are doing here.

# dd if=/usr/share/syslinux/mbr.bin of=/dev/sdb

~~ Edit: /usr/lib/syslinux/mbr.bin to /usr/share/syslinux/mbr.bin --dyingmuppet 12:24, 14 January 2009 (UTC) ~~

Now we need to make a few mount points and mount the ISO and the thumbdrive, remember to substitute your thumbdrive location for the one in the example.

# mkdir /mnt/iso
# mkdir /mnt/usb
# mount /dev/sdb1 /mnt/usb
# mount -o loop -t iso9660 /path/to/iso /mnt/iso

(as an example mount -o loop -t iso9660 /home/jim/Sabayon-Linux-x86-3.5.iso /mnt/iso)

Now we copy things over that we will need.

# cp -rvp /mnt/iso/{boot,isolinux,livecd,livecd.squashfs,README.txt} /mnt/usb

~~ Edit: old copy line gives errors, unless you where cd'ed into /mnt/iso --dyingmuppet 12:24, 14 January 2009 (UTC) ~~

This could take awhile with a DVD iso image. The livecd.squashfs is a monster. Go get a cup of coffee and check back in a few minutes. After it is finished copying we can continue on by running the following commands which set up the files for use by extlinux and make the needed changes to the boot sector.

# cd /mnt/usb
# mv isolinux extlinux
# mv extlinux/isolinux.cfg extlinux/extlinux.conf
# rm extlinux/isolinux.bin
# cd /mnt
# extlinux -i /mnt/usb/extlinux 

Your done, wasn't that easy. The final piece to this is unmounting everything we mounted earlier.

# umount /mnt/usb
# umount /mnt/iso

Now you can reboot into the USB drive by selecting to boot from USB, the ways the various BIOS's handle this though are too numerous to list. Typically there will be an interupt option during the POST to select boot device. If not you'll probably have to go into the BIOS itself and find out where to select it.

Adding Persistance

This next bit is a little more interesting. We will have to resize the main partition and add in a second one on the thumbdrive. For this I find that a GUI app is easier to do than command line, so without any more blah blah from me:

# gparted &

1: On the upper right side you will have a device drop down, click it and select your thumbdrive. In my case /dev/sdb.

2: If it is mounted, right click in the drive use display and unmount it.

3: Right click on the drive in the drive use window and select resize.

4: Grab the slider on the left side and drag it all the way to the right.

5: Right click in the blank space click New.

6: Use the whole of the remaining space (or less if you choose)

7: Set it as ext3

8: Click Apply (or OK depending)

9: Click Apply

Editing the necessary files

Remount the thumbdrive, if necessary unplug it and plug it back in. We will work mostly in the original partition, we have only one thing to do in the second.

# cd /mnt
# mkdir usb2
# mount /dev/sdb1 /mnt/usb
# mount /dev/sdb2 /mnt/usb2
# cd usb2
# touch xsistence-mode
# cd /mnt/usb
# umount /mnt/usb2
# cd extlinux

Now then, we have to edit atleast one file here, mostly to make life easier for us. You can use any text editor you like, nano, vi, kate, gedit, etc. However they must be edited as root, so if your trying to use a GUI based text editor you may have to use 'sudo' here even as root to bypass a $PATH problem, I know I have to when using a GUI editor for this.

The first file is isolinux.txt, we will edit this so that the boot options are displayed on the screen at boot time. Something like as follows.

File: /mnt/usb/extlinux/isolinux.txt

Welcome to Sabayon Linux 3.5

Press �F1�control and F then 1� for help and advanced boot modes.
Automatic Monitor detection, to force a resolution use res=<resolution>.�07

To boot Live Mode press enter
To boot Persistant Live Mode type xsistence and press enter
to boot for Eeepc type eeepc and press enter
Other boot options include
tor, nomusic, text-install, genuine, console, memtest

Make sure you have a return after memtest or it will put the boot option entry line on the same line.

The next file you may or may not want to edit is extlinux.conf. Here you can change the boot options. If you just hit enter here without any of the boot options entered this is the line that is booted.

File: /mnt/usb/extlinux/extlinux.conf
APPEND  root=/dev/ram0 initrd=/boot/sabayon.igz aufs init=/linuxrc cdroot looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet music -- 

If however you type in "sabayon" the following section is the one that is booted into. Yes, it is identical to just hitting enter.

File: /mnt/usb/extlinux/extlinux.conf
LABEL sabayon
  menu label ^Start Sabayon Linux 3.5
  kernel /boot/sabayon
  append root=/dev/ram0 initrd=/boot/sabayon.igz aufs init=/linuxrc cdroot looptype=squashfs max_loop=64 loop=/livecd.squashfs
splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet music --  
Everything after "append" is on one line. It is broken by formatting restrictions of the wiki. You have been warned !!!

We can see from that line, that if we did not want the music to play during boot up all we would have to do is remove "music" from the append line.

Or if we read through all the various boot options that are in this file we can set it up so that persistane is activated by default when we boot the thumb drive, simply by adding "xsistence" to the default boot line. Like so:

File: /mnt/usb/extlinux/extlinux.conf
APPEND  root=/dev/ram0 initrd=/boot/sabayon.igz aufs init=/linuxrc cdroot looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet music xsistence -- 

Please note that the trailing " -- " HAS to be at the end of the append line.

Anyway, now you can change the boot options around to your taste and adjust the text of isolinux.txt to reflect your personal choices for displaying those options.

The last thing you need to do is unmount and sync the USB drive

# umount /mnt/usb
# sync

Have Fun ~Az