Online resize LVM, DRBD, ISCSI and QEMU Guest disk via virsh
Starting with version 0.9.4 Libvirt supports qemu monitor commands to resize block a device.
QEMU host physical storage
root@linuxha01:~# lvresize /dev/system/nuclos01_sda -L+128G
TEST resize with just a small width
root@linuxha01:~# drbdadm -- --assume-peer-has-space --size 160G resize nuclos01
root@linuxha01:~# dmesg
[1479450.593207] block drbd10: Resize while not connected was forced by the user!
[1479450.593212] block drbd10: drbd_bm_resize called with capacity == 335544320
[1479450.593266] block drbd10: resync bitmap: bits=41943040 words=655360 pages=1280
[1479450.593269] block drbd10: size = 160 GB (167772160 KB)
[1479450.724285] block drbd10: Writing the whole bitmap, size changed
[1479450.726373] block drbd10: 160 GB (41942976 bits) marked out-of-sync by on disk bit-map.
or give all space of LVM to DRBD
root@linuxha01:~# drbdadm -- --assume-peer-has-space resize nuclos01
root@linuxha01:~# dmesg -c
[1479571.950153] drbd nbv192_win: sock was reset by peer
[1479571.950172] drbd nbv192_win: peer( Secondary -> Unknown ) conn( Connected -> BrokenPipe ) pdsk( UpToDate -> DUnknown )
[1479571.950174] drbd nbv192_win: short read (expected size 16)
[1479571.950187] drbd nbv192_win: ack_receiver terminated
[1479571.950189] drbd nbv192_win: Terminating drbd_a_nbv192_w
[1479571.950287] block drbd20: new current UUID DBB73010A2598A77:21F4F4A3842E29C1:C69FD02399D80C23:C69ED02399D80C23
[1479571.989254] drbd nbv192_win: Connection closed
[1479571.989378] drbd nbv192_win: conn( BrokenPipe -> Unconnected )
[1479571.989379] drbd nbv192_win: receiver terminated
[1479571.989381] drbd nbv192_win: Restarting receiver thread
[1479571.989382] drbd nbv192_win: receiver (re)started
[1479571.989387] drbd nbv192_win: conn( Unconnected -> WFConnection )
[1479572.525242] drbd nbv192_win: Handshake successful: Agreed network protocol version 101
[1479572.525245] drbd nbv192_win: Feature flags enabled on protocol level: 0x7 TRIM THIN_RESYNC WRITE_SAME.
[1479572.525267] drbd nbv192_win: conn( WFConnection -> WFReportParams )
[1479572.525270] drbd nbv192_win: Starting ack_recv thread (from drbd_r_nbv192_w [1260])
[1479572.565211] block drbd20: drbd_sync_handshake:
[1479572.565216] block drbd20: self DBB73010A2598A77:21F4F4A3842E29C1:C69FD02399D80C23:C69ED02399D80C23 bits:0 flags:0
[1479572.565219] block drbd20: peer 21F4F4A3842E29C0:0000000000000000:C69FD02399D80C22:C69ED02399D80C23 bits:0 flags:0
[1479572.565222] block drbd20: uuid_compare()=1 by rule 70
[1479572.565229] block drbd20: peer( Unknown -> Secondary ) conn( WFReportParams -> WFBitMapS ) pdsk( DUnknown -> Consistent )
[1479572.565669] block drbd20: send bitmap stats [Bytes(packets)]: plain 0(0), RLE 23(1), total 23; compression: 100.0%
[1479572.603874] block drbd20: receive bitmap stats [Bytes(packets)]: plain 0(0), RLE 23(1), total 23; compression: 100.0%
[1479572.603880] block drbd20: helper command: /sbin/drbdadm before-resync-source minor-20
[1479572.606170] block drbd20: helper command: /sbin/drbdadm before-resync-source minor-20 exit code 0 (0x0)
[1479572.606195] block drbd20: conn( WFBitMapS -> SyncSource ) pdsk( Consistent -> Inconsistent )
[1479572.606209] block drbd20: Began resync as SyncSource (will sync 0 KB [0 bits set]).
[1479572.606260] block drbd20: updated sync UUID DBB73010A2598A77:21F5F4A3842E29C1:21F4F4A3842E29C1:C69FD02399D80C23
[1479572.631670] block drbd20: Resync done (total 1 sec; paused 0 sec; 0 K/sec)
[1479572.631676] block drbd20: updated UUIDs DBB73010A2598A77:0000000000000000:21F5F4A3842E29C1:21F4F4A3842E29C1
[1479572.631682] block drbd20: conn( SyncSource -> Connected ) pdsk( Inconsistent -> UpToDate )
[1479593.509212] block drbd10: Resize while not connected was forced by the user!
[1479593.509216] block drbd10: drbd_bm_resize called with capacity == 536854456
[1479593.509723] block drbd10: resync bitmap: bits=67106807 words=1048544 pages=2048
[1479593.509726] block drbd10: size = 256 GB (268427228 KB)
[1479593.633186] block drbd10: Writing the whole bitmap, size changed
[1479593.651619] block drbd10: bitmap WRITE of 768 pages took 16 ms
[1479593.651623] block drbd10: 256 GB (67106743 bits) marked out-of-sync by on disk bit-map.
virsh # qemu-monitor-command --domain nuclos01test --hmp "block_resize drive-virtio-disk0 256G"
Cannot grow device files
virsh # qemu-monitor-command --domain nuclos01test --hmp "block_resize drive-virtio-disk0 255G"
QEMU host system using libvirtd
virsh # qemu-monitor-command --domain nuclos01test --hmp "info block"
drive-virtio-disk0 (#block135): /dev/drbd/by-res/nuclos01/0 (raw)
Attached to: /machine/peripheral/virtio-disk0/virtio-backend
Cache mode: writeback, direct
virsh # qemu-monitor-command --domain nuclos01test --hmp "info block"
drive-virtio-disk0 (#block173): /dev/disk/by-path/ip-linuxha01:3260-iscsi-iqn.2019-02.at.marcher:nuclos01-lun-0 (raw)
Attached to: /machine/peripheral/virtio-disk0/virtio-backend
Cache mode: writeback, direct
virsh # qemu-monitor-command --domain nuclos01test --hmp "block_resize drive-virtio-disk0 255G"
QEMU guest system
After test resize
root@nuclos01_test:~# dmesg
[ 139.582822] virtio_blk virtio1: new size: 335544320 512-byte logical blocks (172 GB/160 GiB)
[ 139.582829] vda: detected capacity change from 161061273600 to 171798691840
After resize
root@nuclos01_test:~# dmesg
[10455.504749] virtio_blk virtio1: new size: 536854456 512-byte logical blocks (275 GB/256 GiB)
[10455.504759] vda: detected capacity change from 161061273600 to 274869481472
root@nuclos01_test:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 256G 0 disk
├─vda1 252:1 0 16G 0 part [SWAP]
└─vda2 252:2 0 134G 0 part /
root@nuclos01_test:~# parted /dev/vda
GNU Parted 3.2
/dev/vda wird verwendet
Willkommen zu GNU Parted! Rufen Sie »help« auf, um eine Liste der verfügbaren Befehle zu erhalten.
(parted) print
Modell: Virtio Blockorientiertes Gerät (virtblk)
Festplatte /dev/vda: 275GB
Sektorgröße (logisch/physisch): 512B/512B
Partitionstabelle: msdos
Disk-Flags:
Nummer Anfang Ende Größe Typ Dateisystem Flags
1 1049kB 17,2GB 17,2GB primary linux-swap(v1)
2 17,2GB 161GB 144GB primary ext4
(parted) resizepart 2
Warnung: Die Partition /dev/vda2 wird gerade verwendet. Sind Sie sicher, dass Sie fortsetzen wollen?
Ja/Yes/Nein/No? J
Ende? [161GB]? -1s
(parted) print
Modell: Virtio Blockorientiertes Gerät (virtblk)
Festplatte /dev/vda: 275GB
Sektorgröße (logisch/physisch): 512B/512B
Partitionstabelle: msdos
Disk-Flags:
Nummer Anfang Ende Größe Typ Dateisystem Flags
1 1049kB 17,2GB 17,2GB primary linux-swap(v1)
2 17,2GB 275GB 258GB primary ext4
(parted) quit
Informationen: Möglicherweise müssen Sie /etc/fstab anpassen.
root@nuclos01_test:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 256G 0 disk
├─vda1 252:1 0 16G 0 part [SWAP]
└─vda2 252:2 0 240G 0 part /
root@nuclos01_test:~# df -h /
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/vda2 132G 67G 60G 53% /
root@nuclos01_test:~# resize2fs /dev/vda2
resize2fs 1.44.1 (24-Mar-2018)
Dateisystem bei /dev/vda2 ist auf / eingehängt; Online-Größenänderung ist erforderlich
old_desc_blocks = 9, new_desc_blocks = 15
Das Dateisystem auf /dev/vda2 is nun 62912247 (4k) Blöcke lang.
root@nuclos01_test:~# dmesg
[61969.988746] EXT4-fs (vda2): resizing filesystem from 35127040 to 62912247 blocks
[61970.032104] EXT4-fs (vda2): resized filesystem to 62912247
root@nuclos01_test:~# df -h /
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/vda2 237G 67G 160G 30% /
Too slow? Add LVM SSD cache...
root@linuxha01:~# lvconvert --type cache --cachepool system/cache0 --cachemode writeback system/nuclos01_sda
Do you want wipe existing metadata of cache pool system/cache0? [y/n]: y
Logical volume system/nuclos01_sda is now cached.