2

I've built an "handmade" multi-system usb key, briefly installing grub (both efi and legacy), then copying on it three heavily customized iso (Ubuntu 16.04 and 18.04, the latter in two "flavours") and finally modifying grub.cfg so that the user can choose between systems and UI locales.

I'd like adding persistence at least on one of them (by adding "persistent" and "persistent-path=..." in grub.cfg menuentry) but until now it has been impossible to have it working: every boot I get something like "persistence file not found" while I've tried to put the casper-rw both directly in usb key's root and in a directory.

So I'd like to know if and how is possible to add persistence on a iso-based bootable usb key.

Thanks,

Sil

[edit] I forgot to state that I don't want to use things like unetbooting, multiboot, mkusb and so on since they ad too much crap to the key. If it isn't possible to have persistence in the way I described above, I prefer having no persistence at all.

Silvia
  • 538

1 Answers1

3

MultiBoot USB Stick from Scratch

(Modification of How do I boot an ISO file from my drive using grub2 on UEFI machines?)

GParted Partitions

GParted

  • Create a gpt partition table on a USB stick.

  • Create partitions as shown above, select unformatted for partition 2.

  • Create a casper-rw file:

    sudo dd if=/dev/zero of=casper-rw bs=1M count=512

    sudo mkfs.ext3 -L casper-rw -F casper-rw

(where count=512 is the persistence size in megabytes, with a max of 4GB).

Persistence partition

Persistence Partition

  • Create an uniquely name folder for each OS, (that requires persistence), on the USB-PRST partition.

  • Add a casper-rw file, (and optional home-rw file), to each persistence folder. A home-rw file can be made by renaming a casper-rw file. A home-rw file is like a separate home partition on a Full install, it can be reused after version upgrades.

Data Partition

Data Partition

  • Create a folder for the ISO files on the NTFS USB-DATA partition.

  • Add some ISO's to the isos folder.

Boot Folder

Boot Partition

  • Open the latest Pre-19.10 ISO file and copy the boot and the EFI folders to the USB-BOOT partition. (Note that Ubuntu 19.10 and later use grub 2.04 which prevents booting of ISO files).

  • Install grub

    sudo mount /dev/sdx3 /mnt

    sudo grub-install --boot-directory=/mnt/boot /dev/sdx

Edit grub.cfg to loopmount the ISO files. Include: persistent persistent-path=/<persistent-folder-name>/ if you want multiple persistence.

if loadfont /boot/grub/font.pf2 ; then
    set gfxmode=auto
    insmod efi_gop
    insmod efi_uga
    insmod gfxterm
    terminal_output gfxterm
fi

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray

set timeout=5

menuentry "ubuntu-19.10-desktop-amd64.iso" {
    set root=(hd0,1)
    set isofile="/isos/ubuntu-19.10-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile persistent persistent-path=/persist-1/ splash --
        initrd (loop)/casper/initrd
}
menuentry "lubuntu-16.04.3-desktop-amd64.iso" {
    set root=(hd0,1)
    set isofile="/isos/lubuntu-16.04.3-desktop-amd64.iso"
        loopback loop $isofile
        linux (loop)/casper/vmlinuz.efi boot=casper iso-scan/filename=$isofile persistent persistent-path=/persist-2/ splash --
        initrd (loop)/casper/initrd.lz
}

Grub.cfg example

sudo parted -ls  /dev/sdx

sudo parted -ls /dev/sdx

sudo lsblk -f  /dev/sdx

sudo lsblk -f /dev/sdx

If the above is used as a USB stick it can be used to boot ISO's stored on a Windows only computer. Grub is not required on the internal drive.

C.S.Cameron
  • 20,530
  • 12
  • 78
  • 125