Which commands to convert a Ubuntu BIOS install to EFI/UEFI without boot-repair on single boot hardware?

61,773

Solution 1

Start a Ubuntu Linux (14.04) Live CD in UEFI mode. In case of a USB boot device, disable "Fast Boot" in UEFI.

Open a terminal window (Ctrl+Alt+T)

To verify that you are actually running in UEFI mode, use this bash command:

$ [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

The resulting output should be:

UEFI

In case it says BIOS, reboot into your firmware and correct the boot device preference.

To do the BIOS to EFI/UEFI conversion enter these commands:

$ sudo mount /dev/sda1 /mnt
$ sudo mkdir -p /mnt/boot/efi
$ sudo mount /dev/sda3 /mnt/boot/efi
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /proc /mnt/proc
$ sudo mount --bind /sys /mnt/sys
$ sudo mount --bind /run /mnt/run
$ modprobe efivars
$ sudo chroot /mnt
# apt-get install grub-efi-amd64

Apt-get networking failure?

# rm /etc/resolv.conf
# ln -s ../run/systemd/resolve/stub-resolv.conf resolv.conf
# apt-get install grub-efi-amd64

No apt-get failure

The following extra packages will be installed:
  efibootmgr grub-efi-amd64-bin
The following packages will be removed:
  grub-gfxpayload-lists grub-pc
...
After this operation, 2,399 kB of additional disk space will be used.

# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy --debug

Despite ending in error message:

Fatal: Couldn't open either sysfs or procfs directories for accessing EFI variables.
Try 'modprobe efivars' as root.

the next reboot already shows "ubuntu" in the firmware its boot options menu, and boots to the console as before, except for now booting in efi mode:

$ dmesg | grep EFI
efi: EFI v2.31 by American Megatrends
fb0: EFI VGA frame buffer device
EFI Variables Facility v0.08 2004-May-17
fb: switching to inteldrmfb from EFI VGA

In case something goes wrong, https://superuser.com/questions/376470/how-to-reinstall-grub2-efi might help.

Solution 2

Small correction:

sudo apt-get install -y grub-efi-amd64
sudo mount /dev/sda1 /mnt
sudo mkdir -p /mnt/boot/efi
sudo mount /dev/sda3 /mnt/boot/efi
for d in dev sys proc usr run; do sudo mount -B /$d /mnt/$d; done
sudo modprobe efivars
sudo chroot /mnt
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy --debug

Done.

Solution 3

This worked for me too with one small alteration. Even though the network was working I couldn't get the apt-get install grub-efi-amd64 to find any of the package servers.

I got around this by booting up in BIOS mode one final time and installing grub-efi-amd64.

I could then follow the procedures here with exception of omitting apt-get install grub-efi-amd64.

Share:
61,773

Related videos on Youtube

Pro Backup
Author by

Pro Backup

Updated on September 18, 2022

Comments

  • Pro Backup
    Pro Backup over 1 year

    Accidental BIOS mode install

    I have Intel 64-bit hardware with UEFI setup utility. Ubuntu 14.04.1 LTS was installed as the only operating system on the only drive attached. Accidentally Ubuntu was installed in BIOS/CSM/legacy mode.

    Convert to UEFI

    While later on learning about UEFI, the goal is to change this existing Ubuntu installation to (quicker) boot via EFI/UEFI. I do still want to have some kind of - 2 seconds displayed - boot menu that allows me to enter the UEFI setup utility. Therefore I think I do need use Grub (can't use an EFI boot stub) and GOP support requires Grub version 1.99 or higher. I have already re-partitioned the drive using a Live CD and inserted a 200 MiB EFI partition in the beginning of the drive and marked that fat16 formatted partition as type id 0xEF.

    Before:

    # fdisk -l /dev/sda
    ...
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048   108478463    54238208   83  Linux
    /dev/sda2       108480510   125044735     8282113    5  Extended
    /dev/sda5       108480512   125044735     8282112   82  Linux swap / Solaris
    

    After:

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *      411648   108478463    54033408   83  Linux
    /dev/sda2       108480510   125044735     8282113    5  Extended
    /dev/sda3            2048      411647      204800   ef  EFI (FAT-12/16/32)
    /dev/sda5       108480512   125044735     8282112   82  Linux swap / Solaris
    
    Partition table entries are not in disk order
    

    No boot-repair please

    The Ubuntu community wiki suggests to use boot-repair to Converting Ubuntu into EFI mode. I don't want to use a GUI, or install any extra packages, and I don't want any data being accidentally sent to pastebin.com and because I do want to know what will be changed exactly, I don't want to use Boot-repair.

    Under the hood

    Trying to figure out what boot-repair actually does, I found this snippet:

    Boot-Repair will convert a BIOS install to UEFI by uninstalling grub-pc, and installing grub-efi, if gpt partitioned.

    source: http://ubuntuforums.org/showthread.php?t=2147295&p=12657352#post12657352

    UEFI mode install comparison

    A clean Ubuntu 14.04.1 installation in UEFI mode creates a 512 MiB Fat32 formatted EFI partition. That partition contains one directory /EFI/ubuntu, containing 4 files: grub.cfg, grubx64.efi, MokManager.efi and shimx64.efi. The grub.cfg contains:

    search.fs_uuid 7d843e47-3917-4114-8725-55dfa1fbe002 root hd0,gpt2
    set prefix=($root)'/boot/grub'
    configfile $prefix/grub.cfg
    

    Search.fs_uuid points to the UUID of the Linux installation partition, in this comparison UEFI installation Linux is installed partition /dev/sda2 (versus sda1 in BIOS mode installation).

    No potential Asrock firmware issues found

    Having CSM still disabled in firmware and using the clean UEFI mode Ubuntu installation. Resizing the 512 MiB EFI partition to 200 MiB using a Live CD and gparted results in that its formatting changes from FAT32 to FAT16. The Asrock firmware P1.50 (incorrectly called BIOS by AMI in boot message "BIOS date") is still able to boot into UEFI mode Ubuntu: UEFI+FAT16 = ok.
    Converting the partition table from GPT to MBR (msdos) using the same Live CD terminal command gdisk and its commands r g p w also results in a UEFI bootable Ubuntu on an MBR partitioned drive: UEFI+MBR = ok.

    Question

    Does this mean that the only commands I do need to execute - from the legacy Ubuntu install and in this order - are:

    # apt-get install grub-efi
    # apt-get remove grub-pc
    

    ? Or is more needed to be done?

    • Rinzwind
      Rinzwind almost 10 years
      I would still use boot repair. You assume you need to install packages ... I believe you are wrong. See: askubuntu.com/questions/226061/…
    • Pro Backup
      Pro Backup almost 10 years
      @Rinzwind I can't use boot-repair because there is no GUI in the current Ubuntu installation (console only) and ubuntu-14.04.1-desktop-amd64.iso doesn't boot when set as first USB UEFI boot device in Asrock's H81 Pro BTC P1.50 UEFI setup utility.
    • oldfred
      oldfred almost 10 years
      Boot-Repair is not gui, but bash with one of the add ins that makes it more gui like. With the newer version of Ubuntu package names have changed a bit, now it is grub-efi-amd64 or grub-efi-amd64-signed, I think. It may be because they want to release a 32 bit UEFI boot loader that name changed. Chroot version, note you also have install grub & create grub.cfg. askubuntu.com/questions/53578/…
    • Pro Backup
      Pro Backup almost 10 years
      @oldfred Boot-Repair is depending on gui: executing apt-get install boot-repair on this Ubuntu server install, results in 245MB of GTK like dependencies boot-repair wants to install. And executing boot-repair command aftwerwards fails. The update of newer grub-efi naming was really helpful.
    • oldfred
      oldfred almost 10 years
      If an Asrock, make sure you have no drive or DVD drive connected to the Asmedia ports. They do not have drivers. Better to only have gpt partitioned drive if booting in UEFI. rodsbooks.com/gdisk/hybrid.html
  • Anish
    Anish about 8 years
    This helped me upgrade my hard drive and convert to GPT/UEFI/SecureBoot without reinstalling. Thank you. One note: I needed the grub-efi-amd64-signed package to avoid having to mess with disabling SecureBoot in my UEFI BIOS.
  • Abhishek Dujari
    Abhishek Dujari over 5 years
    It is now 2018 and this problem with EFI i still persistent. even efi boot is installed but I end up in grub cli. I give up on Ubuntu.
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' almost 5 years
    Can you explain why you are suggesting these changes from the OP’s answer? … … … … Please do not respond in comments; edit your answer to make it clearer and more complete.
  • Joey Adams
    Joey Adams over 4 years
    This worked for me under Ubuntu 19.10. I booted the live USB with EFI, and I added a 200MB partition of type FAT32 for EFI to the end of my disk.
  • Gediz GÜRSU
    Gediz GÜRSU about 4 years
    Flawless. I created a qemu kvm bios and installed minimal.iso (ubu18) in expert mode creating sda1 512 Mb FAT32 and sda2 4.5 GB ext4. I reserved sda1 as "Reserved Boot Area" and installed a minimal ubuntu without installing any bootloader. Then I booted same qemu qcow2 image with live 18.04 desktop cd image with OMVF efi bios firmware. Applied what you said no error. Then I have got grub> screen then I grub> set root=(hd0,gtp2) grub> linux /boot/vmlinuz-4.14.xxxx-generic root=/dev/sda2 grub> initrd /boot/initrd.img-4.14.xxxx-generic grub> boot Tab works arrow works its great
  • Andrew Fielden
    Andrew Fielden about 4 years
    I got this problem. It turned out that /etc/resolv.conf was symlinked to the wrong file. Delete it, and do ln -s ../run/systemd/resolve/stub-resolv.conf resolv.conf. Then rerun your apt-get command.
  • Andrew Fielden
    Andrew Fielden about 4 years
    Outstanding! Helped me convert a SDD with Ubuntu in BIOS mode booting, to EFI. Only caveat was a network problem which prevented running the apt-get command. For my solution to this, see comment on the next answer down, who also got the same problem.
  • Pro Backup
    Pro Backup about 4 years
    @AndrewFielden Did I improve my answer correctly to reflect your error and proposed solution?
  • Andrew Fielden
    Andrew Fielden about 4 years
    @ProBackup looks good (I made a minor change). Thanks again, your help rescued my SDD.