# create image file
qemu-img create -f qcow2 /var/lib/libvirt/images/vm01.qcow2 25G
# create raw disk
chown libvirt-qemu.kvm /var/lib/libvirt/images/vm01.qcow2
chmod 600 /var/lib/libvirt/images/vm01.qcow2
# shrink qcow image
qemu-img convert -O qcow2 image01.in.qcow image.01.out.qcow
# shrink qcow image with compression
qemu-img convert -O qcow2 -c IN.qcow OUT.qcow
# convert qcow2 to raw
qemu-img convert <imgage_in>.qcow2 <imgage_out>.raw
# convert
qemu-img convert -O qcow2 ubuntu-16.04-server-cloudimg-amd64-disk1.img ubuntu-16.04-server-cloudimg-amd64-disk1.qcow2
# create image
qemu-img create disk.img -f qcow2 4G
qemu-img create -f qcow2 /storage/vm1/disc1.qcow2 16G
qemu-img info /storage/vm1/disc1.qcow2
# fsck from qcow2 file
modprobe nbd max_part=8
qemu-nbd --connect=/dev/nbd0 /var/lib/libvirt/images/vm1.qcow2
fdisk -l /dev/nbd0
fsck /dev/nbd0p1
mount /dev/nbd0p1 /mnt
umount /mnt
qemu-nbd --disconnect /dev/nbd0
# make a diff qcow image
qemu-img create -f qcow2 -b img/ubuntu-16.04-server-cloudimg-amd64-disk1.img vm1.qcow2
cat > my-user-data <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_authorized_keys:
- ssh-rsa AAAAB3Nz...necGw== foo@example.com
ssh_pwauth: True
runcmd:
- date > /tmp/debug
EOF
cloud-localds my-seed.img my-user-data
# copy image
qemu-img convert -O qcow2 /var/lib/libvirt/images/img/ubuntu-16.04-server-cloudimg-amd64-disk1.img /var/lib/libvirt/images/vm1.qcow2
# resize
qemu-img resize /var/lib/libvirt/images/www.exmaple.com_1.qcow2 100G
qemu-img info /var/lib/libvirt/images/www.exmaple.com_1.qcow2
# get actual disk size
du -sh /var/lib/libvirt/images/*.qcow2
Links
https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.ldva/ldva_r_qemu-imgCommand.html