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
  • 2
  • 9
  • 1
    Yes it is possible, persistent-path is of course only used with multiboot USB's. Each set of persistence files, casper-rw and home-rw, (if used) must be in their own folder. I wrote an answer about this several years ago, will try to find it for you. It is probably easier to divide a pendrive into partitions and do a Full install onto each. The persistence for each can then be greater than 8GB. – C.S.Cameron Oct 24 '19 at 05:37
  • Here is something from the Forums, I will try to find one I wrote for Ask. https://ubuntuforums.org/showthread.php?t=2343653 – C.S.Cameron Oct 24 '19 at 05:42
  • Her is something I wrote for Ask: https://askubuntu.com/questions/850319/multiboot-with-multiple-persistent-partitions (Which I think is a duplicate of the Forums question), My question was inquiring about multiple persistent partitions, (which never got answered), but I think I outline the method using persistent files OK, if not please let me know and I will write a more specific answer. – C.S.Cameron Oct 24 '19 at 05:54
  • Thanks but I've already tried this way; I mean placing casper-rw file(s) both directly in usb key root and in a dir ("folder" as 85319 shows) and referincing it in grub.cfg: nothing happened but ususal "persistence file not found". I've tried with 16.04 and 18.04 isos: is there something not allowing that in 16.04 and 18.04 as far as you know? – Silvia Oct 25 '19 at 14:48
  • a "last minute doubt": I forgot to tell you that I've built a small fat32 partition (500Mb) for efi and a ext2 partition for everything else; now I see somewhere (googling a bit) that it may depend on that ... this weekend I'll try using a couple of fat32 partitions instead of a fat32 and an ext2 – Silvia Oct 25 '19 at 15:04
  • I have never had luck using a FAT or NTFS partition for casper-rw. I don't think anyone else has either, ext2 is ok, it is non-journaling and may help USB life span. mkusb uses this but gparted shows it as ext4. I use ext4 myself. – C.S.Cameron Oct 26 '19 at 04:04
  • When I am making a custom USB, I start with a mkusb persistent install, (for BIOS / UEFI compatibility). Then delete the ISO9660 partition and use the space for expanding the casper-rw or usbdata partitions. In your case I would put the ISO's in /usbdata/isos/ and the casper-rw files in /usbdata/iso1/, /usbdata/iso2/, etc. I have had best luck if the ISO's and persistence folders are on the same FAT32 or NTFS partition. After it is working you can dissect and study the drive and start over from scratch. MultiBootUSB methods are also worth examining. – C.S.Cameron Oct 26 '19 at 04:21
  • Here is another example with lots of pictures: https://askubuntu.com/questions/1025656/how-do-i-boot-an-iso-file-from-my-drive-using-grub2-on-uefi-machines/1025863#1025863 Note that post 18.04 versions use vmlinuz not vmlinuz.efi and initrd not initrd.lz. Requirements for your version(s) can be confirmed by looking in the casper folder of your ISO. – C.S.Cameron Oct 26 '19 at 10:46
  • 1
    I may be getting carried away. casper-rw and home-rw files must go on a FAT32 partition, that is the reason for the 4GB limit. casper-rw and home-rw partitions must be ext not FAT. A Ubuntu install with the word persistent in the grub menuentry will use the first casper-rw that is finds while booting, starting with the HDD, then a casper-rw partition then a casper-rw file. A casper-rw file or partition only works with the version it was first used with. you do not need persistent-path unless you are using multiple persistence. – C.S.Cameron Oct 26 '19 at 11:03
  • @C.S.Cameron, mkusb uses ex4 in the partition for persistence. But journaling is turned off (to reduce wear). The simple mkusb-minp uses ext2. // +1 for the warning: 'A casper-rw file or partition only works with the version it was first used with'. – sudodus Oct 27 '19 at 10:06
  • @Silvia, When you are happy with your multiboot USB drive with persistence, please make a detailed description of how to make it. I think it will be very useful for many of us :-) – sudodus Oct 27 '19 at 10:13
  • @C.S.Cameron, Short answer: In mkusb I use the shellscript dus-persistent to create the persistent live system. It consists of serveral functions, and specifically the function grub_n_iso to create partitions and put things into them. (The name is inherited from an old system, where iso files were used.) – sudodus Oct 27 '19 at 11:12
  • @sudodus: please see https://askubuntu.com/questions/1184161/what-script-is-used-for-creating-usbboot-partition-and-installing-grub-in-mkusb – C.S.Cameron Oct 27 '19 at 11:56

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
  • 19,519