Linux Mount partitions in raw file with losetup
id : mrs1c698hh
category : computer
blog : unixlinux
created : 02/28/11 - 10:26:23

  • If you have a wmdk file, you need to convert it to have a raw image. You can use qemu convert.
  • Convert your vmdk file :
# qemu-img convert image.vmdk -O raw image.raw

  • You'll need losetup. Install it.
# yum install util-linux

  • Run losetup :
# losetup /dev/loop0 image.raw

  • Run kpartx to discover new partitions :
# kpartx -av /dev/loop0
add map loop0p1 : 0 14651217 linear /dev/loop0 63
add map loop0p2 : 0 3903795 linear /dev/loop0 14651280
add map loop0p3 : 0 1911735 linear /dev/loop0 18555075

  • loop0p1 is /boot, loop0p2 is /home, loop0p3 is /
  • You can now mount your new partitions :
# mount /dev/mapper/loop0p2 /mnt
# ls /mnt
lost+found  user
# umount /mnt

# mount /dev/mapper/loop0p3 /mnt
# ls /mnt
bin   cdrom  etc   initrd      initrd.img.old  lost+found  mnt  proc  sbin  sys  usr  vmlinuz
boot  dev    home  initrd.img  lib             media       opt  root  srv   tmp  var  vmlinuz.old