- if [ -f /etc/centos-release ]; then
- # CentOS, mount image using guestmount.
- # (needs libguestfs-tools installed)
- export LIBGUESTFS_BACKEND=direct
- guestmount -a $imgfile -i --rw $mountdir
- else
- # mount image using qemu-nbd
- modprobe nbd max_part=16
- qemu-nbd -c /dev/nbd0 $imgfile
- partprobe /dev/nbd0
-
- mount /dev/nbd0p1 $mountdir
- fi
+
+ loopdevice=$(kpartx -l $raw_imgfile | head -1 | cut -f1 -d ' ')
+
+ kpartx -av $raw_imgfile
+
+ # for trouble shooting
+ sleep 2
+ dmsetup ls
+ parted -l /dev/${loopdevice:0:5} || true
+ mount /dev/mapper/$loopdevice $mountdir
+ mount -t proc none $mountdir/proc
+