Ubuntu – Install grub2 to usb-drive in order to boot to hdd-installed Ubuntu 13.04 x64 in UEFI mode

dual-bootgrub2installationuefiusb-drive

I've been trying to find a way to install grub2 to a usb drive, in such a way that I can boot a PC in UEFI mode into Ubuntu, without modifying the UEFI firmware settings in any way or replacing the pre-installed Windows 7 x64 bootloader with grub.
Here's the current gpt partition layout of the internal SSD drive as given by gparted, when run from an Ubuntu 13.04 x64 live-dvd session:

/dev/sda1 100mb fat32 /boot (efi system partition)

/dev/sda2 128mb --- /msfres (Windows 7 reserved partition)

/dev/sda3 100gb ntfs (Windows 7 system partition)

/dev/sda4 10gb ext4 (Ubuntu root '/' partition)

So far, I've tried booting my live-dvd in UEFI mode, creating a root partition for Ubuntu (as seen above), then telling the installer to put grub on a 512mb usb pen drive (/dev/sdi) that I had previously formatted in gparted as follows: 1) create a gpt partition layout; 2) create a single primary partition; 3) format the partition as fat32; 4) set the partition flag as '/boot'.

I instructed the Ubuntu installer to install grub to /dev/sdi1 (the partition I created above — since the preceding 1mb was unused space). However, when I rebooted the PC, after the completion of the Ubuntu installer, with the usb pen plugged-in, the firmware boot menu detected the pen as an UEFI device but then proceeded to boot Windows 7 — no Ubuntu or grub menu.

I've tried Google'ing for solutions, and whilst there are many sites that give details on how to dual boot Windows and Linux on UEFI systems, they all assume that you will be able to modify the UEFI firmware settings or replace the Windows 7 bootloader (neither option is available to me, as I don't own the PC).

Therefore, could anyone give me a detailed, step-by-step method of installing grub2 to a usb pen so that I can boot into the Ubuntu partition in UEFI mode, without changing any of the system firmware settings or modifying/replacing the existing Windows 7 bootloader?

The system board is an ASUS Z87-K (bios rev 0412), the SSD is an 120gb OCZ-Vertex3 (firmware rev 2.15)

An update: It turns out that my UEFI firmware DOES have secure boot enabled (because Windows 7 (and other OSes in 'live mode') booted fine, I assumed it was turned off). My apologies if I've been leading people up the wrong path! Since I don't own this PC, I can't turn secure boot off, so I will have to abandon the attempt at an Ubuntu installation for now. Although, according to the Canonical documentation, Ubuntu 12.04.2 and later should be able to boot on a PC with secure boot enabled? Since I can't disable secure boot to narrow-down the problem which is preventing me from successfully booting Ubuntu, I'll leave this question open, but any future installations I attempt will be done on my own hardware so I have the freedom to experiment in greater depth.

Thanks, once again, to all who responded!

Best Answer

You cannot set two /boot partitions with boot-flag ! There is only one boot-flag necessary for grub2 in /boot partition - so simply deactivate boot-flag in your partition /dev/sda1

After this activate boot-flag in /boot partition of /dev/sdi - sure ? this is correct ? You have a /boot partition in /dev/sdi ? So there you need to activate boot-flag ( simply with gparted ).

As you say ... grub2 is already installed in /dev/sdi ? If not now follows (necessary because you modified boot-flags) :

sudo grub-install /dev/sdi

sudo update-grub2

Before this all your machine was booting into Windows 7 of /dev/sda3 via /dev/sda1 - but now boot-flag is deactivated and set to /boot partition of /dev/sdi - and your machine should now boot to installation of your usb-drive.

Only in case that in UEFI-mode your machine is not able to boot into usb-drive - then you should disable UEFI-mode in BIOS-settings and enable there EFI-mode instead.