How to remove separate /boot partition on UEFI system?

When installing Ubuntu, I have created a separate /boot partition for no good reason. Now I'd like to use that partition for something else and move my boot files to the main partition.

I tried the steps from this answer, but now my system boots into GRUB's prompt.


Solution 1:

This answer is a good starting point, but it's not sufficient on UEFI systems.

Here's a step-by-step guide which worked for me.

This answer assumes following partition names:

Device      Purpose
-------------------------
/dev/sda2   EFI partition
/dev/sda5   /boot
/dev/sda6   /

A bootable media (live USB etc.) with Ubuntu or some other Linux distribution is required. Make backups before following these steps.

  1. Boot from Ubuntu media and open Terminal (Ctrl+Alt+T). Become root:

    sudo su
    
  2. Mount filesystems of /, /boot and the EFI partition:

    cd /mnt
    mkdir efi boot os
    mount /dev/sda2 efi
    mount /dev/sda5 boot
    mount /dev/sda6 os
    
  3. Copy contents of the /boot partition into /boot directory on / partition:

    cp -r boot/* os/boot
    
  4. Prevent Ubuntu from mounting /boot automatically. Also take note of root partition's UUID. Open /etc/fstab in your preferred editor:

    gedit os/etc/fstab
    

    Here's what mine looked like (save for comments):

    UUID=df89aab6-941d-4ffa-9681-e16fc94641d3 /               ext4    errors=remount-ro 0       1
    UUID=f7c32b17-a2f1-4eb3-a8e7-414b6a228a72 /boot           ext4    defaults        0       2
    UUID=2252-1B80  /boot/efi       vfat    umask=0077      0       1
    UUID=a80bb662-d531-408b-bc23-b47f28c44ec4 /home           ext4    defaults        0       2
    /swapfile   none    swap    sw  0   0
    

    I have commented out the second line which mounts /boot. I have also copied UUID of / partition, we'll need that in a moment.

  5. Update GRUB's configuration on the EFI partition. This step is crucial on UEFI systems.

    cd /mnt/efi/EFI/ubuntu
    cp grub.cfg grub.cfg.bak
    gedit grub.cfg
    

    My grub.cfg looked like this:

    search.fs_uuid f7c32b17-a2f1-4eb3-a8e7-414b6a228a72 root hd1,gpt5 
    set prefix=($root)'/grub'
    configfile $prefix/grub.cfg
    

    I had to update: 1. the UUID, 2. the partition number and 3. the prefix. Modified file looks like this:

    search.fs_uuid df89aab6-941d-4ffa-9681-e16fc94641d3 root hd1,gpt6 
    set prefix=($root)'/boot/grub'
    configfile $prefix/grub.cfg
    

    Note that it's the same UUID I got from /etc/fstab and I had to prepent /boot to the prefix.

  6. Reboot into Ubuntu on your hard disk. It should boot just fine. Make sure /boot isn't mounted - grep /boot /etc/mtab should output nothing. Format the old /boot partition (don't confuse it with current /boot, which is a regular directory) and refresh GRUB config:

    sudo mkfs.ext4 /dev/sda5
    sudo update-grub
    
  7. Reboot once more, confirm that the OS is up and do whatever you want with your ex-boot partition.