Pages

KVM can use either an entire partition to simulate a disk for the guest operating system, or a single file. By default the file type used is a "raw" file compatible with other virtualization systems, like Xen.

In order to mount the image file of the guest OS we need to first map a loop device to it.

The command losetup is used to associate files
with loop devices. First check what the next available loopback device
is with the -f argument which is used to find the next available device:

Within a single image file there may be multiple partitions (e.g. /, /boot, etc.). The partition table can be read from the new (loop) device and individual devices for each partition created. This is done with the kpartx command (it creates map devices from device partition tables):