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

9,647

Solution 1

You're almost there. Removable media like usb will boot from a boot able EFI partition (and that's one bootable EFI partition PER DEVICE, not total), using the bootloacer /EFI/Boot/bootx64.efi (for x64 architectures). Simply copy your /EFI/ubuntu/grubx64.efi to /EFI/Boot/bootx64.efi, and have a copy of grub.cfg in /EFI/ubuntu/grub.cfg and it should boot. Of course, the grub.cfg must be set up to boot the hard disk like you want. Simply copying the grub.cfg off the hard disk's installation will work, but then you will need to recopy every time you update kernels, so you can make the /EFI/ubuntu/grub.cfg a few lines which import the maintained /boot/grub/grub.cfg (like 13.04 does I think). * For Secure boot, use shim.efi for the /EFI/Boot/bootx64.efi and have a copy of the SIGNED grubx64.efi in /EFI/Boot also. grub.cfg is in the same place, /EFI/ubuntu. Your live media uses this mechanism to boot, so if it works, this method will work.

Solution 2

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.

Share:
9,647

Related videos on Youtube

Paul H
Author by

Paul H

Updated on September 18, 2022

Comments

  • Paul H
    Paul H over 1 year

    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!

  • Paul H
    Paul H over 10 years
    I used win32imgwriter to write the rEFInd .img file to my pen drive and then attempted to boot. No success. The UEFI firmware boot menu prefixes my usb-pen device name with 'UEFI' but when I select it, Windows 7 loads. Perhaps the UEFI firmware doesn't like the presence of 2 efi-system partitions? The fact that rEFInd didn't boot suggests the UEFI firmware, when presented with 2 or more gpt-system partitions, is defaulting to the one on the SSD and ignoring anything else, especially since my Ubuntu live session WILL boot in UEFI mode, but the usb-drive it is stored on has an mbr layout.
  • Paul H
    Paul H over 10 years
    Whilst your solution appears simple, that would involve modifying (even in a small way) my gpt-system partition, which, since the PC in question is not mine, I am not allowed do.
  • Paul H
    Paul H over 10 years
    I mounted the gpt-system partition on the SSD as read-only, copied the contents of EFI/ubuntu/ to my pen drive, then copied EFI/ubuntu/grubx64.efi from the SSD system partition to EFI/Boot/bootx64.efi on my pen drive. First I tried to boot the pen drive using the grub.cfg from the /EFI/ubuntu/grub.cfg located on the SSD system partition, then from the grub.cfg located in /boot/grub/grub.cfg on the SSD's ubuntu partition. Just to be clear, does grub.cfg have to be in /EFI/Boot or /EFI/ubuntu ?
  • ubfan1
    ubfan1 over 10 years
    grub.cfg in /EFI/ubuntu is what worked for me.
  • Rod Smith
    Rod Smith over 10 years
    It's at least as likely that the Windows utility didn't write the image correctly. Try a Linux session and use dd, as in dd if=refind-flashdrive-0.7.2.img of=/dev/sdc (or whatever the USB flash device is). Multiple ESPs are explicitly permitted by the EFI spec. Although Windows has problems with multiple ESPs, any such problem in the EFI itself (and especially one that prevents use of an ESP on a removable disk) would constitute a very serious bug.
  • dschinn1001
    dschinn1001 over 10 years
    @RodSmith - my answer above is wrong then ? should I delete it ? I was thinking that machine can only decide one way to boot ? only there where boot-flag is set, machine knows then, which partition to mount next ?! - I have not said that there is /boot-flag - was writing about boot-flag. I know of earlier installation at my machine, that OS (Linux too ! ) cannot decide between two boot-flags, which one to follow. You would need knoppix then to set one single boot-flag.
  • Rod Smith
    Rod Smith over 10 years
    Somebody referred to a "/boot flag," but it's been edited away -- I think it was in the original question. As to the rest, multiple ESPs are definitely legal. (The term "boot flag" in reference to GPT is specific to libparted-based tools and so is not general. If you use gdisk or another OS to partition, "boot flag" will be meaningless.) An EFI-based computer decides on the boot order based on NVRAM variables set via the efibootmgr utility (in Linux; or various other tools in other OSes). The EFI/BOOT/bootx64.efi file is a ballback loader in case this fails.