How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

Each time you upgrade kernel on external, you can run this to update boot stanza in grub on the internal drive.

sudo update-grub

But you can also add a boot stanza to grub2's 40_custom that boots the partition, not the specific kernel. Ubuntu installs links in / (root) to boot the most recent install. Adjust example below if necessary to your drive & partition. Boot drive with grub is always hd0, but then other drives are in BIOS reported order which may vary.

Edit with:

gksudo gedit /etc/grub.d/40_custom

then, add:

menuentry "Install on sdb1" {
    set root=(hd1,1)
    linux /vmlinuz root=/dev/sdb1 ro quiet splash
    initrd /initrd.img
}

While above works, I find the drive may change when plugging in a flash drive or any other USB device. So I am converting to use labels.

menuentry "Cosmic 18.10 on sdb12 test" {
    search --set=root --label cosmic_b --hint hd2,gpt12
    configfile /boot/grub/grub.cfg 
}

I found out how to use the UUID of the drive, useful if you have multiple drives plugged in at boot time. Credits to oldfred for his note about /vmlinux and /initrd.img symlinks.

Add this to the file /etc/grub.d/40_custom, replacing UUID=XXXX-YYYY with the partition UUID (get UUID with command blkid)

menuentry "Boot from USB Drive" {
    set root=UUID=XXXX-YYYY
    linux /vmlinuz root=UUID=XXXX-YYYY ro quiet splash
    initrd /initrd.img
}

To boot from Ubuntu Live USB menu entry in /etc/grub.d/40_custom should look like that (Replace DRIVE_UUID with your partition's uuid):

menuentry "Boot from LIVE USB Drive" {
   search --set=root --fs-uuid DRIVE_UUID
   linux ($root)/casper/vmlinuz boot=casper quiet splash --
   initrd ($root)/casper/initrd.lz
}

To apply changes run:

sudo update-grub

Tags:

Usb

Boot

Grub2