6

When installing Ubuntu I unknowingly set my EFI mount to the Windows EFI partition. Now I need to delete windows along with its EFI partition for a fresh install. I already have another partition prepped up to be the Ubuntu EFI boot partition.

How do I migrate /boot/efi to that partition?

Mythreya
  • 108
  • Why change. You can only have one efi partition per hard drive and Ubuntu easily uses the one that already exists. With gparted it is the boot flag on a FAT32 formatted partition that defines the efi partition. But only one per hard drive. – oldfred May 10 '14 at 16:32
  • 2
    It's perfectly legal to have multiple EFI System Partitions (ESPs) on a single hard disk, although the Windows installer gets confused by such a setup. That said, I agree that there's no need to change. – Rod Smith May 10 '14 at 19:47

5 Answers5

6

An EFI System Partition (ESP) is simply a FAT32 partition with a GUID type code of C12A7328-F81F-11D2-BA4B-00A0C93EC93B (or 0xEF on an MBR disk). Most partitioning tools have some other way of displaying the GUID type code, because GUIDs are so cumbersome. In parted, GParted, and most other libparted-based tools, it's shown as a "boot flag" being set on the partition. (Note, however, that in libparted-land, the "boot flag" on a GPT disk is unrelated to the "boot flag" on an MBR disk. AFAIK, libparted provides no way to correctly label an MBR ESP.) In GPT fdisk (gdisk, sgdisk, and cgdisk), an ESP has a type code of EF00. Non-Linux tools have their own ways to identify ESPs.

Thus, to create a new ESP, you would:

  1. Boot to any Linux tool that lets you partition the disk. This could be your existing Linux installation or an emergency disk/live CD -- but if you use your regular installation, be aware that you may be limited in what you can do, because many partitioning tools limit what you can do to a disk with partitions that are mounted.
  2. Launch the partitioning tool of your choice.
  3. If necessary, create a new partition. I recommend making it at least 550MiB in size. Note that you may need to shrink existing partition(s) to make room.
  4. Place a FAT32 filesystem on the partition. Some tools, such as GParted, make it possible to combine this step with the previous one.
  5. Mark said partition as an ESP.
  6. Unmark or delete the old ESP.
  7. If necessary, save your changes.

For making partition table changes, there's no need to be concerned with your boot mode -- you can use EFI mode or BIOS mode as you see fit. (That said, some computers make it easier to boot from USB or CD-R in one mode or another.)

I agree with oldfred that creating a new ESP is unlikely to be necessary in your scenario. If you want to completely erase the Windows boot loader from the ESP, feel free to do so -- it would be the /boot/efi/EFI/Microsoft directory tree once Ubuntu is installed. Note that this will not remove the Windows boot loader from the firmware's boot manager menu. To do that, you'll need to use efibootmgr, as in:

$ sudo efibootmgr 
Timeout: 10 seconds
BootOrder: 0000,0004,0001,0002
Boot0000* rEFInd boot manager
Boot0001* PATA: HP DVD Writer 1040r     
Boot0002* SATA: ST32000542AS             2
Boot0003* SATA: TOSHIBA DT01ACA300       3
Boot0004* Windows boot manager
Boot0008* INTERNAL EFI SHELL: ST32000542AS
$ sudo efibootmgr -B -b 4

This example deletes boot option #4, which is identified as "Windows boot manager." (I don't recall the name that Windows uses by default; I edited this example from one of my systems on which Windows is not installed.)

Rod Smith
  • 44,284
  • 7
  • 63
  • 105
  • Is it really necessary 550MB for /boot/efi? I have 511Mb partition and there is only 5Mb used among them. – Suncatcher Jul 13 '17 at 11:19
  • I recommend 550 MiB to work around a couple of (admittedly rare) bugs: Some EFIs have problems with FAT32 partitions smaller than 512 MiB (note: MiB, not MB; the distinction is important), but some tools (like mkdosfs) create FAT16 by default on partitions smaller than some value I've forgotten, but that's slightly above 512 MiB, so I round up to 550 MiB. Some EFIs have problems with FAT16, so using it on a smaller partition is also inadvisable. You might be OK with a smaller and/or FAT16 ESP, but a 550MiB FAT32 ESP is safest, in general. – Rod Smith Jul 13 '17 at 13:32
1

Try using the Ubuntu's disk manager before installing it. Allow bios to be in CSM boot mode before installing "try ubuntu", disks, click on the partition needed format, leave blank or you can format to ext2. Restart, bios back to UEFI boot mode, install should work fine.

1

Using a bootable USB flash drive with your version of Linux installed including Gparted.

Boot from the flash drive by accessing boot order in your BIOS.

On my Asus laptop, the Aptio BIOS, it was necessary to disable FastBoot and SecureBoot before the BIOS would enable Flash drive booting as an option.

Once you can boot from USB, run your Distro with the "Try Ubuntu" option. Now that you are running from the Flash Drive, using Gparted to manage your partitions is fairly straightforward.

Using Gparted while logged in on your HDD Distro is risky.

RCF
  • 2,097
  • 4
  • 19
  • 25
1

On my HP p066us laptop, I have to set the efi boot order in the BIOS, which takes precedence over settings in the efi boot partition. If edits using the efibootloader program don't work for you, you may have to look through your BIOS settings.

0

This can happen when you install Ubuntu onto a device with multiple ESPs in its disk or disks. Seems to be a fairly old bug of Ubuntu, when you have multiple ESPs set up, the installation program only use the first one it found. Here's some detailed info

Reason to change:

When you are setting up more then one EFI system partition, it's most likely because you want a multi-booting with each OS installed on separated physical disks. In that case, your Ubuntu disk pretty much would be an external storage device, thus once you set Ubuntu as the first entry in your UEFI boot list, your computer automatically boots into Ubuntu when you plug your external disk in, and boots into another OS when external disk is removed. And that's where the default installation behavior cause trouble. As you remove the external device, the Ubuntu boot files are still in the ESP of your internal disk, so bootloader loads them first at computer start up, but then it can't find the actual Ubuntu OS, and you ends up stuck in the grub command line.

Solution:

In my case it's fairly easy, I had to get into my Ubuntu system and copy every thing from the old ESP to the ESP I want Ubuntu to boot from, then configure it using efibootmgr.

Show disk info:

$ lsblk -e 7 -o name,fstype,mountpoint,uuid,partuuid
NAME        FSTYPE MOUNTPOINT                 UUID                                 PARTUUID
sda                                                                                
├─sda1      vfat   /boot/efi                  0C47-F306                            60c76b70-01
├─sda2                                                                             60c76b70-02
└─sda5      ext4   /                          8357ad81-13cf-48a9-b74e-a528df7e79d6 60c76b70-05
nvme0n1                                                                            
├─nvme0n1p1 vfat   /media/my_user/SYSTEM_DRV  C6B4-C00B                            aaeb7117-8371-4ab0-9d3f-c3913a79d819
└─...

Inspect current boot entries:

$ efibootmgr -v
BootCurrent: 0002
Timeout: 0 seconds
BootOrder: 0002,0000
Boot0000* Windows Boot Manager  HD(1,GPT,aaeb7117-8371-4ab0-9d3f-c3913a79d819,0x800,0x82000....
Boot0002* ubuntu    HD(1,MBR,0x60c76b70,0x800,0x100000)/File(\EFI\ubuntu\shimx64.efi)

(note that I had an MBR partition type for my current ESP because I parted it on an old computer, I don't have problem with it but you may want to make sure using GPT, modern UEFI may not recognize MBR disks)

Say I want to change active ESP from sda1 to nvme0n1. Once copied all files, this partition should have an EFI/ubuntu directory (with absolute path MOUNTPOINT/EFI/ubuntu), where Ubuntu boot files are located. Now create a boot entry for the new ESP:

$ sudo efibootmgr -c -d /dev/nvme0n1p1 -l \\EFI\\ubuntu\\shimx64.efi

Run efibootmgr -v again, check if the PARTUUID of the new ESP shows up in the new entry. Then edit /etc/fstab, replace the UUID of old ESP with new one to auto mount new ESP to /boot/efi at next boot.

That's all for me. You may also want to adjust boot order using efibootmgr -o, or delete old Ubuntu entry using efibootmgr -b 0002 -B. If you don't feel safe to reboot, you can still find more detailed answers like this one. It's also great to prepare a live USB for recovery, in case something really went wrong