Persistent live systems
Most of the time it is enough with a live only USB pendrive and only a waste of effort to create a persistent live system. The cloning method of mkusb is very reliable and works with most linux distros. It needs hybrid iso files. But sometimes it is better to have a persistent live system, and beginning with version 10 mkusb can create such systems.
Simple persistence
I use the term 'Simple persistence' for a system, that uses a cloned read-only boot drive (CD, DVD, USB) and another drive with partitions for persistence.
Clone the iso file to one drive
It is very easy to create persistence this way, but maybe a bit inconvenient to use it. You have to enter the boot option persistent to an isolinux or a grub sub-menu every time it is used, because the cloned system from the iso file has a read-only ISO 9660 file system (and cannot be changed with conventional methods).
Clone the iso file to a boot drive with the Ubuntu Startup Disk Creator alias usb-creator-gtk version 0.3.2 or higher in Ubuntu 16.04 LTS (or newer), with mkusb (to make a live-only drive) in linux or with Win32 Disk Imager in Windows.
Modify the iso file
You can edit the iso file as a binary file, if you replace suitable blocks of 12 characters with 12 other characters, and it will still work.
sed 's/quiet splash/persistent /' ubuntu-file.iso > ubuntu-file-persistent.iso
Then you can clone this modified iso file with the Ubuntu Startup Disk Creator alias usb-creator-gtk version 0.3.2 or higher in Ubuntu 16.04 LTS (or newer), with mkusb (to make a 'live-only' drive) in linux or with Win32 Disk Imager in Windows.
This way you build the boot option persistent into the iso file and the cloned copy in the USB drive. In this case it will be a bit inconvenient to boot live-only . You have to remove the boot option persistent from an isolinux or a grub sub-menu.
mkusb-minp
The method to edit the iso file as a binary file can also be used with a casper-rw partition in the same USB drive with Ubuntu Eoan, version 19.10, and future versions. This new feature is used with the simple shellscript mkusb-minp.
See this link: ../minp.
Create partitions for persistence to another drive
Please notice that
persistence with casper-rw and/or home-rw partitions in another drive than the boot drive works with all current versions of Ubuntu and Ubuntu family flavours (Kubuntu, Lubuntu ... Xubuntu),
you should have only one casper-rw and/or home-rw partition in the computer when you boot. The boot process will select the first one of each kind it finds, and you can't control which one it is. If there are more than one, it can cause confusion and make the content in the casper-rw partition corrupted.
I suggest using gparted to create one or more partitions in the other drive. It is easy to use the MSDOS partition table (default if you create a new partition table in gparted. You can also use the GUID partition table, GPT, which is more advanced and works with huge drives (more than 2 TB).
casper-rw
Create a partition with an ext file system in a separate drive and give it the label casper-rw. This is the only partition, that is necessary for persistence.
home-rw
You can easily improve the drive by adding a persistent home partition with an ext file system and give it the label home-rw. The system can easily be damaged by errors in casper-rw, and you will need to remove all files (or re-format it). But you can often keep the settings and personal files in home-rw, so this partition can be very useful.
usb-data
You can also make a usb-data partition with the NTFS file system. The usb-data must be partition #1 for Windows to recognize it via USB. So start by making this partition, if you want it.
If you want this partition available also in MacOS, you can select the FAT32 file system. Some Windows version might not mount a FAT partition in GPT, unless you set the msftdata flag. (Otherwise Windows might think it is an EFI boot partition.)
Reduce wear
If in a USB pendrive you should also decrease the wear. Either use the simple ext2 file system or use the more advanced ext4 file system, but remove the journaling (from ext4).
sudo tune2fs -O ^has_journal /dev/sdxy
where x is the drive letter and y is the partition number of the partition, /dev/sdb2 and /dev/sdb3 in the following example.
How to check if there is persistence
You can always check by doing things with the system, for example create a file, reboot, and check if it survived. But you can also watch the output of the command df (or better dh -h).
Live-only mode
The partitions are seen in the following way from the system itself, when running from a 'lubuntu-16.04.1-desktop-amd64.iso' file in live-only mode.
lubuntu@lubuntu:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 384M 6.1M 378M 2% /run /dev/sda 890M 890M 0 100% /cdrom /dev/loop0 849M 849M 0 100% /rofs /cow 1.9G 18M 1.9G 1% / tmpfs 1.9G 112K 1.9G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 1.9G 4.0K 1.9G 1% /tmp tmpfs 384M 8.0K 384M 1% /run/user/999 /dev/sdb3 7.6G 19M 7.2G 1% /media/lubuntu/home-rw /dev/sdb2 9.8G 53M 9.2G 1% /media/lubuntu/casper-rw /dev/sdb1 12G 63M 12G 1% /media/lubuntu/usb-data
Persistent mode
It is very easy to create persistence this way, but maybe a bit inconvenient to use it, unless you modify the iso file, so that it contains the boot option persistent. |
The partitions are seen in the following way from the system itself, when running from a 'lubuntu-16.04.1-desktop-amd64.iso' file in persistent live mode.
lubuntu@lubuntu:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 384M 6.1M 378M 2% /run /dev/sda 855M 855M 0 100% /cdrom /dev/loop0 809M 809M 0 100% /rofs /cow 9.8G 48M 9.2G 1% / /dev/sdb3 7.6G 19M 7.2G 1% /home tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup tmpfs 1.9G 4.0K 1.9G 1% /tmp tmpfs 384M 4.0K 384M 1% /run/user/999 /dev/sdb2 9.8G 48M 9.2G 1% /media/lubuntu/casper-rw /dev/sdb1 12G 63M 12G 1% /media/lubuntu/usb-data lubuntu@lubuntu:~$
Notice these two lines:
/cow 9.8G 48M 9.2G 1% / /dev/sdb3 7.6G 19M 7.2G 1% /home
Comments
There are both advantages and disadvantages to have the persistence separate from the boot drive.
It is possible to make partitions for persistence in an internal drive as well as in an external drive. You can have several drives with persistence for different purposes or simply backup copies.
Screendumps
There are screenshots to help you create and use Simple persistence. See the link /screendumps
Persistent live system in one single drive
An alternative is to create a persistent live drive (typically a USB drive) with mkusb. Then there will be an entry in the grub boot menu to select persistence, and the whole persistent live system will reside in one drive.
The mkusb/persistent system has a built in backup system for the data stored in 'casper-rw'. Please use it at regular intervals, and particularly before and after doing major things with the system.
https://help.ubuntu.com/community/mkusb/persistent