I recently have upgraded my PC, my new Motherboard (ASUS M5A99X EVO) uses UEFi instead of the regular MBR option.
I have a Ubuntu 11.10 installation that I did when I had my previous hardware (MSI MS 7267) , Ubuntu alone boots fine, and so does Windows 7, however Windows 7 is using UEFI (GPT) boot whereas Ubuntu is using MBR.
I have my OSs in separate drives, so that GRUB2 wont' get replaced by the Windows Bootloader and viceversa, as I said both OSs boot fine on their own, but to do that I have to disconnect one drive in this case the Ubuntu drive as it prevents Windows from loading.
Now my question is, How can I change/convert Ubuntu's drive so that instead of using MBR it uses GPT and allow Windows to boot?.
Preferably without reinstalling the whole system or lose any data.
And if I were to wipe the drive, How can I install Ubuntu in GPT, UEFI, whatever it is mode?.
I have used gdisk to convert from MBR to GPT, but now Ubuntu can't boot seems like grub just doesn't start.
I have re installed the OS, and the drive is GPT now by default however grup-pc
is still being used instead of grub-efi
.
How can i make Ubuntu boot from EFI?.
Table of contents:
Terminology
BIOS = Basic Input/Output System
(U)EFI = (Unified) Extensible Firmware Interface
MBR = Master Boot Record
GPT = GUID Partition Table
UEFI / EFI / BIOS = Firmware interface
MBR / GPT = How the computer knows (per hard disk) what partitions are on the drive and how to boot from them.
UEFI / BIOS
A firmware interface is the way that the firmware (the software inside devices) and operating system interact. It initialises the hardware then runs the operating system and ensures that the operating system drivers can operate the hardware.
The BIOS has been the usual firmware interface that has been used. The UEFI is a newer interface that has several features, such as being faster, having a GUI and being able to start the network card and get an ip address. UEFI replaces EFI. (Those developing EFI saw that there were others doing something similar and so joined them, bringing the ideas of EFI with them. This then became UEFI).
A BIOS requires the bootloader to be at the start of the disk, however a UEFI uses a partition for this and can choose among multiple boot loaders to use.
MBR / GPT + GRUB
The MBR is a section of code at the start of the disk that contains a boot loader (for the BIOS), as well as the partition map and a unique disk identifier.
To install GRUB onto a disk with a MBR, GRUB places a small program in the MBR to load the rest of GRUB from another part of the disk. (This is done because the MBR is too small to contain all of GRUB). The space that is chosen is space between the MBR and the first partition, which usually exists.
GPT is a standard for how the partitons are specified. It does have a 'protective' MBR, however this is only for allowing BIOS based computers to boot and stop tools that only know about MBR from trying to trash GPT. It can have
(How GPT is handled depends on whether it is booting using a BIOS (or UEFI system in BIOS emulation mode) or UEFI. I will focus on UEFI as it relates to the question).
Boot loaders for operating systems are stored in a partion called EFI System Partiton, that is formatted (usually) with FAT32. This is where GRUB is installed.
Converting
First...
We are playing around with the partition table, so guaranteed safety is not possible. It is a risky operation. However, the method should not lose data.
Others coming across this: Do not use on Apple Macs.
Now...
You will need to do this on a live CD (or another linux installation installed to a different disk.)
When dealing with GPT disks, we need to use a GPT aware program. 'GPT fdisk' is a good tool to use and what I will be using. It can be called
gptfdisk
orgdisk
depending on distribution (Ubuntu calles itgdisk
). Parted (and Gparted) is also GPT aware, so can 'safely' be used with GPT disks.To convert you need to:
1) Resize partition
Use
parted
(command line) orgparted
(GUI) to resize the first and last partition. The first partion should have about 200MiB before it, and the last partition should have 1MiB to 2MiB (either will do) taken off the end.2) Convert the disk
Run
changing the device you want to convert is
/dev/sdx
.It should tell you that it will convert the partiton table.
Now add a new partition, making it of type 'EFI system'. It should find the free space at the beginning (I suggest some low sector number like 34) and automatically use all the free space. The examples use a 4GB USB flash drive with 1 partition already on there, resized as per above.
You should now have the EFI partition.
Then exit
gdisk
Now use Gparted (or command-line
mkfs.vfat -F 32 /dev/partition
) to format the partition as FAT32.3) Install GRUB
This comes with less assurances that the previous part as I have not tried it myself.
I am not sure about this step, so I'll guess using RAOF's instructions:
You should work out which version of grub-efi to install with
If it says
EFI32
install thegrub-efi-ia32
package, if it saysEFI64
install thegrub-efi-amd64
package. You can install the packages withThis will probably only work if you have booted in EFI mode.
If it does not work, you could try these step by step instructions (under "Install GRUB2 in (U)EFI systems") once
grub-efi
is installed.Configuring (+ Dual Boot)
If RAOK's instructions work, you should be able to add the following line to
/etc/grub.d/40_custom
It assumes that Windows is recognised as
hd0
by GRUB. It may need to be changed tohd1
in order to work.Now run
to update the config file.
References and further reading
I used several sources.
This answer is incomplete; I've not tested any of this. It's unlikely to eat any of your data, but you have been warned!
What I would guess is happening here is that your BIOS is preferentially booting from legacy MBR, so poor old UEFI Windows 7 is getting overlooked.
One of the nice things about UEFI is that you should no longer need to worry about Windows overwriting GRUB; they should both coexist nicely on the EFI partition. One option would therefore be to switch to
grub-efi
. Note: I'm unsure whethergrub-efi
understands MSDOS-style partitions; I think it does. If it does not, this will fail to boot, and you'll need a LiveCD to recover. In fact, have a LiveCD handy anyway!To switch to
grub-efi
you'd want to/boot/efi
. Add this to/etc/fstab
¹grub-efi
packageUEFI and Legacy
toUEFI only
(or a similar option)That should leave you with a UEFI-booting Ubuntu install. If it does not, boot up your trusty LiveCD (or Ubuntu Alternate install CD - the “Fix a broken system” option is what you're after ☺), chroot into your system, and install
grub-pc
again.¹: More detail for this step: You'll need to find what the Linux kernel calls your EFI system partition. This will be something like
/dev/sda2
,/dev/sdb3
, or such². You'll then need to make the/boot/efi
directory, and add a line to/etc/fstab
. If your EFI partition is/dev/sdb3
, then you would add the following line:Once you run
sudo mount /boot/efi
you should then find that/boot/efi
contains aEFI
directory, with a subdirectory for Windows 7.²: Since you've got multiple hard drives it might be a good idea to find out the UUID of the partition, as that will be stable under addition/removal of harddrives whereas the
/dev/sda2
name is not guaranteed not to change. This can be done after you've finished setting everything else up, though.You can find the UUID by looking in
/dev/disk/by-uuid
. For example, I get:In my case, I know
/dev/sda1
is my EFI system partition, so I havein my
/etc/fstab
.That's ideal, so you're likely to have at least one primary partition free in the partition table.
You don't have to convert MBR to GPT to do UEFI booting, just create a primary FAT partition, install the
grub-efi-amd64-bin
package and follow the instructions in Add an ESP to an existing installation with MBR which should work with current releases of Ubuntu.To complement Portablejim's answer (which really helped me for converting from MBR to GPT, thanks !), you can use Boot-Repair to reinstall grub. It worked like a charm to repair my boot after I failed to complete step 3, and once again when the installation of Windows 10 made the linux boot option disappear.