Saturday, April 2, 2016

Setting up a Flash Drive to UEFI Boot Linux (from an ISO)

Update 27/1/2017: A slightly simpler variant for flashing an ISO when targeting legacy BIOS PCs

The following process may be a bit cumbersome (I'm sure it could be cleaned up to use a minimal set of tools and/or have the interactive parts automated), but it works to allow a current Linux distro (I was using Kubuntu) to boot from a USB flash drive on a Dell laptop with a recent (Skylake) CPU via UEFI with SecureBoot turned on.

  1. Plug in the flash drive and find the device number (using lsblk or fdisk -l). In the following example I'm using /dev/sdc as that was the device allocated to my flash drive. If you get the device wrong, you could trash your system using the steps below!
  2. Delete everything on the flash drive to freshen it up, and create a new msdos partition:

    sudo parted /dev/sdc mklabel msdos

  3. Use fdisk to interactively add a new partition. The commands look something like this, where most of the values are defaults:

    $ sudo fdisk /dev/sdc

    Command (m for help): n
    Partition type:
    p primary (0 primary, 0 extended, 4 free)
    e extended
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-15633407, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-15633407, default 15633407):
    Using default value 15633407

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.
    $

  4. Create a FAT32 partition on the drive:

    sudo mkfs.vfat /dev/sdc1

  5. Create a mount point for the drive:

    sudo mkdir /mnt/flash
    sudo mount -t vfat /dev/sdc1 /mnt/flash -o rw,umask=000

  6. Extract the ISO to the flash drive (this will take a while):

    7z x kubuntu-16.04-beta2-desktop-amd64.iso -o/mnt/flash

  7. Set the boot flag on the flash drive:

    sudo parted /dev/sdc set 1 boot on

  8. Unmount the flash drive so it's ready to be removed and used:

    sudo umount /mnt/flash

Further reading on the various steps used above:

No comments:

Post a Comment