Saving a session back to the boot device (or even somewhere else)

An easy way to create a customized live system is to start from an existing one, make whatever changes you like, and then save the result back to the boot device. Of course, for this you need a writeable boot device, e.g. a USB-stick.

Overlay archives

In larch the uppermost layer in the union file-system is in tmpfs and can (optionally) be saved at shutdown to the boot medium. It is compressed using tar and lzop to the file 'overlay.tar.lzo'. When the system next boots this file will then be unpacked into the initially empty top layer.

This is handled primarily by the 'shutdown2' script, supplied in the 'larch-live' package. It is called from a hook function in 'etc/rc.shutdown'. If the medium is writeable and contains a file 'larch/save', the user is offered the possibility of saving this overlay archive, thus saving the current state.

When this archive grows too large it will reduce the amount of available memory, perhaps to an unacceptable extent. It will also lengthen boot and shutdown times. To counter this, it is possible to merge the overlay archive with the middle (squashfs) union layer, mods.sqf (which is normally not copied to memory), thus restoring the rapid load and save times for overlay.tar.lzo, and maximizing the available memory. I call this process 'overlay merging', and it is offered as a shutdown option. The script 'merge_overlay' (in the 'larch-live' package) provides this facility. It takes longer to execute than a normal session save, so it should probably not be used for every session saving operation, but just when the top overlay gets too big. Note that use of the overlay merging feature creates an additional layer in the union, 'filter.sqf'. This contains only 'whiteout' files to cover up overwritten data in the underlying 'system.sqf'. Unlike in previous larch versions the 'mods.sqf' archive contains no 'whiteouts'. It is hoped that this new structure will cure the problems experienced in these earlier versions.

Special places in /var

It was considered undesirable to include some things in the '/var' directory in the session saves, primarily because of the space they occupy. Firstly, the standard pacman package cache, '/var/cache/pacman/pkg' - if you do want to save your cache, you should either handle this manually or set up another location using 'CacheDir' in /etc/pacman.conf'. Also the log files (in '/var/log') and '/var/tmp' (temporary files, like '/tmp') are not saved.

Updating packages

It is possible to perform package addition and removal in the live system, but one should be aware that packages in the base system are not actually replaced, just (effectively) hidden, so that the space usage might become a consideration. Also the handling of kernel updates must be handled in a special way, because it is stored outside the root file-system, on the boot medium and needs a separate mechanism to save it at shutdown. It should be fairly transparent to the user, but under certain circumstances it might be necessary to bear this in mind.

At some point, after extensive updating, it might be desirable to completely rebuild the system, so that also 'system.sqf' is recreated. This will require quite a bit of space, but should otherwise pose no great problems.

Activating and deactivating the session-saving feature

As mentioned above, for this feature to be available, there must be a file with the name 'save' in the boot medium's 'larch' directory. This will be generated automatically if installing to a partition (i.e. if not building an iso) and if there is no 'nosave' file in the profile. The gui provides a button to create and delete this 'nosave' file, thus disabling or enabling session saving on the created medium.

Customizing the behaviour using scripts

Some aspects of the session saving can be customized by writing scripts to override the default behaviour. These scripts are (in general) kept on the boot medium, in the 'larch' directory. As these are shell scripts and their use requires some knowledge of the inner workings of the larch live system, it will almost certainly be necessary to read the existing larch scripts where the custom scripts are 'sourced' if you want to write your own scripts to change the behaviour of the live system in this respect. All these scripts are found in the 'larch-live' package.

  • session-save0

    Used in session-save/shutdown2 (in function 'checkse'). This script can be used to customize the creation of the new overlay archive, e.g. by specifying a new location. The default is 'overlay.tar.lzo' on the boot medium.

  • save-menu

    Used in session-save/shutdown2 (in function 'session-save'). This script can be used to further customize the creation of the new overlay archive, e.g. by providing an alternative session save menu. Note that if the session-save0 script specified an alternative device path for saving the overlay, this script will be sought in the 'larch' directory on that path.

  • boot-init

    In initramfs hook larch3. This script allows adjustment of the overlay handling during the boot process, e.g. getting them from another path. Note that the shell environment here is that of the initramfs and thus very limited.