Ubuntu: How to allow partitions to dynamically extend?


I have a virtual machine (on Hyper-V host) running Ubuntu server 16.04.3. It is set up to have dynamically expanding virtual hard disk (VHDX).

I have disk space issues when trying to "tab-complete" names:

-bash: cannot create temp file for here-document: No space left on device  

I asked df -h and here is what the server responded:

Filesystem                 Size  Used Avail Use% Mounted on  udev                       221M     0  221M   0% /dev  tmpfs                       48M  1.8M   47M   4% /run  /dev/mapper/zapp--vg-root  2.0G  2.0G     0 100% /  tmpfs                      240M     0  240M   0% /dev/shm  tmpfs                      5.0M     0  5.0M   0% /run/lock  tmpfs                      240M     0  240M   0% /sys/fs/cgroup  /dev/sda1                  472M   70M  379M  16% /boot  tmpfs                       48M     0   48M   0% /run/user/1000  

Obviously, that 2.0G partition is full. However, the virtual disk hadn't reached the size allowed size (3.0GB max, 2.69GB real).

We tried to expand the disk limit to 5GB, but the server doesn't seem to notice and use the available space - even after a restart.

Is it possible to allow these partitions to expand when needed until the cap of disk size is reached? Or what should be done here?


First you need to run parted and use its resizepart command to expand the partition to use the whole disk, then run pvresize to tell LVM about the new space, then run lvresize to grow the logical volume, and finally resize2fs on the logical volume to grow the filesystem to use the new space. This can be done without a reboot.


If the machine sees the expanded space, and if you're using LVM (which appears to be the case), then you can use the lvresize command to resize the partition to fill up the new space. This does not happen automatically.

You'll want to become familiar with the man page of lvresize, and in particular the --resizefs and --size switches.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »