qemu-img
Manage virtual machine disk images
TLDR
Create disk image with a specific size (in gigabytes)
Show information about a disk image
Increase or decrease image size
Dump the allocation state of every sector of the specified disk image
Convert a VMware .vmdk disk image to a KVM .qcow2 disk image
SYNOPSIS
qemu-img command [options] [image format] filename [size]
PARAMETERS
create
Creates a new disk image.
-f fmt
Specifies the image format. Supported formats include raw, qcow2, vmdk, vdi, etc.
filename
The path and name of the disk image to create or modify.
size
The size of the disk image to create. Use suffixes like K, M, G, T for kilobytes, megabytes, gigabytes, and terabytes respectively.
convert
Converts a disk image from one format to another.
-O output_fmt
Specifies the output image format for conversion.
info
Displays information about a disk image.
resize
Resizes a disk image.
+size
The amount to increase the image size by.
snapshot
Manages snapshots of a disk image.
-c
Create a new snapshot.
-l
List existing snapshots.
-d
Delete a snapshot.
-a
Apply a snapshot.
commit
Commit changes from a snapshot to the base image.
check
Check a disk image for errors.
-r
Reclaim unused space.
DESCRIPTION
qemu-img
is a command-line utility included with QEMU that allows you to create, convert, and manage virtual disk images. It supports a variety of image formats including raw, qcow2, vmdk, and vdi. You can use qemu-img
to create new images, resize existing images, convert between formats, take snapshots, and perform other disk image manipulation tasks. This is crucial for virtualization as disk images represent the storage for virtual machines. Understanding qemu-img is critical to efficiently manage virtual machine storage. It's used extensively for creating virtual hard drives. It's an extremely versatile tool useful for managing virtual machine disk images for QEMU based virtual machines.
CAVEATS
Resizing a disk image doesn't automatically resize the filesystem inside the image. You may need to use guest OS tools to resize the filesystem after resizing the image.
Some formats may support features like compression or encryption; explore format-specific options for these.
EXAMPLES
Create a 10GB qcow2 image: qemu-img create -f qcow2 mydisk.qcow2 10G
Convert a raw image to qcow2: qemu-img convert -O qcow2 old.raw new.qcow2
Get info about a qcow2 image: qemu-img info mydisk.qcow2
HISTORY
qemu-img
was developed as part of the QEMU project, initially released in 2003.
Its evolution mirrors that of QEMU itself, with continuous improvements and support for newer disk image formats and features.
Over time, it became an essential tool for managing virtual machine storage, alongside the main QEMU emulator.
SEE ALSO
qemu-system-x86_64(1), virt-manager(1)