A FOB STORY: some notes on bootable flash drives

Standalone grub2 - legacy and UEFI

Simply copying a live CD or ISO contents to a flash intended for UEFI booting – or copying a Windows install DVD or ISO contents to a properly-prepared (by DISKPART) flash drive for legacy booting – takes care of bootloader installation.  For non-Windows legacy booting or in cases where a full Linux distro isn’t desired (or that may be booted as an ISO – more on that later…) a stand-alone bootloader install may be required.  Legacy bootloader installation can also be used to make a flash drive both UEFI and legacy bootable.

Grub2 has commands that can be used to install stand-alone for UEFI installations.  Intended for HDD installs, I believe.  For a UEFI flash drive, probably the easiest way to “install” grub2 is to just “borrow” it from a Ubuntu CD or ISO.  Just copy the /boot and /EFI directories to the flash drive.  That’s all it takes.  /boot/grub/grub.cfg will probably need to be hand edited for the specific application.  More detail and examples to follow.

Installing grub2 for legacy booting is a bit more work.  The good news is that it can be done from a Ubuntu installation running on HDD, from a live CD or flash drive that’s up and running, or even from a Ubuntu virtual machine running in Windows.

A particularly slick trick is to copy the Ubuntu ISO contents to a prepped flash drive, live boot it in UEFI mode, then use it to do a legacy grub2 install to itself.  The result is a flash drive that can boot in both UEFI and legacy mode.  The two modes will  share the grub.cfg menu nicely, although they may not both be able to boot every entry depending on mode.

NOTE: for legacy only or UEFI and legacy bootability, the partition must be set active.

Better yet, the grub.cfg file is not part of the secure boot chain.  That means that editing it does not break secure boot.  It’s possible to have the same flash drive boot Ubuntu in UEFI + secure boot mode and still boot other distros and utilities in UEFI non-secure and legacy modes.  Sweet!

Thanks to Pendrive Linux for these grub2 legacy stand-alone install instructions:  Install GRUB2 on USB from Ubuntu Linux

From a running Ubuntu 14.04 (for example) as superuser:

# grub-install --force --no-floppy --boot-directory=<mount point>/boot  <device>

Mount point and device will vary depending on the system’s particulars and whether Ubuntu is a bare-metal install, running in a VM, or a live boot from CD or flash drive – and whether it’s booted directly (as from a live CD or CD copied to flash) or a loop-mounted ISO.

The mount command can be used to determine both the device and mount point.  Here’s a snip of what it looks like with a flash drive mounted in a virtual machine:

# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
...
/dev/sdb1 on /media/wdw/307E-B176 type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2)

The device is sdb and the mount point is /media/wdw/307E-B176 so the install command would be

# grub-install --force --no-floppy --boot-directory=/media/wdw/307E-B176/boot /dev/sdb

A loop-mounted ISO on a flash drive booted live looks like this (in this case the flash device target is the same device that’s actually been booted):

# mount
/cow on / type overlayfs (rw)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
...
/dev/sdc1 on /isodevice type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
...

In this example the device is sdc and the mount point is /isodevice.   To install grub2:

# grub-install --force --no-floppy --boot-directory=/isodevice/boot /dev/sdc

If the running flash drive had been created by copying the contents of a live CD rather than loop mounting and booting an ISO the mount point would typically be /cdrom.  Of course, if the running Ubuntu is actually booted from a CD, /cdrom won’t be the flash drive.

It may first be necessary to remount the target read/write:

# mount -o remount -rw  /isodevice (or /cdrom or /media/<something>...)

There may also be a GUI right-click option (properties/permissions or a simple remount r/w selection) to remount the flash drive read/write – on the desktop or the file browser.  It may or may not require super user permissions.

That should do it.  The only thing left is create or edit the boot menu – either hand building it if this is a pure stand-alone installation, or editing the one included with the Ubuntu CD or ISO (or “borrowed” from the Ubuntu ISO).  Some examples later in this article.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

Crafty Question: * Time limit is exhausted. Please reload CAPTCHA.