QEMU-KVM Mount Raw Image

  1. Shut down the VM using the file

  2. Mount the image to a loop device using kpartx
    kpartx -av /path/to/img/file

  3. It should give you a list of the partitions. They will be created in the /dev/mapper directory with the names loop0p1, loop0p2, loop0p3, etc. for every partition in the image.

  4. Mount the partition
    mount /dev/mapper/loop0p1 /mnt

  5. Make the necessary changes

  6. Unmount
    umount /mnt

  7. Delete the loop device
    kpartx -dv /dev/loop0

  8. Start the VM back up