Oracle VirtualBox: Resize Linux Filesystem

We have an Oracle Linux Virtual Machine that we created in our previous post up and running.

When I examined the space on this VM, I found that I have only 2GB of free space available in “/” filesystem, which is not enough for me to do my work.

So, I decided to increase the space by another 10GB.

How many physicals disks that we have, how many partitions?. Let us see:

So, we have one physical disk (/dev/sda) divided into 2 partitions, /dev/sda1 for /boot (small one) and larger partition /dev/sda2) , that is used to build LVM.

We have to Logical Volums (2 lvs) ,, one for swap (3GB) , and the larger one for “/” file system.

Given this disk layout, we have two options to increase the “/” filesystem size:

1- To add a new physical disk to the VM, and use it to expand the LV and so the filesystem.

2- To resize the current physical disk from about 39GB to 50 GB, and then resize the LV and filesystem.

I’ll proceed with the second option.

Stop the VM

The fist step is to resize the hard disk from the OS to be 50GB using VBoxManage command

Now start the VM, and check the free space:

Nothing changed so far.
You notice now that the physical disk /dev/sda has larger size

Now, we will use the newly added space to create a new disk partition, using the fdisk command:

Now examine the disk layout again:

So, we can see that we have a new disk partition /dev/sda3

Now, we are going to create physical volume on the new partition (but we need to reboot the VM first):

so, now we 2 PVs , but the new one still not added to the volume group.

What about the volume group?:

We have one volume group with about 40GB, the new disk still not reflected.

Now we are going to extend the volume group with the newly added PV (/dev/sda3):

So, now the volume group is about 50GB, 10GB of them are free:

What about the logical volums?:

We have 2 LVs, and we need to extend the first one by 10GB

Extend the LV (lv_root) by 10GB:

Now is the last step, which is to extend the filesystem created above the logical volume lv_root:

Now, check the free space again:

The 10GB added successfully to our “/” filesystem.

That’s all.

Donate to support our blogging work




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s