Extend disk in VirtualBox

So, i am using a VirtualBox machine on my linux server where i host my docker applications/images. I created that VM a while ago, and lately i found (out as more and more applications are running/tested) that the images are filling up the disk of the docker VM.

At first i thought: lets create a new VM with al larger disk; so i did. But migrating all my Dockers (including my Home-Assistant, where a lot of ESP devices are communicating with) means als a lot of reconfiguration.. So the other option became more attractive.. Let’s size-up the disk on Virtualbox. (In the end is wasn’t that hard…)

Resize the disk of the VM.

  1. Make a backup from the source VM or disk. (
  2. Step one: turn the VM off.. Unfortunately you can only resize the VM when it’s powered down.
  3. Start the Orcale VM VirtualBox Manager
    • Goto Tools – Harddisks
    • Select the Disk you want to resize, give the new size in (right from the slider), and klick Apply.
  4. Start the VM.

Extend your linux filesystem.

Now the disk is resized, but we can not use it, because the os is still working with the old disk partition and filesystem settings. So we need to change these settings, with following commands:

  • growpart <disk> <partitionnumber> -> Used to resize the partition from disk to its full length. You might need to install it. you can do that with the ‘sudo apt install cloud-guest-utils’ command.
  • resize2fs <filesystem> -> Resizing the filesystem to the size of the partition.

See following commands:

servacc@docker:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        20G   18G 1012M  95% /

servacc@docker:~$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   41G  0 disk
├─sda1   8:1    0    1M  0 part
└─sda2   8:2    0 20.3G  0 part /

servacc@docker:~$ sudo growpart /dev/sda 2
[sudo] password for servacc:
CHANGED: partition=2 start=4096 old: size=42485760 end=42489856 new: size=85895216 end=85899312

servacc@docker:~$ sudo resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 6
The filesystem on /dev/sda2 is now 10736902 (4k) blocks long.

servacc@docker:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        41G   18G   21G  47% /

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *