UEFI Boot – How to Move EFI and Boot Partitions

bootpartitionuefi

I am in the midst of moving these two partitions from sda5 and sda6 to sda1 and sda2 respectively. This is to allow me to have a contiguous space for the root file system to grow. The following is what I have done so far:

  • Create partition sda1 for EFI System with gdisk
  • Create partition sda2 for boot with gdisk
  • Copy content on sda5 to sda1 with dd
  • Copy content on sda6 to sda2 with dd
  • Remove boot flag on the old EFI System sda5 with parted

The following is what I have now (# parted -l):

Number  Start   End    Size    File system  Name                  Flags
 1      1049kB  211MB  210MB   fat16        EFI System            boot
 2      211MB   735MB  524MB   ext4         Microsoft basic data
 4      200GB   250GB  50GB
 5      250GB   250GB  210MB   fat16        EFI System Partition
 6      250GB   251GB  524MB   ext4
 7      251GB   481GB  230GB                                      lvm

Upon reboot, the boot menu that I was presented with is still tied to what is inside the old EFI System partition in sda5, despite turning off its boot flag. How to proceed further from here?

Best Answer

Just to share, this is what I have done:

There is no need to perform grub-install since all the files are already there. What needs to be done subsequently is to create a new boot option at the partition sda1 using the EFI boot manager and pointing to the shim.efi bootloader:

# efibootmgr -c -L Fedora -l \\EFI\\fedora\\shim.efi

Then check its boot position (refer to PARTUUID using blkid if not sure):

# efibootmgr -v
BootCurrent: 0004
Timeout: 1 seconds
BootOrder: 0004,0000,0002,0001
Boot0000* Fedora    HD(1,800,64000,<PARTUUID>)File(\EFI\fedora\shim.efi) <= NEW
...

and make sure that it is the first boot loader in the sequence:

# efibootmgr -o 0000,0002,0001,0004

For grub, what needs to be done is to change all instances of /boot location to point to the new partition:

# vi /boot/efi/EFI/fedora/grub.cfg

....
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt6 --hint-efi=hd0,gpt6 --hint-baremetal=ahci0,gpt6
....

Search and replace "gpt6" with "gpt2" (if /boot is moved from sda6 to sda2)

To prevent the OS from mounting the old /boot and /boot/efi partitions due to duplicate UUIDs, edit fstab:

# vi /etc/fstab

Replace the duplicate references of UUIDs with PARTUUID (if you are using GPT) or device node (e.g. /dev/sda1).

Reboot and you are done.

Related Question