Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

How to merge unallocated space in linux?

2 Answer(s) Available
Answer # 1 #
  • Take a full system backup using CloneZilla Live¹
  • Boot a live environment of gparted.
  • Move sda3 to the left (this will move both sda5 and sda6 as well)
  • Extend sda3 with the now free space at the end.
  • Move sda6 to the end of sda3.
  • Extend sda5 still leaving 10% of the disk space unallocated between sda5 and sda6 ²
[1]
Edit
Query
Report
Kraig Moati
Psychiatric Nurse
Answer # 2 #

In this post we'll briefly explain how to fullfill such task in most Linux operating systems - such as CentOS, RHEL, Ubuntu, Debian and more - using a simple & secure approach based on four convenient built-in tools: parted, partx, pvresize and lvextend. The best part about such techinque is that it doesn't even require a reboot, which makes it definitely better than other reboot-based approaches such as this one.

The first thing we need to do is to retrieve the names of the disks and the partition we want to resize. To do that, execute the lsblk command to show the system's information about all available block devices. In this tutorial we'll take the following scenario as an example:

By looking at the above screenshot we can easily determine the following:

As we can easily see, we do have roughly ~100GB of unallocated space on the sda disk: in this tutorial we'll see how we can assign them to the lv_root logical volume, thus extending it from 97.4GB to 197.4GB (or so on).

Now that we've successfully recovered the disk name (sda), the partition name (sda2), and the names of the volume group (vg) and logical volume (lv_root) we want to resize/extend, we can proceed with the actual task.

Open a terminal window (with root permissions) and type the following commands, replacing the names of our sample scenario with those recovered early on:

Here's a brief explanation of the above commands:

As soon as we issue these four commands, we can issue the lsblk command again and see what happened to our system's devices:

As we can see, the resize/extend operation has been completed without flaws: the lv_root logical volume (and filesystem) has been successfully extended from 97.4GB to 199.5 GB. The newly available space is also ready to use, without requiring a reboot.

That's it, at least for now: we sincerely hope that this post will help other System Administrators to resize/extend the disk space of their CentOS, RHEL, Ubuntu, or Debian Linux Virtual Machines.

[0]
Edit
Query
Report
Usama cmqiyzu
CORK MOLDER