Boot a USB stick from Grub2

Putting this here mainly so I’ll remember the next time I need it, but maybe it’ll be useful for someone else.  I wanted to boot a Ubuntu USB live install drive from within Grub2, because my Surface Pro 1 won’t boot from USB once a grub bootloader has been installed.

The Surface Pro boot process freezes if you have a USB stick plugged in at all, unless you first boot into windows, go to “Advanced boot options” and tell the Surface Pro to boot from your USB stick.  It won’t actually boot from the stick, because the grub bootloader is installed, not the MS bootloader.  But at least the boot process doesn’t freeze, and you can get into the grub menu.

Good news though: booting a USB stick from usb works, and it’s pretty easy to do.  With your USB stick plugged in, boot into the Grub2 menu, and hit ‘c’ to get to the grub command line.

Grub2 uses a different partition naming system than linux does.  To figure out which partition name refers to your LiveUSB’s main partition, use the ‘ls’ command.  With no arguments, this command will list all available partitions.  ‘ls’ results show the Grub2 partition names – results for my livecd look like this:

(hd0) (hd0,apple1) (hd0,apple2) (hd0,msdos2) 

Now, find out which partition holds the initrd, efi and vmlinuz files.  Again, use the ‘ls’ command, but this time pass a partition name in quotes as an argument. 

ls '(hd0)'
ls '(hd0)/'
ls '(hd0,msdos2)/'

Without the trailing slash, ls will show you info about the partition – size, label, etc.  With the trailing slash, it will list the files in the partition.  If you specify a directory path, it will list the files in that directory.  My LiveCD’s main partition showed as ‘(hd0)’.

Now, find the efi boot file – mine was here:

ls '(hd0)/EFI/BOOT/'BOOTx64.EFI    grubx64.efi

Now you’re ready to boot.  But you need to add some modules to allow Grub2 to boot your USB drive.

insmod part_gpt
insmod fat
insmod chain

Now set the root, specify the chainloader (I used grubx64.efi, but BOOTx64.EFI may also work), and boot:

set root='(hd0)/'
chainloader /EFI/BOOT/grubx64.efi

…and that should boot you into your LiveUSB stick.

Leave a comment

Your email address will not be published. Required fields are marked *