Linux: Persistent Live USB with Extra Space

Apparently, persistent live USBs are fairly simple to set up. I originally learned to create one for Linux Mint Debian Edition from here. It turns out that the procedure is exactly the same for some other ISOs. Specifically, I tried it on CrunchBang because I couldn’t find a specific guide for CrunchBang Waldorf. I also prefer to have some extra space on my USB for other storage space, so I tried tacking on an extra partition at the end, and it worked! (Your mileage may vary; at least one OS, Elementary, didn’t work with this method.)

Ingredients:

  • Unetbootin (Windows or Linux)
  • Gparted (Linux) or other hard drive partitioner (Windows)
  • Text editor (Windows or Linux)
  • USB drive

Directions:

1. We will be using Unetbootin for the initial ISO install. Unetbootin will not recognize the drive unless you format the drive to FAT32.

fat32_2fat32_1

2. Also, so Unetbootin doesn’t complain about not being able to access the drive, you will need to mount the USB drive somewhere. I’m assuming that your drive is /dev/sdb and mounted in /media/mountpoint; replace as needed.

sudo mount /dev/sdb1 /media/mountpoint

3. Using Unetbootin, install the ISO of your choice on your USB.

unetbootinunetbootin_1unetbootin_2

4. You can reboot and see if the ISO installed correctly; you will need to press the designated key for your motherboard so that your computer will boot from a secondary device. If you can boot into the ISO, you’ve got the live USB part. Now for the persistence part. If you did reboot, boot back into your computer.

5. If you didn’t reboot, make sure you unmount the USB so Gparted doesn’t complain in the next step.

sudo umount /media/mountpoint

6. Using Gparted, shrink the partition with the ISO. How much you do this is up to you; the ISO isn’t going to get any bigger, but I made mine larger so that if I ever want to swap the ISO out for a larger one, I don’t need to repartition.

gparted_1

7. Using Gparted, create another partition labeled “persistence.” This is the partition holding all the persistent data. I made mine 2GB so I’d have plenty of room for persistent applications, settings, and other things. Format it ext2, ext3, or ext4. I like ext2 because it has less overhead.

gparted_2

8. Finally, again using Gparted, create another partition and let it fill the rest of the space. This is the extra storage partition. Format it whatever you’d like; I picked NTFS so that it would still be readable from Windows.

gparted_3

9. Before you apply your changes, make sure you’ve done all the previous partitioning steps correctly. Then, apply your changes.

gparted_4

10. Mount the first partition, the one with the ISO.

sudo mount /dev/sdb1 /media/mountpoint

Open syslinux.cfg, at the root of the partition, in a text editor. For the “unetbootindefault” and “ubnentry0” labels, under “append,” after “boot=live,” add the word “persistence.” For those two blocks, it should look like this (with the additions in bold):

label unetbootindefault
menu label Default
kernel /ubnkern
append initrd=/ubninit boot=live persistence config quiet

label ubnentry0
menu label Live Session
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live persistence config quiet

This tells the bootloader to tell the kernel to be in persistence mode (I think). Save the file.

11. Mount the second partition, the persistence one.

sudo mount /dev/sdb2 /media/mountpoint

Create a single file named “live-persistence.conf.” Open it in a text editor and insert a single line:

/ union

I have no idea precisely what this does; I think it persistent-izes all of the root filesystem. Save the file.

12. Reboot into the USB. You should now have a persistent live USB with a bit of extra space at the end.

13. If you ever want to change distros, just use Unetbootin to install another  ISO. Make sure you edit syslinux.cfg in the root partition for the new distro, and don’t forget to wipe all folders (but not live-persistence.conf) from the persistent partition.

EDIT: it looks like Elementary, Ubuntu-based Linux Mint, and Ubuntu itself uses a casper-rw partition instead of a persistence partition. A good guide for the Ubuntu-based Linux Mint, which I couldn’t get to work persistently without this workaround, is here. The workaround essentially creates a casper-rw partition, tells unetbootin to set up persistence for a 100mb casper-rw file, and deletes the file. This sets all the settings necessary for persistence, but it allows use of the partition instead of the file.

Advertisements
Tagged , , , , ,

One thought on “Linux: Persistent Live USB with Extra Space

  1. lliseil says:

    Nice share.
    Note that putting the storage partition anywhere but in the first place will make it unusable for Windows OSes. I learned it the make-me-feel-stupid way 😉
    Not Debian Live Manual or other sources’ fault: many warn on this Windows “feature” eg http://www.prime-expert.com/articles/a05/enabling-multiple-partitions-on-removable-usb-storage-devices.php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: