Creating Ubuntu Pen-Drives With Persistence

Ubutnu Pen-Drives

(This is a layman’s guide for creating bootable Ubuntu pen-drives with persistence. It has been sourced from similar other resources, and my own trial and error based observations about such similar pen-drives on my Macbook Air 13. From whatever I’ve understood about the Macbooks and non-Mac platforms until now, any bootable drive that works on a Macbook should also work on a non-Mac PC or laptop. The same could not be spoken with conviction about a reverse scenario, however.)

While there are tools, like Universal USB Installer, available for creating Ubuntu pen-drives with persistence, the 4GB cap they place on the persistent files under a fat32 file system would severely restrict a regular computer user. Creating a non-fat32 persistent partition is, therefore, the prime goal for most regular users of such pen-drives, which is what we are going to focus upon in the remainder of this article.

Let me list out a few observations before I start describing my methods and workarounds for an Ubuntu pen-drive with persistence here.

1) The biggest problem you would face is to overcome the bug described here, which could leave you confused and stranded, if you weren’t aware about it from the beginning.

2) The aforementioned bug would surface up only, if you were trying to create a persistent partition in a live stick, which had all of the Ubuntu’s ISO contents extracted on a fat32 partition.

3) The bug won’t annoy you, if you were…

A) Content with having a 4GB or less in size ‘casper-rw’ persistent file on your pen-drive’s root partition. But aren’t we debating this subject for that same reason, anyway?

B) Aiming to run your pen-drive using the ISO itself.

C) Attempting to have the boot and other system folders extracted into two different partitions on your pen-drive… i.e. ‘boot’ and ‘EFI’ folders on a fat32 partition, and the rest on the subsequent ext4 one.

4) Hence, there are two main routes you could choose from for creating Ubuntu live-sticks with persistence…

A) Running your Ubuntu pen-drive from the ISO itself. This would work, both, for a two partition and a three partition table schemes in your pen-drive.

B) Running your Ubuntu live-stick from  the extracted content of that ISO file. This would only work with a three partition table scheme in your pen-drive. A two-partition scheme would result in the aforementioned bug.

5) In both cases, you would require to boot from a working Ubuntu installation or live-stick (such as the one created by the Universal USB Installer) and Gparted for partitioning and copying the relevant files into your pen-drive.

6) Apart from partitioning and copying the Ubuntu files, you would also need to update the /boot/grub/grub.cfg file accordingly, as described in this write-up later.

7) I used a VB Ubuntu machine on my Macbook Air 13, a 16GB pen-drive and Ubuntu-16.04.3-desktop-amd64.iso for creating my pen-drive with almost 12GB of persistent storage.

Creating Ubuntu live-sticks with persistence from UBUNTU’s ISO file…

Boot from a working Ubuntu installation or live-stick. Partition your pen-drive (it would obviously be erased now, hence backup if required) using the Gparted tool into three primary partitions, viz. a 350MB fat32, a 2GB ext4 and the remainder of space carrying ext4 formatting. Flag the first one as boot and lba, apart from labelling the third one as ‘casper-rw’ as shown below.

Three Partition Scheme In Gparted

Extract the Ubuntu ISO and copy the boot and EFI folders into the first partition. Copy the ISO file into the second partition. Now replace the menuentry for “Try Ubuntu without installing” with the following text in /boot/grub/grub.cfg…

(Remember to replace smart quotes with regular/ straight ones in each of the below grub.cfg entries… or press Control+Shift+V or Command+Shift+V for pasting these entries in your grub.cfg file, depending on your operating system. Thank you Passiday for suggesting this.)

menuentry “UBUNTU LIVE” {
set gfxpayload=keep
set isofile=”/ubuntu-16.04.3-desktop-amd64.iso”
loopback loop (hd0,2)$isofile
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile quiet splash noprompt persistent —
initrd (loop)/casper/initrd.lz
}

In case of a two partition scheme, the ‘boot’ and ‘EFI’ folders, as well as the Ubuntu’s ISO file must be copied into the first fat32 partition of, say, 2.5GB in size, and the other – an ext4 one – must be labelled as ‘casper-rw’ for persistence. The concerned menuentry(ies) should be updated as well in gurb.cfg accordingly…

menuentry “UBUNTU LIVE” {
set gfxpayload=keep
set isofile=”/ubuntu-16.04.3-desktop-amd64.iso”
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile quiet splash noprompt persistent —
initrd (loop)/casper/initrd.lz
}

Both above procedures should result in a bootable Ubuntu pen-drive with more than 4GB of permanent storage.

Creating Ubuntu pen-drives with persistence from the extracted content of the ISO file…

As stated earlier, this would only work in a three-partition scheme. Boot from a working Ubuntu installation or live-stick. Partition your pen-drive using the Gparted tool into three primary partitions, viz. a 350MB fat32, a 2GB ext4 and the remainder of space with ext4 formatting again. Flag the first one as boot and lba, apart from labelling the third one as ‘casper-rw’.

Extract Ubuntu’s ISO and copy its boot and EFI folders into the first partition, and the remainder of the content into the second one. Now replace the menuentry for “Try Ubuntu without installing” again with the following text in /boot/grub/grub.cfg…

menuentry “UBUNTU LIVE” {
set gfxpayload=keep
set root=(hd0,2)
linux /casper/vmlinuz.efi boot=casper quiet splash noprompt persistent —
initrd /casper/initrd.lz
}

This would again create a bootable Ubuntu pen-drive of more than 4GB of persistent storage.

(Update: A recommendation for ext2 formatting, instead of the ext4 I’ve suggested in the above solutions, has been made by EvilSupahFly (seann-giffin) on https://launchpad.net/ubuntu/+source/casper. I know about the pros and cons of both these options, but am not technically proficient enough to decide about the best choice. So, I’d rather leave it on the readers to decide about it themselves.)

2 thoughts on “Creating Ubuntu Pen-Drives With Persistence”

  1. Excellent work, thank you! The only thing to note is that you should replace the smart quotes with straight ones, in the grub.cfg listings, for the peace of mind of those poor souls who copy-paste it. And I wonder why the bug that calls for such a painful fix is left unsolved for such a long time.

  2. Thank you Passiday for your comment, and glad to know this is helping out others as well. It’s surprising indeed, why this bug has been allowed to continue for so long. I myself had given up on creating a larger ‘casper-rw’ file for several months before finally deciding to do some trial and error kind of hard work (based on some remotely – if not directly – related observations, of course).

    The smart quotes issue does not seem to be that easier in this case. I added several solutions in functions.php to stop it’s forced implementation, but in vain on each occasion. So, I’m adding a friendly warning about this in the above blog post, till I can find a workable solution with other means.

Leave a Reply

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