13
December
2024
How does Persistence work in antiX and MX Linux
11:57

How does Persistence work in antiX and MX Linux

13 December 2024 11:57

Persistence is saving the state of the OS and home directory, settings when working in Live CD mode.

What is Persistence / Persistence / Persistence in antiX Linux. What are its advantages?

Persistence can be translated into Russian as Constancy or Fortitude. Indeed, when the antiX or MX Linux OS is shut down, these operating systems, when choosing the “persistence” mode, are able to save the last state to a storage device - USB or hard drive, which does not depend on external power. After some time, you can turn on the PC, boot from the flash drive and, when selecting Persistence, restore the system at the time of shutdown - with all additionally installed applications, settings and user files, and even “garbage” - temporary files and browser cookies. Also, unlike classic OSs, where a backup is made using timeshift or iSCSI or rsync, it takes quite a long time, because... All files are copied, only changes compared to the original image are saved here, and in a single file, which significantly reduces recording time. In the absence of updates and additional programs, the size of Persistence files is about 200 MB, and in compressed form - 30 MB. The main thing is that you don’t need to copy many files - only two: rootfs and homefs.

There are two types of Constancy / Persistence / Persistence:
*static*(data is immediately written to the media - slow, but there are no RAM requirements)
dynamic**(data is first written to RAM - a quick way, but requires execution persist_save to save changes. The convenience of the dynamic method with the choice of whether to save or not (semi-automatic or manual) - changes can not be saved to the media if they are not needed. For example, if the ping or traceroute or lshw command is executed and the results are read from the screen and saving the OS state is not required.

Operating principle of Constancy / Persistence / Persistence

Persistence uses an OverlayFS layer on top of the file system, which is an object-based abstraction through which files are accessed.
OverlayFS - implemented in Linux since kernel version 3.18, but has not been widely used until now. OverlayFS is designed to combine several different base mount points from different physical media into one, resulting in a single directory structure containing base files and subdirectories from all sources. Conventional applications overlap a read/write partition with a read-only partition, such as with LiveCDs and IoT devices with limited flash write cycles.

overlays

When the persistence_root type is enabled, both partitions are loaded into RAM homefs and rootfs. If the computer's power is lost, all changes will disappear. This is written about here:
https://download.tuxfamily.org/antix/docs-antiX-23/FAQ/persistence.html#under-toc.

What are the disadvantages of the Persistence mode in antiX Linux / MX Linux?

Root persistence mode allows you to save changes to the system and the user's personal settings and preferences. The mode has two significant limitations. These limitations are due to the fact that while the system is running, changes are stored in RAM and will be lost unless they are specifically copied back to the rootfs file.
1) If your computer suddenly shuts down or crashes before the changes are copied back, your changes will be lost.
2) Another limitation is that the amount of new information you can store is limited by the amount of free RAM.

Dynamic root save saves file system changes in RAM (like booting from a regular LiveCD/USB). Program persist-save must be run to copy these changes to the rootfs file on the media so that they can be remembered across reboots. Use persist-config to set the saving mode - either Automatic, Semi-automatic or Manual. In automatic mode the program persist-save automatically starts on shutdown/reboot.

On a USB 2.0 flash drive, the reading time for 200 MB persistence files is about 15-20 seconds, for 2 GB it is about 1.5 minutes. You should try to create files of the minimum required size - for example, 100 MB. The rootfs file, which is loaded into RAM, grows when OS updates are installed, but does not exceed 2 GB. For the Persistence function to work, you need 4-6 GB of RAM.

Options for the location of persistence files on storage media

Option 1: the rootfs and homefs files are located next to linuxfs in the same directory on the same physical media (by default). The size of rootfs and homefs can be increased, but it cannot exceed the size of the first partition on the media. Booting from a flash drive occurs the same and successfully from any PC, with a different number of disks, because... both the boot partition and persistence are actually on the same volume. The capacity of a flash drive is 4 GB (more is possible).

The default location of files on the disk is on the first partition of the boot disk, in the same place where linuxfs is located:
USB disk partitioning

The Persistence files are called rootfs and homefs. The latter is created optionally using the "Configure Persistence" utility with a purple icon.
antix-usb2
Rootfs stores changes to programs and settings in relation to the reference image of the linuxfs system. homefs stores user interface settings and files in the home folder.

Option 2: the linuxfs file is located on the main flash drive, in the first section. The rootfs and homefs files are on the same flash drive in the second partition. When starting, specify the parameter pdev=/dev/sde2. You need to specify a real letter, for example /sdb2 or /sdc2 because The name of the disks varies from PC to PC. This is disadvantage number 1. Disadvantage No. 2 - the flash drive is quite slow, there is no speed when saving and restoring states. On the other hand, when used with the same PC, the letter X in pdev=/dev/sdx2 will always be the same.

After burning a USB disk using special programs, the first partition is obtained in FAT32 format and can be compressed. The remaining space can be given to a second partition with any file system for storing files.
antix-mydisk2

A second partition to store persistence was created after compressing the disk space using gparted. Then I saved the files to it using the key, see above.
antix-usb3

Option 3: the linuxfs file is located on the main flash drive, in the first section. The rootfs and homefs files are on the hard drive /dev/sda1 in the folder /antiX. When starting the OS, add to the kernel parameter pdev=/dev/sda1. Advantage - very high speed in read and write modes when calling persist-save and practically unlimited size of rootfs or homefs. But you need to transfer these files, for example, from the same USB flash drive before starting the OS for the first time. This can be done by booting from a LiveCD and copying the rootfs or homefs files to your hard drive. The hard drive itself must be in good condition. The file system /dev/sda1 on which the roofts file will be saved can be any - EXT3, EXT4, FAT32 or NTFS.

antix_persistence_ext_disk

Option 4: all three files are on two different “flash drives” - on the first (boot disk) linuxfs, on the second (data) rootfs and homefs. This option is relevant if the PC hard drive is faulty or missing, and the capacity of the USB drive does not allow storing all three files as in option No. 1.

Note: the first time you create rootfs, you will be prompted to create passwords for the root and demo users.

Kernel settings and parameters when booting antiX / MX Linux

In the menu when starting the system you need press F5, select persist_all(for dynamic storage in rootfs RAM, but without home) or persist_root(to dynamically save the contents of the rootfs and homefs partitions in RAM).

All parameters and keys for launching the antiX/MX Linux initial window (including Persistence Location "pdev=") are described here:
https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_Parameters

In the absence of parameters, persistence files are used with the main one. bootable USB flash drive.

If you have forgotten the demo user password, simply remove rootfs and homefs, the system startup with Persistence will begin as if from a “clean slate”, and a new password will be requested.

antix_linux_core_startup_parameter

Notes:

  • The rootfs and homefs files can be zipped and emailed to yourself.

Live USB start menu options are saved when you select the far right item F8 "write"!


Sources:
https://antixlinux.com/the-most-extensive-live-usb-on-the-planet/
https://mxlinux.org/blog/do-cool-stuff-with-live-usbs/



Related publications