User Tools

Site Tools


tech:server:linux:virtualization:kvm-qemu:libvirt:libguestfs:libguestfs

libguestfs

Guest Virtual Machine Image Management.

Resize Guest Image Size

qemu-img resize nextcloud1.example.com.qcow2 40G
qemu-img resize mx1.example.com.qcow2 40G
root@hotaru:/var/lib/libvirt/images# cp -a nextcloud1.example.com.qcow2 nextcloud1.example.com.qcow2.202001121448
root@hotaru:/var/lib/libvirt/images# cp -a mx1.example.com.qcow2{,.202001121448}
root@hotaru:/var/lib/libvirt/images# qemu-img resize nextcloud1.example.com.qcow2 20G
qemu-img: Could not open 'nextcloud1.example.com.qcow2': Could not open 'nextcloud1.example.com.qcow2': No such file or directory
root@hotaru:/var/lib/libvirt/images# qemu-img resize nextcloud1.example.com.qcow2 20G
qemu-img: Can't resize an image which has snapshots
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -l nextcloud1.example.com.qcow2
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
2         prepare-ncadmin-user      0 2020-01-12 09:12:43   00:00:00.000
3         nextcloud-installed       0 2020-01-12 11:32:21   00:00:00.000
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -l mx1.example.com.qcow2
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         virt-sysprep-up-to-date      0 2020-01-07 07:55:49   00:00:00.000
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -d 1 mx1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -d 2 nextcloud1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -d 3 nextcloud1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -l mx1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# qemu-img snapshot -l nextcloud1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# qemu-img resize nextcloud1.example.com.qcow2 40G
Image resized.
root@hotaru:/var/lib/libvirt/images# qemu-img resize mx1.example.com.qcow2 40G
Image resized.
virt-filesystems --long -h --all -a nextcloud1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# mv mx1.example.com.qcow2 mx1.example.com.qcow2.old
root@hotaru:/var/lib/libvirt/images# mv nextcloud1.example.com.qcow2 nextcloud1.example.com.qcow2.old
virt-filesystems --long -h --all -a mx1.example.com.qcow2.old
virt-filesystems --long -h --all -a nextcloud1.example.com.qcow2.old
root@hotaru:/var/lib/libvirt/images# virt-filesystems --long -h --all -a mx1.example.com.qcow2.old
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    8.0G  -
/dev/sda1  partition   -     -      83   8.0G  /dev/sda
/dev/sda   device      -     -      -    40G   -
root@hotaru:/var/lib/libvirt/images# virt-filesystems --long -h --all -a nextcloud1.example.com.qcow2.old
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    8.0G  -
/dev/sda1  partition   -     -      83   8.0G  /dev/sda
/dev/sda   device      -     -      -    40G   -
qemu-img create -f qcow2 mx1.example.com.qcow2 40G
qemu-img create -f qcow2 nextcloud1.example.com.qcow2 40G
root@hotaru:/var/lib/libvirt/images# qemu-img create -f qcow2 mx1.example.com.qcow2 40G
Formatting 'mx1.example.com.qcow2', fmt=qcow2 size=42949672960 cluster_size=65536 lazy_refcounts=off refcount_bits=16
root@hotaru:/var/lib/libvirt/images# qemu-img create -f qcow2 nextcloud1.example.com.qcow2 40G
Formatting 'nextcloud1.example.com.qcow2', fmt=qcow2 size=42949672960 cluster_size=65536 lazy_refcounts=off refcount_bits=16
virt-resize --expand /dev/sda1 mx1.example.com.qcow2.old mx1.example.com.qcow2
virt-resize --expand /dev/sda1 nextcloud1.example.com.qcow2.old nextcloud1.example.com.qcow2
root@hotaru:/var/lib/libvirt/images# virt-resize --expand /dev/sda1 mx1.example.com.qcow2.old mx1.example.com.qcow2
[   0.0] Examining mx1.example.com.qcow2.old
**********

Summary of changes:

/dev/sda1: This partition will be resized from 8.0G to 40.0G.  The
filesystem ext4 on /dev/sda1 will be expanded using the 'resize2fs' method.

**********
[   2.2] Setting up initial partition table on mx1.example.com.qcow2
[   2.8] Copying /dev/sda1
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  20.7] Expanding /dev/sda1 using the 'resize2fs' method

Resize operation completed with no errors.  Before deleting the old disk,
carefully check that the resized disk boots and works correctly.
root@hotaru:/var/lib/libvirt/images# virt-resize --expand /dev/sda1 nextcloud1.example.com.qcow2.old nextcloud1.example.com.qcow2
[   0.0] Examining nextcloud1.example.com.qcow2.old
**********

Summary of changes:

/dev/sda1: This partition will be resized from 8.0G to 40.0G.  The
filesystem ext4 on /dev/sda1 will be expanded using the 'resize2fs' method.

**********
[   2.2] Setting up initial partition table on nextcloud1.example.com.qcow2
[   2.8] Copying /dev/sda1
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  50.5] Expanding /dev/sda1 using the 'resize2fs' method

Resize operation completed with no errors.  Before deleting the old disk,
carefully check that the resized disk boots and works correctly.
root@hotaru:/var/lib/libvirt/images# ls -lh
total 66G
-rw------- 1 libvirt-qemu kvm   21G Jan 12 15:15 gitlab1.example.com.qcow2
-rw-r--r-- 1 root         root 3.5G Jan 12 15:14 mx1.example.com.qcow2
-rw------- 1 root         root 4.0G Jan 12 14:37 mx1.example.com.qcow2.202001121448
-rw------- 1 root         root 4.0G Jan 12 15:01 mx1.example.com.qcow2.old
-rw-r--r-- 1 root         root 7.6G Jan 12 15:15 nextcloud1.example.com.qcow2
-rw------- 1 root         root 8.8G Jan 12 14:36 nextcloud1.example.com.qcow2.202001121448
-rw------- 1 root         root 8.8G Jan 12 15:02 nextcloud1.example.com.qcow2.old
-rw------- 1 root         root 8.1G Jan 12 08:06 template.qcow2
-rw------- 1 libvirt-qemu kvm   20G Jan 12 15:15 vol-dokuwiki.img
You have mail in /var/mail/root
root@hotaru:/var/lib/libvirt/images# virt-filesystems --long -h --all -a mx1.example.com.qcow2
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    40G   -
/dev/sda1  partition   -     -      83   40G   /dev/sda
/dev/sda   device      -     -      -    40G   -
root@hotaru:/var/lib/libvirt/images# virt-filesystems --long -h --all -a nextcloud1.example.com.qcow2
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    40G   -
/dev/sda1  partition   -     -      83   40G   /dev/sda
/dev/sda   device      -     -      -    40G   -
tech/server/linux/virtualization/kvm-qemu/libvirt/libguestfs/libguestfs.txt · Last modified: 2020/01/12 15:22 by wnoguchi