Difference between revisions of "Custom Live USB"

From Organic Design wiki
(Create page with notes about custom live images and persistence.)
 
m (Ventoy: Add note about image resizing.)
 
(18 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
=== Ubuntu ===
 
=== Ubuntu ===
[https://launchpad.net/cubic 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 reinstalling applications and pre-saving data it is straight forward.
+
[https://launchpad.net/cubic 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 ===
 
=== Debian ===
Looks like [https://live-team.pages.debian.net/live-manual/html/live-manual/about-manual.en.html live-build] is an option for customizing Debian ISOs but this method looks more difficult that CUBIC.
+
[https://live-team.pages.debian.net/live-manual/html/live-manual/index.en.html 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.
 +
 
 +
 
 +
[https://www.bustawin.com/create-a-custom-live-debian-9-the-pro-way/ This tutorial] is nice an simple for getting started with.
 +
 
 +
==== Basic Instructions ====
 +
Install with:
 +
<source lang="bash">
 +
sudo apt-get install live-build
 +
</source>
 +
 
 +
Setup and configure with:
 +
<source lang="bash">
 +
mkdir debian;
 +
cd debian;
 +
lb config;
 +
# https://manpages.debian.org/stretch/live-build/lb_config.1.en.html
 +
</source>
 +
 
 +
You should clean the old build configuration before building:
 +
<source lang="bash">
 +
sudo lb clean
 +
</source>
 +
 
 +
Then you can build with:
 +
<source lang="bash">
 +
sudo lb build
 +
</source>
 +
 
 +
==== 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 =====
 +
<source>
 +
W: Cannot check Release signature; keyring file not available /usr/share/keyrings/debian-archive-keyring.gpg
 +
</source>
 +
 
 +
This can easily be fixed by installing the keyring:
 +
<source lang="bash">
 +
sudo apt-get install debian-archive-keyring
 +
</source>
 +
 
 +
===== Failed getting release file =====
 +
<source>
 +
E: Failed getting release file http://ftp.debian.org/debian/dists/wheezy/Release
 +
</source>
 +
 
 +
This default release mirror was returning a 404 so, just change it:
 +
<source lang="bash">
 +
lb config -m http://ftp.nz.debian.org/debian/
 +
sudo lb clean
 +
sudo lb build
 +
</source>
 +
 
 +
The release Wheezy is outdated, it needed changing to bullseye.
 +
<source lang="bash">
 +
#lb config -d bullseye --parent-distribution bullseye
 +
lb config -d stable --parent-distribution stable
 +
sudo lb clean
 +
sudo lb build
 +
</source>
 +
 
 +
=====  Does not have a Release file =====
 +
There seems to be some repo issues:
 +
* https://lists.debian.org/debian-live/2020/07/msg00019.html
 +
 
 +
 
 +
Disabling security fixes it for now.
 +
<source lang="bash">
 +
lb config --security false
 +
sudo lb clean
 +
sudo lb build
 +
</source>
 +
 
 +
===== Sub-process /usr/bin/dpkg returned an error code =====
 +
<source>
 +
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)
 +
</source>
 +
 
 +
===== Wrong url format =====
 +
<source>
 +
[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.
 +
</source>
 +
 
 +
The URL was missing '''/main''' in it so it had to be manually edited:
 +
 
 +
<source lang="bash">
 +
sudo nano /usr/lib/live/build/lb_chroot_linux-image
 +
</source>
 +
 
 +
Search for the content:
 +
<source lang="shell">
 +
${LB_PARENT_MIRROR_CHROOT}/dists/${LB_PARENT_DISTRIBUTION}/Contents-${LB_ARCHITECTURES}.gz
 +
</source>
 +
 
 +
And replace with:
 +
<source lang="shell">
 +
${LB_PARENT_MIRROR_CHROOT}/dists/${LB_PARENT_DISTRIBUTION}/main/Contents-${LB_ARCHITECTURES}.gz
 +
</source>
 +
 
 +
And likewise search for:
 +
<source lang="shell">
 +
${LB_MIRROR_CHROOT}/dists/${LB_DISTRIBUTION}/Contents-${LB_ARCHITECTURES}.gz
 +
</source>
 +
 
 +
And replace with:
 +
<source lang="shell">
 +
${LB_MIRROR_CHROOT}/dists/${LB_DISTRIBUTION}/main/Contents-${LB_ARCHITECTURES}.gz
 +
</source>
 +
 
 +
Then build without cleaning again:
 +
<source lang="bash">
 +
sudo lb build
 +
</source>
 +
 
 +
See also:
 +
* https://lists.ubuntu.com/archives/ubuntu-devel-discuss/2014-October/015092.html
  
 
== Multi ISO USB ==
 
== Multi ISO USB ==
Line 28: Line 168:
  
 
=== Ventoy ===
 
=== 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.
+
Ventoy has a [https://ventoy.net/en/plugin_persistence.html 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:
 +
<source lang="bash">
 +
# 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
 +
#
 +
</source>
  
# Plug your Ventoy USB in.
+
 
# Open a terminal and cd into your usb directory.
+
Note: You can do the [[Custom_Live_USB#Manually_Configure_Ventoy|next part manually]] if the GUI scares you.
# Run '''sudo /PATH/TO/VENTOY/CreatePersistentImg.sh -s <SIZE_IN_MB>''' (Note this will create the persistent file in whatever directory you run it so ensure you are in the mounted USB.)
+
 
# Change to your Ventoy installation directory (you need to be in this dir) and run '''./VentoyPlugson.sh /YOUR/USB/MOUNT # e.g. /dev/sdb'''
+
 
# Open your browser and navigate to http://127.0.0.1:24681
+
After that finishes change to your Ventoy installation directory and run:
 +
<source lang="bash">
 +
# Note this script won't work if you are not in the right directory.
 +
./VentoyPlugson.sh /YOUR/USB/MOUNT # e.g. /dev/sdb
 +
</source>
 +
 
 +
Open your browser and navigate to http://127.0.0.1:24681 and configure the plugin by:
 
# Click '''Persistence Plugin''' on the left.
 
# Click '''Persistence Plugin''' on the left.
 
# Click '''Add''' down the bottom right.
 
# Click '''Add''' down the bottom right.
 
# Fill the '''File Path''' with the path of your ISO inside the Ventoy USB.
 
# Fill the '''File Path''' with the path of your ISO inside the Ventoy USB.
 
# Fill the '''Dat Path''' with the path of the generated persistence file inside the Ventoy USB.
 
# Fill the '''Dat Path''' with the path of the generated persistence file inside the Ventoy USB.
# Once that is done reboot and boot the ISO with the persistence option.
 
  
  
 +
Once that is done reboot and choose the ISO from the menu then choose  the '''with persistence''' option.
  
==== Manually Configure Ventoy ===
+
==== Manually Configure Ventoy ====
 
Instead of using the VentoyPlugson UI you can manually configure Ventoy to use the persistent storage file.
 
Instead of using the VentoyPlugson UI you can manually configure Ventoy to use the persistent storage file.
  
Line 62: Line 219:
 
}
 
}
 
</source>
 
</source>
 +
 +
 +
==== Debugging ====
 +
==== Resizing Image - Bad Substitution ====
 +
I got a Bad Substitution error when resizing the image, it is because the default shell is not bash - to fix edit the '''ExtendPersistentImg.sh''' file and ensure it is using bash instead of sh on the first line.
 +
 +
== See also ==
 +
*[[Create a LiveCD]] ''- legacy method from years ago''
 +
[[Category:Linux]]

Latest revision as of 03:09, 1 February 2022

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"
            ]
        }
    ]
}


Debugging

Resizing Image - Bad Substitution

I got a Bad Substitution error when resizing the image, it is because the default shell is not bash - to fix edit the ExtendPersistentImg.sh file and ensure it is using bash instead of sh on the first line.

See also