Home / Linux Admin /
KVM Disk Image Management
Convert Disk Image Formats
- With qemu installed, this works. In this example, converting from a VDI VirtualBox format to Qcow2. Note that that is -O (capital O) not -0 (zero)
qemu-img convert -f vdi -O qcow2 ubuntu.vdi ubuntu.qcow2
Mount Disk Image in Linux
This is might be specific to qcow2 image files.
DO NOT mount the disk image in read/write mode while the VM is running!
- Install libguestfs-tools
apt install libguestfs-tools
- Create a mount point:
- Mount it (replace device with anything to get a list of what devices are available):
guestmount -a /path/to/qcow2/image -m <device> /mnt/guestIMG
- note that this does NOT require super user permissions if your user has full access to the mount point and image
- use
guestmount -a /path/to/qcow2/image -m <device> --ro /mnt/guestIMG to make it read only (which would allow you to mount while the VM is running)
- Unmount it when finished:
- resource
Resize Qcow2 Disk Image
qemu-img resize diskImage.qcow2 +5G
- after that, launch the VM and resize partitions
Shrink Qcow2 Disk Image
virt-sparsify bloatedDiskImage.ext outputShrunkDiskImage.ext
- this appears to support
qcow2, vdi, and raw (img I think?)
- Conjecture - I think if you have a
qcow2 image you can use --in-place to avoid having to create a second image
- more info
- Alternatives
- 1 look into virt-sparsify
- 2 - less efficient, but more stable?
- 3 - alt zeroing method
- Be sure to test the resulting image before deleting the original
this document last modified: May 15 2018 01:00
popout article
permalink
Home / Linux Admin /