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:
/dev/sda2 EFI partition
A bootable media (live USB etc.) with Ubuntu or some other Linux distribution is required. Make backups before following these steps.
Boot from Ubuntu media and open Terminal (Ctrl+Alt+T). Become root:
Mount filesystems of
/boot and the EFI partition:
mkdir efi boot os
mount /dev/sda2 efi
mount /dev/sda5 boot
mount /dev/sda6 os
Copy contents of the
/boot partition into
/boot directory on
cp -r boot/* os/boot
Prevent Ubuntu from mounting
/boot automatically. Also take note of root partition's UUID. Open
/etc/fstab in your preferred editor:
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.
Update GRUB's configuration on the EFI partition. This step is crucial on UEFI systems.
cp grub.cfg grub.cfg.bak
grub.cfg looked like this:
search.fs_uuid f7c32b17-a2f1-4eb3-a8e7-414b6a228a72 root hd1,gpt5
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
Note that it's the same UUID I got from
/etc/fstab and I had to prepent
/boot to the prefix.
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
Reboot once more, confirm that the OS is up and do whatever you want with your ex-boot partition.