Goal:
I have a VMware, increased the size of this machine from VMware GUI but still the free space is unusable in Ubuntu machine. In this tutorial will see how we can safely extend/increase the size of partition with no space. In short we will add 18 GB of space to the 100% full partition.
We can see the Root partition is full:
df -h
Let’s see available free space. We can see the total size of /dev/sda
below image. So Size is changed. Linux will add this free space by itself. Now we will create another partition and then add it to the partition which is 100% full.
sudo fdisk -l
(Optional)
sudo lsblk
Select partition:
sda3 is partion of disk sda.
Enter root : sudo -s
fdisk /dev/sda
Enter “m” to list all commands:
Enter F:
To check free space, Here we have 11G (11 GBs) free space. Unpartitioned.
Let’s create a partition,
Enter n, Press Enter after it to select default max values. We can see partition is now created.
(Optional) In above it new partition it already selected the “Linux filesystem”. Just in case you want to change type in future partitions.
Enter Command n:
it will select the new partition automatically, You can also specify it. Enter L for the list.
I will select option 20: Linux file system. Press q to exit list.
now, Enter 20
Save changes:
Enter w:
write changes.
Reboot:
shudown -h now
SSH or login again,
We can see the new partition is added.
sudo fdisk -l
Now, Create Physical volume: /dev/sda4
sudo pvcreate /dev/sda4
We can see the volume size, and free size.
sudo vgdisplay
Extend:
Here we will extend, or add the new partition /dev/sda4
to VG NAME : ubuntu-vg
. See the vg name in above image.
sudo vgextend ubuntu-vg /dev/sda4
We can see the Volume size, and free space is changed but Alloc size is still same. Now we need to use this free space.
sudo pvscan
Get Lv path of this volume group:
sudo lvdisplay
Time to Extend it:
+100%FREE mean use all the free space. You can also specify as much you want change command little bit sudo lvextend -L +10G /dev/ubuntu-vg/ubuntu-lv
. This will extend 10Gb space.
sudo lvextend -l +100%FREE <Logical Volume path>
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
At this point we have increased the size of the block volume where your root filesystem resides, but we still need to extend the filesystem on top of it.
df -h
Resize it:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Now, we are good. The free space is added successfully.
Thank you for reading, and understanding it. I hope it have helped you. 😎
Top comments (0)