Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active February 9, 2020 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmalex07/07a65288e260a3997dbce2405fb7fef3 to your computer and use it in GitHub Desktop.
Save drmalex07/07a65288e260a3997dbce2405fb7fef3 to your computer and use it in GitHub Desktop.
Create bootable USB with Grub2. #grub #grub2 #boot #usb

README - Create bootable USB with GRUB2

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment