[Linux] Adjust and increase the capacity of VDI virtual drive to install Ubuntu on VirtualBox

Table of Contents

[Linux] Adjust and increase the capacity of VDI virtual drive to install Ubuntu on VirtualBox

Problems encountered

I have deployed an ubuntu server on the virtualbox virtualization platform, I divided the hard drive space is 200GB, but after creating and checking, the hard drive space is only 100GB

s1@s1:/shared/docker/nn4/database$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.6G  1.5M  1.6G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   97G   74G   19G  80% /
tmpfs                              7.9G     0  7.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  247M  1.6G  14% /boot
tmpfs                              1.6G  4.0K  1.6G   1% /run/user/1000

image

I checked the hard drive space more closely, and it was clear that it still received the 200GB I had divided, but only allocated 100GB to use, the rest was not divided

s1@s1:/shared/docker/nn4/database$ sudo lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
loop0                       7:0    0 55.6M  1 loop /snap/core18/2566
loop1                       7:1    0 63.2M  1 loop /snap/core20/1623
loop2                       7:2    0   62M  1 loop /snap/core20/1587
loop3                       7:3    0 79.9M  1 loop /snap/lxd/22923
loop4                       7:4    0  103M  1 loop /snap/lxd/23541
loop6                       7:6    0   48M  1 loop /snap/snapd/16778
loop7                       7:7    0   48M  1 loop /snap/snapd/17029
sda                         8:0    0  200G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    2G  0 part /boot
└─sda3                      8:3    0  198G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0   99G  0 lvm  /
sr0                        11:0    1 1024M  0 rom

image

Extend LVM virtual partition

If Ubuntu uses the LVM (Logical Volume Manager) virtual partition, we need to extend it to use the full capacity of the /dev/sda3 partition

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

Result: Successful partition extension

s1@s1:/shared/docker/nn4/database$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <99.00 GiB (25343 extents) to <198.00 GiB (50687 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
s1@s1:/shared/docker/nn4/database$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 51903488 (4k) blocks long.

s1@s1:/shared/docker/nn4/database$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              1.6G  1.5M  1.6G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  195G   74G  113G  40% /
tmpfs                              7.9G     0  7.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  247M  1.6G  14% /boot
tmpfs                              1.6G  4.0K  1.6G   1% /run/user/1000
s1@s1:/shared/docker/nn4/database$

image

Note: if you get the error write error failed: No space left on device, clear the apt cache (this cache will be automatically recreated later), then proceed to step 3.

rm -rf /var/cache/apt

References

Leave a Reply

Your email address will not be published. Required fields are marked *