Score:1

Trying to create a custom RAM-backed Ubuntu Live USB with optional persistence

jp flag

I've been racking my brain trying to figure out the best way to do this. It might sound a bit confusing, so let me explain the "why" first.

I already have a Linux live USB stick (on a high-end 256GB Samsung USB stick that's as fast as an SSD, it works great!) But what I want is to create a different Linux USB stick(s) only for performing basic bulk tasks like cloud restores or running the same maintenance script on different laptops/desktops at once. Some of these are in various states, various OSes, some don't even have a network connection... But sticking in Linux USB with the files I need and a standardized script running/recovery environment is perfect.

Problem is, I obviously have a limited number of USB sticks. What I want is to be able to boot into the OS and have it all stay in RAM, then pull out the USB stick and nothing weird happens, it just keeps going. Well guess what already does this out of the box? The Ubuntu Live 22.04 installer in "Try Ubuntu" mode. This also has the advantage of taking up way less space than a standard 22.04 install, which also means less RAM use as the disk is stored entirely in RAM. It takes up as little as 1.6GB by my observation.

Update: By removing maybe-ubiquity from grub, I was able to get the system to boot directly into the Live Ubuntu rather than the installer. Thanks to @Raffa for the help with that. Secondly, I was able to customize the non-persistent filesystem (under /casper/filesystem.squashfs) by using the unsquashfs tool, booting a VM, changing stuff, and re-making it. However, this is super inconvenient, especially if you only want to make a small tweak.

Also, I can confirm that even with the toram option added to grub, the persistent partition (which fyi, you get by simply naming an ext4 partition 'writeable' and booting with the persistent option) DOES NOT get cached. The system will immediately glitch out and eventually hang/crash upon removal of the USB. In non-persistent mode however, things are now nice and stable when the USB is removed. I even wrote a script that safely unmounts the USB on boot, so you're good to remove it as soon as you see the desktop come up.

One idea I have is that I could automate the unsquishing and resquashing process, so that you can literally boot into non-persistent mode like normal, but upon running a script, the RAM contents are written back into filesystem.squashfs. This has the risk that data will be lost if the system powers off unexpectedly, but given that I'd only be making changes every once and a while, and under most cases only using non-persistent mode, this makes sense for my use case.

guiverc avatar
cn flag
You've not provided any Ubuntu product/release details; but not all ISOs use the `maybe-ubiquity` option (ie. not ask ask if you want to TRY or INSTALL), so if I wanted to create aush a system I'd explore those. You also ask about the TORAM option, but without the product/release details I just glanced at your question (*as didn't have a specific ISO/product to consider*).
Raffa avatar
jp flag
For live USB to RAM see for example: https://askubuntu.com/a/829962 and for installed system to RAM see for example: https://askubuntu.com/a/1416932
jp flag
@guiverc Okay, added in which ISO I'm using specifically. I do see the "maybe-ubiquity" in my grub config.
jp flag
@Raffa Do you know if adding that "toram" option would mean that the persistent partition also gets put into RAM? Cause that's currently the issue I have. the persistent patriation is not held in RAM. But if I don't have persistent mode on then everything seems to be in RAM (without the toram option, even.)
Raffa avatar
jp flag
I haven’t verified it but according to [this](https://manpages.ubuntu.com/manpages/trusty/man7/live-boot.7.html) read-only Media is copied … You could however let it boot normally and then move everything to ram including the persistent partition … You can write a script to automate that … See the second post I linked to above for a kickstart … It will involve a lot of plumbing though :-)
Joepie Es avatar
eg flag
If you use Ventoy you can put more than 1 .iso on the USB stick/memorycard. Install Ventoy on the device. Than just drag and drop the .iso files into the Ventoy folder. Easy. You can install it with persistence, so it will create a folder or a partition for that.
jp flag
@Raffa That is a potential option. Also I made some progress, I'll update the post in a sec
jp flag
@JoepieEs Unfortunately I don't see anywhere that Ventoy can create Live USBs with this ability to cache everything to RAM so the USB can be removed. The Ubuntu Live USB is doing this already, I just need to get RAM-cached persistence to work, preferably with minimal use of RAM.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.