Let /dev/sdb
be the USB device.
Create 1 VFAT partition at /dev/sdb1
and mount at /mnt/usb0
.
Install GRUB on the device:
grub-install --boot-directory=/mnt/usb0/boot /dev/sdb
Now, all files needed by GRUB (e.g modules for filesystems) are under /mnt/usb0/boot/grub
.
No menus are present and we only have a terminal interface. We can add a menu by adding a grub.cfg
file under /mnt/usb0/boot/grub
.
We can use the menu confifuration generated by our OS (using configuration from /etc/grub.d
ans placed at /boot/grub/grub.cfg
) as a starting point.
Be carefull because hard disk devices will not have the same numbering when boot device is the USB!
A minimal example of a grub.cfg
:
set timeout=15
set default=0
menuentry "Debian 9 (4.9.0) @somewhere" {
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd1,msdos5)'
echo 'Loading Linux 4.9.0-11-amd64 ...'
linux /vmlinuz-4.9.0-11-amd64 root=UUID=91702617-9014-4e87-a852-0aa8f2b672ea ro quiet cgroup_enable=memory swapaccount=1
echo 'Loading initial ramdisk ...'
initrd /initrd.img-4.9.0-11-amd64
}
Some good articles on this: