How to Create Live USB with Persistent Storage
This project is work in progress (unfinished at the moment). I was asked to create a live USB with persistent storage for Anuko Time Tracker
, which is a PHP application.
I already have a custom ISO image that installs CentOS 7 and all required components for the application. I need to figure out how to make a bootable Live USB
out of it. The data need to be persistent between sessions, meaning that the database data and files created during application use need to stay
- Ubuntu Linux 16.04 LTS or 18.04 LTS as development machine.
- Already available custom ISO image (the one from Anuko website) that install CentOS 7 and Anuko Time Tracker on top of it. The image is based on Minimal ISO, so there is no GUI.
- UEFI based system, on which to create, and then use Live Time Tracker USB.
This project is currently work in progress, The following things were tried so far, with some conclusions.
- Researched an option to install the OS onto USB stick / pendrive and running it from there with complete persistence, This did not work well for my hardware at all. Because of painfully slow response, installation took several hours to complete, and after install I saw timeouts when attempting to run things from it. Although there are tweaks to try for better performance, this option looks like a support hell for a production environment.
- Startup Disk Creator, which comes with Ubuntu 16.04 cannot be used, because it creates a read only filesystem, I have not tried the one that comes with 18.04 but expect it to be the same. Internet searches reveal that earlier versions of this program were capable of creating writable partitions but were buggy. This leaves us with manual tools. More details below.
- Tried Linux Live Kit to create an ISO from a running OS. At this time, I can create an ISO image. I am currently stuck with actually using it as both Live CD and Live USB. As Live CD option is simpler because of no persistent storage at all, I am working on Live CD at the moment. I am now able to boot the kernel from CD but the provided init script cannot find data bundle file (although it is there). More on this below,
- If I resolve Live CD issue in my setup, I anticipate a further, and perhaps a more advanced challenge with Live USB option, specifically with data persistence. The database is backed up into a volume inside a Docker composition in my application. I envision a difficulty with figuring out how to make this working with USB. Because of this, my plan B is to try slax OS instead of CentOS, which means repackaging my entire appliance from scratch.
This seems like an easy part.
We'll try to use Linux Live Kit from https://www.linux-live.org
to create an ISO of a running system. According to their docs "It is a set of shell scripts which allows you to create your own Live Linux from an already installed Linux distribution. The Live system you create will be bootable from CD-ROM or a disk device, for example USB Flash Drive
, a camera connected to USB port
, and so on. People use Linux Live Kit to boot Linux from iPod
- Start with a Time Tracker system created from custom ISO.
- Download linux-live-master.zip to /tmp directory. Unzip it.
- Istall squashfs-tools and mkisofs packages.
- Install zip package.
yum install squashfs-tools
yum install mkisofs
yum install zip
- Docs in /tmp/linux-live-master/DOCS/ tell us to change LIVEKITNAME variable in config file. This is a directory name on USB where everything will be located. If we change it to anuko, we'll get /tmp/anuko-x86_64.iso file after build, and if we don't: /tmp/linux-x86_64.iso. Don't change it, as the docs are not fully relevant in our situation (explained below).
- Run /tmp/linux-live-master/build.
- Run /tmp/gen_anuko_iso.sh to get /tmp/linux-x86_64.iso file.
Now that we have an ISO file, burn it onto a CD and try to boot from it. It does display a yellow boot selection screen as shown below, but won't boot, because kernel file is missing.
Linux Live Kit ISO Boot Selection
To fix this, I had to make the following modifications on the source OS (copied the kernel file).
# cd /boot
# cp vmlinuz-3.10.0-957.el7.x86_64 vmlinuz
Then, adjusted /tmp/linux-live-master/config
file by editing the VMLINUZ string as so:
Created ISO and burned a disk again. Now it boots and finds the kernel. However, there is another problem: it does not find a data bundle
Linux Live Kit ISO failing to find data bundle
Apparently, as find_data_try
string in debug output reports, it looks for data in /memory/data/
directory and it is not there.
In the end, it prints the following error message:
Fatal error occurred - Could not locate linux data
Something went wrong and we can't continue. This should never happen.
Please reboot your computer with Ctrl+Alt+Delete ...
If we examine the image by looking into the zip file that the utility also allows to generate we can see that the 01-core.sb
file is there in the root of the directory, but the init
script at boot is looking somewhere else for it. How do we make it find the data bundle?
// TODO: fix the init script to find data bundle, if using slax OS (below) fails. Currently investigating slax OS.
Initially, I thought I could use Startup Disk Creator
from Ubuntu 16.04.
Using it to create a startup USB from Ubuntu 18.04 ISO image works (I tried with a couple of USB sticks), in a sense that I get a bootable USB. The system can boot from it. But there are a couple of problems.
- Problem 1. Data is not persistent. Saved document on desktop is no longer there after reboot. The file system on USB is read-only.
- Problem 2. On power down, it asks to "Please remove the installation medium, then press ENTER:". Removing the USB stick keeps it usable (and bootable). But NOT REMOVING the stick makes it no longer bootable, and we see the "Reboot and Select proper Boot device" when attempting to boot with it.
The above means Startup Disk Creator
is useless in our situation.
Using Slax OX Instead
My current plan is to repackage everything into a customized Slax OS
instead. We can download Slax OS
ISO from https://www.slax.org
Let's see how to install Time Tracker application in there, trying SSD install first to speed things up.
Here is what I needed to do to make Slax OS bootable from SSD:
- Downloaded an ISO and burned a CD.
- Booted from a CD, which runs Slax in Live CD mode,
- Had a spare SSD in my system installed for experimentation, assuming in advance a complete loss of data.
- Used fdisk in running Slax to erase all existing partitions in my SSD (/dev/sda).
- Rebooted Slax to notice the changes on SSD, then formatted it as ext4 using this command.
mkfs --type=ext4 /dev/sda
- Copied /slax directory from ISO image onto the root of SSD drive. To do that, I first copied the ISO onto a USB, then was able to see the /slax directory in there and copied.
- Finally, ran /slax/boot/bootinst.sh in it to make the drive bootable.
The above seemed to work, and now I can boot from SSD.
Slax OS running off SSD
Procedure to install Docker and docker-compose on Slax is described at http://www.doitcontractors.com/projects/0033/how_to_install_docker_on_slax.htm