How to boot Ubuntu from EFI/UEFI?

Solution 1:

This is a modified post by nerasezi in the Ubuntu Forum

The main source for the UEFI was the Ubuntu UEFI guide

The following are the steps he did:

  1. Use a live CD which matches the UEFI architecture. Mostly x86-64. Boot up the live cd (xubuntu or lubuntu. Those are lightweight desktop but it should work with Ubuntu and kubuntu as well).

    Be sure your live system is booting in UEFI mode. You may check it on the UEFI setup, probably under Boot option or similar. In my case it just put the "UEFI" prefix before the device name.

  2. Once the live system is running set through the terminal a root password by typing
    sudo passwd root

    Then log out from the default live cd user and log in as root in gui mode. Plug in the hard drive. I use a USB3 portable HDD but in most cases the hard drive is a SATA internal drive. Anyway, be sure you've BACKED UP ALL YOUR DATA, cause the process is going to wipe off everything on the drive. Launch Gparted (a gui tool is much easier than the text one) and select the drive you're willing to install the system into. (Be sure to select the right one!) Point to the top menu and select Device>Create Partition Table... A warning message pops out. Click on Advanced and select "gpt". Say OK A new GPT disk layout had been created. Now you need to create partitions on it. It's very important that you create as the first and primary partition, a FAT32 volume and you need to assign the label EFI to it. Once the partition is created, right click on it and select "manage flags". Check the "boot" flag and say OK. Move on to the creation of the / partition (you may want to separate /home and /boot. Do it as you usually do. In my case I've just created the / partition), and a swap area. Always prefer primary partitions cause with GPT the 4 primary partition limitation has been removed. Close Gparted.

  3. Install the system into the hard drive "/" partition and remember to point here the bootloader (GRUB 1.99) to install to. If you've created a separete "/boot" partition, you have to choose that one for the bootloader installation.

  4. Here comes the part from the UEFIBooting guide:

    Building GRUB2 (U)EFI

    Download the latest grub2 source code ZIP file. ftp://ftp.gnu.org/gnu/grub/

    Building grub2 requires the following programs to be installed (build dependencies):

    bison autoconf automake flex autogen python (2.x series) (for autogen.sh if building from bzr repo) texinfo help2man gettext (NLS support) device-mapper freetype2 (libs)

    sudo apt-get install bison libopts25 libselinux1-dev autogen m4 autoconf help2man libopts25-dev flex libfont-freetype-perl automake autotools-dev freetype2-demos texinfo efibootmgr

    efibootmgr was added to the software you need to install because you will need it later on.

    For 64-bit (U)EFI:

export EFI_ARCH=x86_64 ./configure --with-platform=efi --target=${EFI_ARCH} --program-prefix="" make

In case you have a 32-bit architecture, check the online documentation at the link I have provided at the top.

Install GRUB2 in (U)EFI systems

Determine your EFI SYSTEM PARTITION. (it should be /dev/sda1 or /dev/sdb1 if is set on the 2nd hd)

Then mount the partition at /mnt/EFISYS (or at any mountpoint you wish). The following code assumes /dev/sda1 to be EFISYS partition.

sudo mkdir -p /mnt/EFISYS

sudo modprobe dm-mod

sudo mount -t vfat -o rw,users /dev/sda1 /mnt/EFISYS

sudo mkdir -p /mnt/EFISYS/efi/grub

Then, build an EFI application for GRUB and copy it and the other modules:

Enter the "grub2 compiled source/grub-core" directory - Default : /usr/lib/grub/{EFI_ARCH}

grub-mkimage -O ${EFI_ARCH}-efi -d . -o grub.efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot

sudo cp grub.efi *.mod *.lst /mnt/EFISYS/efi/grub

Note : The -p "" option is important for creating a portable grub.efi app. Now create a grub.cfg in /mnt/EFISYS/efi/grub :

sudo touch /mnt/EFISYS/efi/grub/grub.cfg

Make the firmware launch GRUB2 (U)EFI as default

For non-Mac UEFI systems, efibootmgr is used to modify the UEFI Firmware Boot Manager. This requires the kernel to be booted in UEFI mode and that the kernel processor architecture should match the firmware architecture (and 'noefi' is NOT used) for 'efivars' kernel module to be loaded and efibootmgr to access the boot manager variables. Initially the user is required to manually launch "efi/grub/grub.efi" from the firmware console itself if grub2-efi was installed in BIOS mode. Then efibootmgr should be run to create the boot entry.

sudo modprobe efivars

Enter the "grub2 compiled source/grub-core" directory

grub-probe --target=device /boot/efi/efi/grub/grub.efi

Assuming the output the grub-probe to be /dev/sda1

sudo efibootmgr --create --gpt --disk /dev/sda --part 1 --write-signature --label "GRUB2" --loader "\\EFI\\grub\\grub.efi"

In the above command, /boot/efi/efi/grub/grub/efi can be split up as /boot/efi and /efi/grub/grub.efi, which translates to (/dev/sda) -> partition 1 -> \EFI\grub\grub.efi .

  1. Open Synaptic and remove all grub packages and install just the grub-efi packages (amd64 for me) and all the necessary dependencies. Once the installation is over, run sudo update-grub in the terminal. You should edit "grub.cfg" from /boot/grub and check that the disk UUID matches your disk and partitions, the voice "insmod part_" and "set root='(hd0," have "gpt" textline. If everything is ok, copy "grub.cfg" to the "efi/grub" on the EFI System Partition. If something i mentioned before, doesn't match, just edit grub.cfg and manually change them values. Then copy the file to the "efi/grub" directory on the Efi System Partition (should still be mounted under /mnt).

    Then when I rebooted the system, a new entry on the Boot tab under the UEFI setup has appeared, named GRUB2 and i set it as the default boot option.

Solution 2:

To help confirm if your machine is U/EFI capable simply run dmesg | grep EFI from Terminal in live desktop session.
To help confirm if your installed Ubuntu has booted using U/EFI see what /sys/firmware/efi returns.
A time saving solution is to make sure Ubuntu has actually booted in UEFI mode at install time. Referring to the newer Ubuntu UEFI Guide section 2.4 illustrates this brilliantly

Identifying if the computer boots the CD in EFI mode

Warning: even if your PC boots the CD in EFI mode, it might boot the HDD in Legacy mode (and the contrary).

When booting on a 64-bit Ubuntu disk:

  • If the BIOS is set up to boot the CD in EFI mode, then you will see the screen below:

UEFI mode

  • If the BIOS is NOT set up to boot the CD in EFI mode, or if the disk is not 64-bit, then you will see the screen below:

BIOS mode

Be sure to use the same guide referred to in order to ensure hard drive is booted using UEFI also. This may be as simple as setting SATA to AHCI but depends on your firmware being used.

Once getting to grub screen it is possible to drop to comand line by pressing "c" and try lsefisystab which should give table of EFI entries with GUIDs which is another handy method to identify if UEFI is being used BEFORE installing.

It is possible to use dmesg | grep EFI to identify if your machine is UEFI capable. On one of my machines that is not U/EFI capable but doing this gives me UEFI capable?
which may be misleading as doing the same command on a UEFI capable machine would return many more lines (possibly 50+) when booted using EFI I found this simple tip at rodsbooks(the link is for rEFInd which is an alternative to using Grub2). rodsbooks webpages are regularly updated and are a very reliable source of information. The author of which is an UEFI Professor to say the least if not a genius!

Referring to rodsbooks on this page shows that Ubuntu 11.10 makes an ESP with FAT16 filesystem where as some UEFI firmwares want an ESP with FAT32 filesystem. You will find the full explanation if you do Ctrl + F and search for Fedora on the linked page in this paragraph.(Click Next once in "Find bar" to go straight to the information that is being referred to).
Considering the fact UEFI specification required for Secure Boot is => UEFI 2.2 and Windows 8 pre-installed machines will use UEFI 2.3.1.
All of which confirms Ubuntu 11.10 is not secure boot capable so secure boot is not the problem.

It is possible after using UEFI to install Windows- which can only use GPT when using UEFI; that Ubuntu installs using BIOS/legacy settings due to installer deficiencies. ie Ubuntu can install to GPT using both BIOS or UEFI which then leads to the need of switching firmware settings in order to boot each OS.

To identify if Windows is using UEFI is to use disk management to confirm GPT is being used. It is possible to convert a Windows Bios install to UEFI using this guide Converting Windows BIOS installation to UEFI

One easy solution is to run Boot-repair-disk (downloading the cd .iso will mean slightly quicker booting than compared to using full Ubuntu.iso and then installing boot-repair. Check advanced options before running recommended fix bearing in mind which firmware settings you have used to boot boot-repair. Boot-Repair will install grub-efi and fix firmware hardcoding problems in order for system to use UEFI and boot Ubuntu as well as any other existing installs using UEFI.

An important part (which may be vendor specific) is how to bootup in EFI mode (ie, the same Ubuntu 14.04 LTS CD can detect two different mode and render the different text vs non-text bootup screen as shown above).

http://forum.hardware.fr/hfr/OrdinateursPortables/portable/resolu-installation-probleme-sujet_67937_1.htm

or this:

http://rog.asus.com/220572013/rampage-motherboards/rampage-iv-uefi-boot-installation-guide-on-windows-7-or-8/

Notice that at the BIOS setup for boot priorities, there are generally two different option for DVD: Px or UEFI (or some other words). One of this is for UEFI and another is for legacy MBR-based bootup.

Solution 3:

Solved the EFI problem on my ACER notebook 5560G, it turned out that renaming the EFI directory and EFI file on the Wubi USB disk worked (thanks immerohnegott).

It forced a normal GRUB install on 2 premade partitions with GParted on a USB stick. The partitons were:

  • /boot (100 mb)
  • / (70 GB)

Reboot into Windows 7 and install the free version of EasyBCD. Add a new entry , Linux -- >> Grub 2 and it will search all partitions for the GRUB bootloader.

In this way the Windows "System Reserved" partition and the PQSERVICE Acer Hidden Partition are not touched.

Solution 4:

You can make USB bootable drives that work with the EFI system, I'm not as seasoned as some of y'all so I figured out a way that is easy and works :)

In a machine that has the EFI bios, insert a CD/DVD with Parted Magic (I had it on a HIREN Boot CD that I made into a CD instead of a USB) Boot from that CD/DVD.

Once you are in Parted Magic, insert an empty USB jump drive with at least 2GB memory. Open up the Unetbooten utility that is included in Parted Magic. Run the program and choose whatever distribution you are trying to load on the jump drive. Follow directions and wait for it to complete.

That USB drive should boot on any EFI system now. At least it worked for me :oP