Expand the logical volume by fill free space on Hyper-V

The logical volume on Hyper-V may be half size of the virtual disk. I installed the Ubuntu Server on the Hyper-V virtual machine, then I found the root volume is only half size. I specified the size of the virtual disk to 256 GB but the root volume was only 128 GB.

Check the current status

Check the current status of your machine with df .

$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              791M  1.1M  790M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  125G   11G  109G   9% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop1                          62M   62M     0 100% /snap/core20/1242
/dev/loop2                          56M   56M     0 100% /snap/core18/2246
/dev/loop7                          62M   62M     0 100% /snap/core20/1270
/dev/loop4                          43M   43M     0 100% /snap/snapd/14066
/dev/loop5                          44M   44M     0 100% /snap/snapd/14295
/dev/loop6                          68M   68M     0 100% /snap/lxd/21835
/dev/loop3                          68M   68M     0 100% /snap/lxd/21803
/dev/loop0                          56M   56M     0 100% /snap/core18/2253
/dev/sda2                          976M  204M  706M  23% /boot
/dev/sda1                          511M  5.3M  506M   2% /boot/efi
tmpfs                              791M     0  791M   0% /run/user/1000

The size of the root partition is 125GB.

Fill the free space

To expand the LVM logical volume, we need the path to the volume, use lvdisplay .

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                jOhKhn-FPg7-ZtyK-tK10-fF2g-pPUL-Vt4Yaa
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2021-05-27 03:29:41 +0000
  LV Status              available
  # open                 1
  LV Size                127.25 GiB
  Current LE             32576
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

lvdisplay print the logical volume information, and you can see the the path is /dev/ubuntu-vg/ubuntu-lv.

Expand it with lvextend.

$ sudo lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 127.25 GiB (32576 extents) to <254.50 GiB (65151 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

The first parameter is an amount of expanding. -l+100%FREE means filling free space. The second parameter is a path to the volume.

To reflect to the file system, use resize2fs.

$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 16, new_desc_blocks = 32
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 66714624 (4k) blocks long.

resize2fs may takes a moment.

Use df to see the volume is successfully expanded.

$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              791M  1.1M  790M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  251G   11G  229G   5% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop1                          62M   62M     0 100% /snap/core20/1242
/dev/loop2                          56M   56M     0 100% /snap/core18/2246
/dev/loop7                          62M   62M     0 100% /snap/core20/1270
/dev/loop4                          43M   43M     0 100% /snap/snapd/14066
/dev/loop5                          44M   44M     0 100% /snap/snapd/14295
/dev/loop6                          68M   68M     0 100% /snap/lxd/21835
/dev/loop3                          68M   68M     0 100% /snap/lxd/21803
/dev/loop0                          56M   56M     0 100% /snap/core18/2253
/dev/sda2                          976M  204M  706M  23% /boot
/dev/sda1                          511M  5.3M  506M   2% /boot/efi
tmpfs                              791M     0  791M   0% /run/user/1000

OK. The size of the root volume is now 251GB.

Sponsored Links
Get the Latest News !

ServerLatest 8 Posts