Safely Extend Volume Size of VMware, Linux.
Tags: linux, virtualmachine, ubuntu, devops
Published: 2023-05-22 19:26:16

**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`

![Root Partitions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1woijdel4yqok7oqwwa.png)

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`

![fdisk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ze7206flie6wh0pivdrl.png)

(Optional)

`sudo lsblk`

![lsblk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nun3osxkirb75j7a4on0.png)

#### Select partition:
_sda3 is partion of disk sda._

**Enter root** : `sudo -s`

`fdisk /dev/sda`

![fdisk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n2k1d8tgvyj6w5jn45gf.png)

Enter **“m”** to list all commands:


![fdisk options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwsp6ir7gjvb40nb01ht.png)

**Enter F:**
To check free space, Here we have 11G (11 GBs) free space. Unpartitioned.

![Free space](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixtp16aezwknae4rnzvj.png)

Let’s create a partition,

Enter n, Press Enter after it to select default max values. We can see partition is now created.


![fdisk options](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pgpiq373m1f6xiftif91.png)

(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.

![partition type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tmjjsszf7g0vam566ay.png)

I will select option 20: Linux file system. Press q to exit list.


![fdisk filesystem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eatskd4eq9903q7gfqmy.png)

now, Enter 20


![fdisk filesystem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7hknrghkunck2h5hhsn.png)

**Save changes:**

**Enter w:**
write changes.

![fdisk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqttou61avwpg1qad2tv.png)

Reboot:

`shudown -h now`


![Linux shutdown](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zlpj80ozx2yog45b4blg.png)

SSH or login again,

We can see the new partition is added.
`sudo fdisk -l`


![fdisk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vhnfe7sooni8m88o046f.png)

Now, Create Physical volume: `/dev/sda4`

`sudo pvcreate /dev/sda4`


![pvcreate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f2ihtcrnlem0d8y45bkx.png)

We can see the volume size, and free size.

`sudo vgdisplay`


![vgdisplay](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlu5jxohg6vpz9csgt1m.png)

#### 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`

![vgextend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kpwj28p0mldkojhtun87.png)

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.


![vgdisplay](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ar1ylam1pvv0onws0i4c.png)

`sudo pvscan`

![pvscan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rtj5hoyb4pogvy175ll2.png)

#### Get Lv path of this volume group:
`sudo lvdisplay`


![lvdisplay](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hx8wlr47q4p2gx8nxddh.png)

#### 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`


![lvextend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gzdabcd10rziuthiel93.png)

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`

![size check](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ts3qy3ogc5qzairsrwd.png)

#### Resize it:

`sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv`


![resize2fs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3ah9efydkjq3b07cjf2.png)
Now, we are good. The free space is added successfully.

`df -h`
![size](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dizj29rsrtex0il8prf6.png)

Thank you for reading, and understanding it. I hope it have helped you. 😎