Custom Live USB

From Organic Design wiki
Revision as of 22:10, 31 January 2022 by Saul (talk | contribs) (Ventoy: Typo)

Custom ISO

It can be useful to customize an image to preinstall packages or pre-configure settings so that when the image gets live booted those packages are already installed and usable.

Ubuntu

CUBIC (Custom UBuntu Iso Creator) is a easy tool for customizing Ubuntu based distribution images such as Mint. The process gives you a virtual shell and you can install packages and configure the OS as you normally would, after doing this CUBIC packages it back up into an ISO. There appears to be many advanced options but for preinstalling applications and pre-saving data it is straight forward.

Debian

live-build is the way to build debian images (can do Ubuntu too!) however it is a bit more complicated than CUBIC in the fact that you do not start off with a base image you build your own and some things may be missing that you may be expecting to be there like a desktop environment. (You can still add one.)


NOTE: Save yourself a lot of hassle by doing the process on Debian, if you are not running Debian - do it off a live image. I've encountered many errors trying on Mint but Debian gave next to none.


This tutorial is nice an simple for getting started with.

Basic Instructions

Install with:

sudo apt-get install live-build

Setup and configure with:

mkdir debian;
cd debian;
lb config;
# https://manpages.debian.org/stretch/live-build/lb_config.1.en.html

You should clean the old build configuration before building:

sudo lb clean

Then you can build with:

sudo lb build

Customization

Adding Files/Folders

Files and folders placed in config/includes.chroot will be copied into the root directory on install.

Packages

You can add packages to the image by creating the file config/package-lists/my.list.chroot with the list of packages separated by newlines.

Custom Packages

You install .deb packages by placing them into the config/packages.chroot directory.

Hooks

The config/hooks directory is for placing your scripts you would like to run at certain times in the build process. For example to customize something in the live boot you would need to create a folder called live in this directory, then place a shell script that performs some actions in there.

Debugging

Check the chroot/debootstrap/debootstrap.log file for more specific logs.

Cannot check Release signature
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.gpg

This can easily be fixed by installing the keyring:

sudo apt-get install debian-archive-keyring
Failed getting release file
E: Failed getting release file http://ftp.debian.org/debian/dists/wheezy/Release

This default release mirror was returning a 404 so, just change it:

lb config -m http://ftp.nz.debian.org/debian/
sudo lb clean
sudo lb build

The release Wheezy is outdated, it needed changing to bullseye.

#lb config -d bullseye --parent-distribution bullseye
lb config -d stable --parent-distribution stable
sudo lb clean
sudo lb build
Does not have a Release file

There seems to be some repo issues:


Disabling security fixes it for now.

lb config --security false
sudo lb clean
sudo lb build
Sub-process /usr/bin/dpkg returned an error code
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 1 expected program not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin
E: Sub-process /usr/bin/dpkg returned an error code (2)
Wrong url format
[2022-01-31 14:54:31] lb_chroot_linux-image 
--2022-01-31 14:54:31--  http://ftp.debian.org/debian//dists/stable/Contents-amd64.gz
Resolving ftp.debian.org (ftp.debian.org)... 151.101.166.132, 2a04:4e42:27::644
Connecting to ftp.debian.org (ftp.debian.org)|151.101.166.132|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2022-01-31 14:54:31 ERROR 404: Not Found.

The URL was missing /main in it so it had to be manually edited:

sudo nano /usr/lib/live/build/lb_chroot_linux-image

Search for the content:

${LB_PARENT_MIRROR_CHROOT}/dists/${LB_PARENT_DISTRIBUTION}/Contents-${LB_ARCHITECTURES}.gz

And replace with:

${LB_PARENT_MIRROR_CHROOT}/dists/${LB_PARENT_DISTRIBUTION}/main/Contents-${LB_ARCHITECTURES}.gz

And likewise search for:

${LB_MIRROR_CHROOT}/dists/${LB_DISTRIBUTION}/Contents-${LB_ARCHITECTURES}.gz

And replace with:

${LB_MIRROR_CHROOT}/dists/${LB_DISTRIBUTION}/main/Contents-${LB_ARCHITECTURES}.gz

Then build without cleaning again:

sudo lb build

See also:

Multi ISO USB

Ventoy is a great tool if you would like to have multiple bootable ISOs on a single USB drive. Ventoy is fairly easy to use since it has a few scripts to handle things for you.

Ventoy Usage

  1. Download Ventoy from its releases.
  2. Run the the appropriate (for your architecture) Ventoy GUI program.
  3. Select your USB drive and flash it with the Ventoy software.
  4. Unplug and replug your USB drive.
  5. Copy any ISOs you like onto the drive (probably labeled "Ventoy").
  6. Boot into your usb and select the ISO you would like to boot from the menu.

Persistent Storage

Live images will not normally persist storage which can really limit their use-case, however there seems to be some options for solving this.

Partitioning/File

It seems possible for Ubuntu (and Debian?) distributions to persist storage through partitions or a file. It looks like if you partition your USB that has the ISO formatted on it with partitions labeled casper-rw and home-rw Ubuntu will detect these and use them as persistent storage. Alternatively it appears you can create a loopback file in the root directory that will be used as well, this file must be named casper-rw.

Ventoy

Ventoy has a plugin that allows you to use a persistent storage file for storing your data and this storage can be configured to be used across the images that support it's format.

Plug your Ventoy USB in and open a terminal and cd into your USB directory.


Run:

# Note: this will create the persistent file in whatever directory you run it so ensure you are in the mounted USB.
sudo /PATH/TO/VENTOY/CreatePersistentImg.sh -s <SIZE_IN_MB> # For Ubuntu based distros.
sudo /PATH/TO/VENTOY/CreatePersistentImg.sh -s <SIZE_IN_MB> -l persistence -c persistence.conf -t ext4 -o debian-persistence.dat # For Debian
#


Note: You can do the next part manually if the GUI scares you.


After that finishes change to your Ventoy installation directory and run:

# Note this script won't work if you are not in the right directory.
./VentoyPlugson.sh /YOUR/USB/MOUNT # e.g. /dev/sdb

Open your browser and navigate to http://127.0.0.1:24681 and configure the plugin by:

  1. Click Persistence Plugin on the left.
  2. Click Add down the bottom right.
  3. Fill the File Path with the path of your ISO inside the Ventoy USB.
  4. Fill the Dat Path with the path of the generated persistence file inside the Ventoy USB.


Once that is done reboot and choose the ISO from the menu then choose the with persistence option.

Manually Configure Ventoy

Instead of using the VentoyPlugson UI you can manually configure Ventoy to use the persistent storage file.

  1. Create the folder called ventoy in the root of your Ventoy USB if it doesn't already exist.
  2. Edit or create a file in there called ventoy.json.
  3. Modify the file to include the following JSON:
{
    "persistence":[
        {
            "image": "/YOUR_IMAGE_NAME.iso",
            "backend":[
                "/persistence.dat"
            ]
        }
    ]
}

See also