Mount a KVM image (.img) file directly
Posted: Tue Aug 13, 2013 12:52 am
This HowTo describes the steps necessary to mount a GNU/Linux virtual machine image file created by "virt-install" and used by KVM.
1) Connect the image as "loop" device:
returns:
Check the next available/free loop device:
For example, on a Ubuntu live distro it will return
Then assign the image to that loop device:
2) Map the partitions which are inside the image:
returns:
Voila!
Unmounting is basically the same in reverse order with "delete" arguments:
Thanks to Kirk Dougland's article "Mounting a KVM Disk Image" and David Champion's page Mounting a KVM disk image without KVM.
1) Connect the image as "loop" device:
Code: Select all
$ losetup <image_filename.img>
If this doesn't work (for whatever reason), you can do it manually.Loop device is /dev/loop0
Check the next available/free loop device:
Code: Select all
$ losetup -f
(Because loop0 and loop1 are taken by the live distro)./dev/loop2
Then assign the image to that loop device:
Code: Select all
$ losetup /dev/loop2 <image_filename.img>
Code: Select all
$ sudo kpartx -av /dev/loop0
3) Mount the desired partition(s):add map loop0p1 (253:0): 0 20967424 linear /dev/loop0 2048
Code: Select all
$ mount /dev/mapper/loop0p1 <mountpoint>
Unmounting is basically the same in reverse order with "delete" arguments:
Code: Select all
$ unmount /mnt
$ kpartx -dv /dev/loop0
$ losetup -d /dev/loop0