Wednesday, December 15, 2021

GRUB2

I've always loved GRUB.  It's not easy to use, but man it works well, usually the setup is automatic, but maybe a little scary if you have to do something manually.  But then it's setup and it works for years.  

If/when GRUB fails it doesn't wreck your data, and can usually be recovered with a boot disk and a few commands.

Seriously love GRUB, and GRUB2 is dramatically better!

Yesterday I got tired of putting 2-4GiB ISO images on to 32GiB SD cards.  My friends were starting to wonder if I needed an intervention:

 So I started looking at tools to put multiple ISO's on to one large bootable SD card, and simply choose which one you wanted to boot at boot time.  I found the excellent website of LinuxBabe.com who suggested MultiBootUSB  and MultiSystem - but both of those appear to be abandoned projects from some time ago.

Someone on Discord suggested PLOP. Truly hilarious name.  But that also looked really sketch.  Then I found another LinuxBabe article;  apparently GRUB2 can boot directly to ISO's!!

So I made these partitions on a USB stick: 

Number  Start   End     Size    File system  Name      Flags
 1      1049kB  2097kB  1049kB               bios
 2      2097kB  68.2MB  66.1MB  fat32        efi_boot  boot, esp
 3      68.2MB  128GB   128GB   ext2         iso_cube

The first partition is a BIOS protective partition and has no file system, some old computers or misbehaving software will overwright the beginning little bit of a disk.  1 MiB is excessive, but it also helps ensure partitions are 4k block aligned, and I don't care about 1 Mib.

Mounted new filesystems:

mkdir /mnt/efi_boot
mkdir /mnt/iso_cube
mount /dev/{usbstick}2 /mnt/efi_boot
mount /dev/{usbstick}3 /mnt/iso_cube
mkdir /dev/efi_boot/boot
 

Installed GRUB2 onto the USB stick (this was on an Ubuntu system, YMMV):

grub-install --efi-directory=/mnt/efi_boot --boot-directory=/mnt/efi_boot/boot --removable

Booted to the USB stick, and then proceeded to boot directly to an ISO file.  The 'ls' commands are me looking for files, GRUB names disks in a way that is easiest for GRUB - we just have to deal with it:

ls
ls (hd0,gpt2)/
ls (hd1,gpt3)/
set isofile="/ubuntu-20.04.3-desktop-amd64.iso"
loopback loop (hd1,gpt3)$isofile
ls (loop)
ls (loop)/
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet noeject noprompt splash
lnitrd (loop)/casper/initrd
boot

Victory!

So LinuxBabe showed how to add ISO entries to the GRUB menu so you don't have to memorize and type a bunch of commands every time.  After I add a bunch more ISO's and test them out I expect I'll probably do that.  For now I just made a file on the usb stick with the commands I typed.  The grub command line has 'cat' so I can read my instructions, I don't boot from USB very often, so I might just leave it.  Having to use the GRUB command line every once and a while will go a long way to helping me learn it. 

No comments:

Post a Comment