Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
1  
I would still use boot repair. You assume you need to install packages ... I believe you are wrong. See: askubuntu.com/questions/226061/… – Rinzwind Aug 10 '14 at 16:34
    
@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. – Pro Backup Aug 10 '14 at 16:59
1  
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/… – oldfred Aug 10 '14 at 20:58
    
@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. – Pro Backup Aug 11 '14 at 12:21
    
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 – oldfred Aug 11 '14 at 19:02
up vote 20 down vote accepted

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

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, http://superuser.com/questions/376470/how-to-reinstall-grub2-efi might help.

share|improve this answer
    
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. – Robie Basak Mar 22 at 1:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.