A FOB STORY: some notes on bootable flash drives

Persistence

Unlike consistency (“A foolish consistency is the hobgoblin of little minds…”  Ralph Waldo Emerson ) persistence can be a wonderful thing.

Live bootable media (CDs, flash drives, etc) are ephemeral.  They are either literally read-only, or run as if they were.  Any changes made to the running system – Ubuntu Linux in these examples – disappear at shutdown and aren’t around the next time the flash drive is booted.  That can be a good thing, but there are times when persistence between boots can be useful – when a live distro is updated, for instance, or if a needed wifi driver or useful app  or utility has been added.

Fortunately, a mechanism for this has been added to newer versions of Ubuntu.  There are ways to store persistent data on alternate media – the hard drive on the target system, for instance, or another flash drive – but for our purposes we’ll put the persistent storage on our flash drive.

[Update 2019.04.23]  A little late with this update… Bad news:  as of Ubuntu 18.04 – and perhaps earlier, certainly later – persistence is no longer usable 🙁  Live persistence leads to excessive CPU usage, so severe that it’s a show-stopper.

Got no joy, but here’s the bug report.  There doesn’t seem to be much interest in fixing it.  Not good.  https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1767896

[Update 2019.10.31] Ubuntu 19.10 seems to correct the snapd-related bug and persistence is usable again 🙂

[Update 2019.11.09] Unfortunately Ubuntu 19.10 breaks the ability to boot an ISO in UEFI mode, so it isn’t very usable after all 🙁

[Update 2020.09.13] persistence and ISO booting:

Persistence didn’t work with Ubuntu 20.04.  Just about went up in smoke trying to figure it out.  The name of the persistence file has changed from casper-rw to writable.

There’s a work-around that gets loop-mounted ISOs to boot in 20.04.  Add rmmod tpm to grub.conf as shown below:

if loadfont /boot/grub/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm

# try to work around ISO loop boot problem
rmmod tpm
fi

A somewhat generic, live CD oriented discussion:  Live CD/Persistence

We’ll use the instructions there to create a loopback file with an internal ext3 filesystem.  The exact location of the file is optional, but the name is not.  It must be casper-rw.  Since my flash drives are multiboot, with several Ubuntu distros, I use several persistence files located in a directory named for the distro.

The commands below create a 128MB file with an ext3 filesystem.  It may be necessary to remount the flash drive read/write.  The path to casper-rw will vary depending on the user’s preference on location and where the flash drive is mounted.  That further varies depending on what’s being used to do the creation formatting, an installed Ubuntu, a live CD, a live flash drive – either directly booted or a loop-mounted ISO.  See previous page “Standalone Grub2…” for path examples and remount read/write command.

With the flash drive mounted in a running Ubuntu virtual machine:

$ dd if=/dev/zero of=/media/wdw/307E-B176/bootable/persistent/ubuntu-14.04.1-desktop-amd64/casper-rw bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes transferred in 0.947819 seconds (141606919 bytes/sec

$ mkfs.ext3 /media/wdw/307E-B176/bootable/persistent/ubuntu-14.04.1-desktop-amd64/casper-rw
mke2fs 1.38 (30-Jun-2005)
/media/hda1/casper-rw is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the super user
First data block=1
16 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
   8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

The boot stanza for the above distro + persistence file looks like this.  This is the version booting Ubuntu that’s been copied from the contents of the ISO.  A loop-mounted and booted ISO would use similar persistence entries, but a different boot configuration.  See the previous page “Booting ISOs…”

menuentry "Boot Ubuntu 14.04.1 with persistence" {
    set gfxpayload=keep
    linux /casper/vmlinuz.efi file=/cdrom/preseed/ubuntu.seed boot=casper persistent persistent-path=/bootable/persistent/ubuntu-14.04.1-desktop-amd64 splash --
    initrd /casper/initrd.lz
}

When it comes to persistence files, size matters.  Larger files will slow down booting the particular distro on the flash drive.  The required size will vary depending on need: a few wifi drivers, or a full distro update.

In the interest of speed, it isn’t necessary to use persistence every time a particular distro is booted.  If the target machine doesn’t require updated drivers, just boot the installed distro without peristence.  Multiple grub.cfg boot stanzas can be used for the same distro: one with and one without persistence.

For that matter, persistence isn’t necessary to simply save or add data to the flash drive.  Make the running flash drive writable and just copy data to it.  Since one of these fobs is always on my key chain or in my backpack, I have an “/export” directory where I back up everything and keep frequently used downloads, images, videos…  Where persistence is useful is when the running distro itself has been modified – with added or updated drivers, for instance.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to A FOB STORY: some notes on bootable flash drives

  1. Pingback: FOB Story II | GeezBlog

Leave a Reply

Your email address will not be published. Required fields are marked *