If you want to remove an OS in a computer where you have two or more OS installed, and resize the partitions, follow this tutorial.

Introduction

I am going to describe the process of removing an OS that was created after the operating system you want to keep (“main system”). The main system partition needs to be before the system partition you want to remove.

Use a Live USB

If you want to resize the partition of the OS you want to keep, you’ll need a system that can boot from a USB, because the partition you want to resize needs to be unmounted.

Delete the partition of the OS you want to remove

  1. Type fdisk -l (change to the root user if needed). Take note of the device in where the partition you want to remove is (for example: /dev/sda).
  2. Type fdisk and the device name.
    fdisk /dev/sda
    
  3. Type p to list the partitions. Remember the number of the partition you want to remove.
  4. Type d to delete a partition. It will show a prompt where you need to type the partition number you want to delete (for example: 6).
  5. Type p to check if the main system partition has the same number as before.
  6. Type d to delete the main system partition (don’t worry, we are not really going to delete it, but we are going to re-create it). Type the partition number of the main system. It will ask you if you want to remove an existing signature, type N for No.
  7. Type p to check again the partition table.
  8. Type n to create a new partition. When it asks you for the “Last sector”, type +, and the size you want for the partition (for example: +100G). If you want the partition takes all available space, accept the default.

Resize the main OS filesystem

  1. Run e2fsck -f <partition path>.
    e2fsck -f /dev/sda3
    
  2. Run resize2fs <partition path>.
    resize2fs /dev/sda3
    
    • It will resize the filesystem to fill all the partition space.

Bootloader

  1. You may need to update your bootloader (usually GRUB). Depending of the Linux distro, this can be achieved using update-grub or grub-mkconfig -o <grub.cfg path>. If you have problems doing this from the Live USB, try rebooting (from the hard drive). If you see the GRUB command-line (instead of the GRUB boot menu), you can follow these steps in order to recover the GRUB menu.

GRUB only shows a command-line, not the boot menu

  1. Type ls / to see if you are in the boot partition (it will show efi and boot folders). If it’s the boot partition, go to step 2. If not, type only ls to see the partition list and then type ls <partition name>/ with every partition until you see boot folders. Then change root to the correct partition.
    # in this case, (hd0,1) is the correct partition
    grub> ls (hd0,1)/
    grub> set root=(hd0,1) 
    
  2. Look for the .efi file for the Grub boot menu. It can be in /EFI/GRUB/grubx64.efi.
  3. Run chainloader and the path of that efi file.
    grub> chainloader /EFI/GRUB/grubx64.efi
    
  4. Run boot. If you’re lucky it will show the system boot menu.