Archiv für den Monat: Oktober 2024

Universal USB Boot Stick based on Ventoy

Running non ISO Linux from flash drive

While testing Ventoy and its option for customization I was wondering whether storing and starting the different images on the USB Stick is realy the most effective way.
Havinf different Images in place for fast installations is great. And the oportunity ofjust copying them to the flash drive without any further hazel is nearly perfect for daily purposes.

But on the other hand I there are three other use cases for Live Systems

  • Preinstalled Toolset for Work
  • Hacking
  • Images for System Rescue

For those use cases a more efficient way for booting and storing Data on the same flash drive makes more sense.

Mounting ISO and extract necessary files

Mounting an ISO is quiet easy. Either open it wiith graphical UI of the OS of your choice or (on *nix) mount ist as a loop device.

mkdir /tmp/loop
sudo mount -o loop /path/to/some.iso /tmp/loop

Now extract the vmlinuz, initrd.gz and the root filesystem. Based on Damm Small Linux 2024 this looks like this.

tree /Volumes/dsl-2024.rc7/
/Volumes/dsl-2024.rc7/
├── antiX
│   ├── initrd.gz
│   ├── initrd.gz.md5
│   ├── linuxfs
│   ├── linuxfs.info
│   ├── linuxfs.md5
│   ├── random-seed
│   ├── vmlinuz
│   ├── vmlinuz.md5
│   └── vmlinuz1.md5
├── boot
│   ├── isolinux
│   │   ├── README
│   │   ├── boot.cat
│   │   ├── chain.c32
│   │   ├── console.def.gfx
│   │   ├── console.def.orig
│   │   ├── console.men.orig
│   │   ├── gfx-cpio
│   │   ├── gfxboot.c32
│   │   ├── gfxsave.cfg
│   │   ├── isolinux.bin
│   │   ├── isolinux.cat
│   │   ├── isolinux.cfg
│   │   ├── ldlinux.c32
│   │   ├── libcom32.c32
│   │   ├── libmenu.c32
│   │   ├── libutil.c32
│   │   ├── menu.c32
│   │   ├── readme.msg
│   │   └── version
│   └── memtest
├── cdrom.ico
└── version

4 directories, 31 files

Checking the /boot/isolinux/isolinux.cfg gives us a brief overview abot the needs.

...
#    MENU LABEL antiX-23-runit_386-base (26 August 2023)
LABEL live
    MENU LABEL DSL 2024, hacked from antiX 23
    KERNEL /antiX/vmlinuz
    APPEND quiet splasht disable=lxF
    INITRD /antiX/initrd.gz
...

To avoid missing something we copy the complete directory antiX. Problem is, that the filesystem is withn the Image linuxfs, which is mounted in an overlay configuration stored in initrd.gz.

On the the flash drive we create a directory to store our non ISO based systems (in my case /linux). Within this directory we create as subdirectories for Damm Small Linux (dsl) in which we copy all the files from the antiX directory.

Changing the reference to the filesystem within initrd.gz

To update the reference we have to extract the data from the initrd.

mkdir /tmp/temp-initrd
cd /tmp/temp-initrd
gzip -dc /[path to flash drive]/linux/dsl/initrd.gz | cpio --extract --make-directories

Now we can edit the path to the init file in the root of our temporary directory and update the default path to linuxfs.

vi init

...
    DEFAULT_SQFILE=/antiX/linuxfs    (change to:/linux/dsl/linuxfs)
...

/linuxfs

After saving those change it is time to recreate the initrd.gz. The following pipe of commands finds every content in the current directory pipes it to cpio for creating a new initrd which pipes the output to gzip for compressing and storing it back to our target directory on the flash drive.

find . | cpio --create --format=newc | gzip > /[path to flash drive]/linux/dsl/initrd.gz

Creating a custom grub2 menu

Since we not have an image here the necessary item in grub2 will not automatically be created. Therefor we use the custom menu plugin from ventoy and define custom class for our entries.

If not existing we create a ventoy directory in the root of the flash drive. That’s the common directory for config and themes in Ventoy.

mkdir -p /[path to flash drive]/ventoy

Next we create a file named ventoy_grub.cfg to store our custom menu configuration.

vi /[path to flash drive]/ventoy/ventoy_grub.cfg

with the following content

menuentry "Damm Small Linux" --class=custom {
    echo "Loading Kernel ..."
    linux (hd0,msdos1)/linux/dsl/vmlinuz root=(hd0,msdos1)/linux/dsl/linuxfs
    echo "Loading Initrd ..."
    initrd (hd0,msdos1)/linux/dsl/initrd.gz
}
menuentry '<-- Return to previous menu [Esc]' --class=vtoyret VTOY_RET {
    echo 'Return ...'
}

After saving this we are ready for booting our customized Ventoy flash drive. After booting into the Ventoy grub2 menu we have to call our custom menu with [F6] and kann boot directly without beeing limited by the ISOs in boot time or errors caused by failed file sources.

To be done:

  • Creating a directory or a partition on flash drive to store data and system state

[TOC]