I want to be able to boot from a live Ubuntu USB stick, and then using a rsync script permanently on that USB stick, make incremental snapshots (backups) of my main Debian system to a 2nd hard drive.
One would think that making a persistent live Ubuntu USB stick would be so easy, but most live USB makers don't allow for persistence, and those that do, haven't worked. This includes UNetBootin, even after I locally compiled and debugged the missing dependencies. So I want a simple, terminal only, solution that I can understand and debug when necessary.
The simple dd from iso, and then add casper-rw file method had problems with partitioning tools getting confused by the non-standard efi partition image. (ref)
Some solutions, like UNetBootin got close to working, but when I tried to do a sudo -s to get a root shell, they would crash and dump, and destroy my live USB image.
Best Answer
Most of the solution (below) comes from this great article which comes close to working, but not quite, as it needs some updates a few places. But I suggest you look at it, as it's more complete in explanation of steps.
This is for my BIOS based laptop. I'm guessing this might not work for a EUFI boot machine.
TIPS:
Don't make the grub configuration file as that article above suggests, but rather as I show below.
Once you finally have it working below, you'll find that over time the file system will become full unexpectedly. I finally figured out that this occurs because Ubuntu is silently doing
apt-get update
and this will fill up all of your file space and then you'll get a warning message. (It took me a couple of years to figure out what was going on.)The initial fix was to do
apt-get clean
to dump the apt cache, but this doesn't really solve the underlying problem. Then I tried simply disabling the wi-fi so it couldn't do an automatic update. This works great for me! Now my sticks last a long time without problems.Steps carefully tested to work:
1. Download Ubuntu 16.04 ISO image here.
2. set some variables to use below:
3. Plugin and optionally erase If partitioning fails below the erase is recommended. (Before when I had dd'ed an iso image to the usb device, I had to zero it out before I could make fdisk work properly again.).
4. Make partitions. Use a partitioning tool to put a msdos type partition map on the usb stick and partition it into two partitions as follows:
? Question: I'm not sure why these partitions can't be swapped, with the boot partition as the first partition. But for what it's worth, I tried that and could not get it to work.
5. Write the iso image to the 2nd partition. I struggled with whether to include a block size parameter or not here, (e.g. bs=2048), and in the end it appears it doesn't matter or has little effect. Also note this partition doesn't need formatting, as the ISO will effectively format it when copied directly to the partition.
6. Format the first partition. Note, he formats this with VFAT32 (i.e. long file names version of FAT32). I'm guessing this is to make it easy to read that partition on any machine (i.e. portability). [I plan to see if ext3 might also work and will update this later w/ that test].
7. Mount partition #1 to be able to install files into it.
8. Install grub into the first sector of the usb stick and into the root directory in partition #1.
9. Copy the kernel and ram disk files. (NOTE, this is revised from the article. The kernel now comes as an *.efi version, (but it's still just a kernel), and initrd (the ram disk with all of the packages) is now compressed with lz rather than gz). First we mount the image file (as a loop device) where we will get these two files from:
10. Create a file to hold the persistent file system. Adjust the size if you want. This is set as 1024x1mb=1gb. Note that inside the casper-rw file it's an ext3 file system. The name casper-rw is magic, so don't change it.
11. Create a simple grub configuration file. Be sure to give it a (possibly newer?) cfg not conf file name extension so grub can find it (ref). Use your favorite editor, or use:
12. Paste the following grub commands in.
13. sync (recommended) and cleanup (optional):
14. Backup your new USB drive.
15. Reboot and hit a key to boot Ubuntu USB stick.
16. Add your backup script to it. Here's my incremental script which deals with two laptops. FIRST CHECK IT CAREFULLY FOR YOUR SYSTEM AND ADJUST IT AS NEEDED. Name it mybackup and hard link myrestore to it (
ln mybackup myrestore
). Set execution permissions withchmod u+x my{backup,restore}
. Run it with./mybackup