I wanted to boot a complete system from a pendrive. Not just a live install medium but a full-blown, persistent one.

How hard is it to install it?

It turns out it's not that hard, but it needs some rather unusual tools.

The first tutorials I found (1 and 2) both approach it in a rather straightforward way:

  • Have 2 USB pendrives
  • Burn the installer to one of them
  • Boot the installer
  • Disable the ESP partition
  • Install to the other pendrive
  • Enable the ESP partition

Why is there an ESP partition trick here? Turns out installing on a pendrive would mess up the boot on the harddrive. But if the 'esp' flag is turned off then it will be untouched. Unbootable as well, so it's important to turn it on after.

Then I found this article that used a different process that I liked a lot more. It uses a qemu virtual machine that has a hard disk from a file, boots the install ISO, proceeds with the installation, and finally, burns the file to the pendrive. It does a lot less magic which I like.

Prepare the hard disk image (13.5 GB in my case):

dd if=/dev/zero of=kubuntu.img bs=1M count=13500

Install the edk2_ovmf package. It took me 2 tries to figure out this is needed, but it's logical. By default qemu boots up in legacy BIOS mode, which means the installer would proceed in the MBR-style boot partition, which in turn won't work in UEFI laptops. By using this firmware the boot will use UEFI so the installer will install UEFI-compatible system.

The variables will change, so make a copy:

cp /usr/share/edk2/x64/OVMF_VARS.4m.fd .

Finally, boot up the machine:

qemu-system-x86_64 -enable-kvm -cpu host -smp cores=4 -cdrom kubuntu-24.04.2-desktop-amd64.iso -drive format=raw,file=kubuntu.img -m 4096 -vga cirrus -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd -drive if=pflash,format=raw,file=OVMF_VARS.4m.fd

Probably there are other arguments to make the installer faster, but the above was good enough for me.

Finally, burn the resulting image to the pendrive (after triple-checking that /dev/sda is the right target):

sudo dd if=kubuntu.img of=/dev/sda bs=1M status=progress

And that's it, I could restart and boot my new install from the pendrive.

Originally published at advancedweb.hu

Advanced Web MachinerySource