User Tools

Site Tools


wiki:resize_lvm_partition_used_by_vm

This is an old revision of the document!


Resize LVM partition used by a VM

Setup:

You have a host server which has a PV volume and lots of different LV volumes used by different qemu-kvm VMs.

You want to expand the disk of test1.1.1.1.1 VM (called a domain in virsh speak). First find the VM via

~# virsh list

then the disk used by the VM:

~# virsh domblkinfo --domain test1.1.1.1.1 --all --human
Target     Capacity        Allocation      Physical
-----------------------------------------------------
vda        40.000 GiB    (parted) select /dev/vda

Using /dev/vda (parted) print Model: Virtio Block Device (virtblk) Disk /dev/vda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:

Number Start End Size Type File system Flags 1 1049kB 1050MB 1049MB primary xfs boot 2 1050MB 49.4GB 48.3GB primary lvm

(parted) print free Model: Virtio Block Device (virtblk) Disk /dev/vda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:

Number Start End Size Type File system Flags

      32.3kB  1049kB  1016kB           Free Space

1 1049kB 1050MB 1049MB primary xfs boot 2 1050MB 49.4GB 48.3GB primary lvm

      49.4GB  64.4GB  15.0GB           Free Space

(parted) quit

38.564 GiB      60.000 GiB

You can see that the Physical and Allocation column are almost the same.

Check if you have available space under Free PE / Size in output below:

~# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  94
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                26
  Open LV               20
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <1.82 TiB
  PE Size               4.00 MiB
  Total PE              476774
  Alloc PE / Size       331078 / 1.26 TiB
  Free  PE / Size       145696 / 569.12 GiB
  VG UUID               wWFiiE-v4CP-pha0-aAtf-zFiZ-0j6f-RUwUID

Check that the LV volume is part of the VG volume (centos here). Now expand the disk size

~# lvextend -L +100G /dev/mapper/test1.1.1.1.1

The above is the new disk size in GB.

Restart the VM to pick up the new disk size.

Inside of VM run these commands (Cent OS 7 example):

Check which filesystem you want to expand:

[root@quad ~]# lsblk -f
NAME                      FSTYPE      LABEL UUID                                   MOUNTPOINT
sr0
vda
├─vda1                    xfs               32d11a94-18ec-42f0-95fd-ca95fb435ea0   /boot
└─vda2                    LVM2_member       OcgeR3-hMty-TsOV-hkAL-4maE-HcjB-KZNpeY
  ├─centos-lv_root        xfs               02c6e4df-8573-4b36-af74-5e67ba36dbcc   /
  ├─centos-lv_swap        swap              be38e77e-69ab-49c3-88a7-e1dad5459076   [SWAP]
  └─centos-lv_varlibmysql xfs               4b574fe6-830e-45a4-9e1f-894fd3296447   /var/lib/mysql

Here we want to expand vda2, centos-lv_root FS. Run these commands:

sudo yum install -y cloud-utils-growpart
sudo growpart /dev/vda 2
sudo pvresize /dev/vda2
sudo lvextend -l +100%FREE /dev/centos/lv_root
sudo xfs_growfs /

The partition should be expanded now.

If you want to check that the new disk size is seen by the VM use the parted tool:

Before expanding disk:

(parted) select /dev/vda
Using /dev/vda
(parted) print free
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 49.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1050MB  1049MB  primary  xfs          boot
 2      1050MB  49.4GB  48.3GB  primary               lvm

After expanding the disk and before expanding the partition and filesystem:

(parted) select /dev/vda
Using /dev/vda
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1050MB  1049MB  primary  xfs          boot
 2      1050MB  49.4GB  48.3GB  primary               lvm

(parted) print free
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1050MB  1049MB  primary  xfs          boot
 2      1050MB  49.4GB  48.3GB  primary               lvm
        49.4GB  64.4GB  15.0GB           Free Space

(parted) quit

Tested on

  • CentOS 7 VM host and guest
  • qemu-kvm

See also

References

wiki/resize_lvm_partition_used_by_vm.1756988188.txt.gz · Last modified: by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki