📜 ⬆️ ⬇️

Increase LVM disk in virtual machine on the fly

Continuing the theme described here habrahabr.ru/post/252973 , again I write about the increase in virtual machine disks.
The configuration is as follows:
Supermicro hypervisor server with KVM and libvirt on Ubuntu.
Guests - Ubuntu with LVM2.
Task:
Increase the size of the system disk without shutting down / restarting the guest OS.

In the comments on the previous article habrahabr.ru/post/252973/#comment_8330673 farcaller wrote:
System can also be decrypted on the fly. To do this, libvirt has a command:
virsh qemu-monitor-command resized-virtual-machine --hmp "block_resize $ DRIVENAME $ NEWSIZE"

For HA projects this is a very important point, the continuous operation of the service is necessary.
I decided to try resizing the disk with virsh.
Below are the results of this successful experiment.

In short it was like this:
On the hypervisor:

On the guest:

profit!
Log from hypervisor
 root @ hyp-0: / local # ls

 ca-1-disk-1.qcow2 vm-db-disk-1.qcow2

 root @ hyp-0: / local # qemu-img info ./vm-db-disk-1.qcow2

 image: ./vm-db-disk-1.qcow2
 file format: qcow2
 virtual size: 800G (858993459200 bytes)
 disk size: 717G
 cluster_size: 65536
 Format specific information:
     compat: 1.1
     lazy refcounts: false

 root @ hyp-0: / local # virsh list

  Id Name State
 -------------------------------------------------- -
  2 vm-ag-0 running
  3 vm-db running
  12 vm-ca-1 running

 root @ hyp-0: / local # virsh qmu-monitor-command vm-db --hmp "info block"

 drive-virtio-disk0: /local/vm-db-disk-1.qcow2 (qcow2)
 drive-ide0-1-0: [not inserted]
     Removable device: not locked, tray closed


 root @ hyp-0: / local # virsh qmu-monitor-command vm-db --hmp "block_resize drive-virtio-disk0 1000G"

 root @ hyp-0: / local # qemu-img info / local / vm-db-disk-1.qcow2

 image: /local/vm-db-disk-1.qcow2
 file format: qcow2
 virtual size: 1.0T (1073741824000 bytes)
 disk size: 717G
 cluster_size: 65536
 Format specific information:
     compat: 1.1
     lazy refcounts: false
 root @ hyp-0: / local #


This is how the log from the guest looks like.
 root @ vm-db: /var/lib/postgresql/9.1/main# df -h

 Filesystem Size Used Avail Use% Mounted on
 / dev / mapper / vm - db - vg-root 730G 671G 22G 97% /
 none 4.0K 0 4.0K 0% / sys / fs / cgro 
 udev 29G 4.0K 29G 1% / dev
 tmpfs 5.8G 360K 5.8G 1% / run
 none 5.0M 0 5.0M 0% / run / lock
 none 29G 0 29G 0% / run / shm
 none 100M 0 100M 0% / run / user
 / dev / vda1 236M 95M 129M 43% / boot

 root @ vm-db: / sys / block / vda / device # parted / dev / vda

 GNU Parted 2.3
 Using / dev / vda
 Welcome to GNU Parted!  Type 'help' to view a list of commands.
 (parted) print
 Model: Virtio Block Device (virtblk)
 Disk / dev / vda: 1074GB
 Sector size (logical / physical): 512B / 512B
 Partition Table: msdos

 Number Start End Size File Type System Flags
  1 1049kB 256MB 255MB primary ext2 boot
  2,257MB 859GB 859GB extended
  5 257MB 859GB 859GB logical lvm

 (parted) resizepart 2
 End?  [859GB]?  1000GB
 (parted) print
 Model: Virtio Block Device (virtblk)
 Disk / dev / vda: 1074GB
 Sector size (logical / physical): 512B / 512B
 Partition Table: msdos

 Number Start End Size File Type System Flags
  1 1049kB 256MB 255MB primary ext2 boot
  2 257MB 1000GB 1000GB extended
  5 257MB 859GB 859GB logical lvm

 (parted) resizepart 5
 End?  [859GB]?  1000GB
 (parted) q

 root @ vm-db: / sys / block / vda / device # lvscan

 File descriptor 7 (pipe: [9143432]) leaked on lvscan invocation.  Parent PID 5423: bash
   ACTIVE '/ dev / vm-db-vg / root' [741.17 GiB] inherit
   ACTIVE '/ dev / vm-db-vg / swap_1' [58.59 GiB] inherit

 root @ vm-db: / sys / block / vda / device # lvextend / dev / vm-db-vg / root -l + 100% FREE

 File descriptor 7 (pipe: [9143432]) leaked on lvextend invocation.  Parent PID 5423: bash
   Extending logical volume root to 872.49 GiB
   Logical volume root successfully resized

 root @ vm-db: / sys / block / vda / device # resize2fs / dev / vm-db-vg / root
 resize2fs 1.42.9 (4-Feb-2014)
 Filesystem at / dev / vm-db-vg / root is mounted on /;  on-line resizing required
 old_desc_blocks = 47, new_desc_blocks = 55
 The filesystem on / dev / vm-db-vg / root is now 228718592 blocks long.

 root @ vm-db: / sys / block / vda / device # df -h
 Filesystem Size Used Avail Use% Mounted on
 / dev / mapper / vm - db - vg-root 859G 678G 140G 83% /
 none 4.0K 0 4.0K 0% / sys / fs / cgroup
 udev 29G 4.0K 29G 1% / dev
 tmpfs 5.8G 364K 5.8G 1% / run
 none 5.0M 0 5.0M 0% / run / lock
 none 29G 0 29G 0% / run / shm
 none 100M 0 100M 0% / run / user
 / dev / vda1 236M 95M 129M 43% / boot


I want to warn you that the numbers in the logs may contain inaccuracies, I restored them, cleaned them, and the guest log was compiled from 2 virtual machines, on which I successfully otresayzil / drives on the fly.
In conclusion I want to say a huge thank you to farcaller for a tip on a really necessary opportunity.

')

Source: https://habr.com/ru/post/261755/


All Articles