mount windows disk image in linux

I was recently converting a Windows installation from a physical desktop to a virtual machine. Because the installation was an OEM installation the P2V conversion failed the “hardware” check and the target VM was unregistered. The only way to fix was to do a repair install changing the installation from an OEM to a Retail version of Windows. This needed to be done on the physical source desktop. There’s no way I was going to attempt this without a total backup of the system. I could have just copied important files, but I decided a disk clone was more appropriate. I booted off of a Debian rescue cd, mounted a NFS share, and dd’d a copy of the entire drive to a flat file.

# mkdir /mnt/nfsserver/diskclone
# mount nfsserver:/vol/diskclone /mnt/nfsserver/diskclone
# cd /mnt/nfsserver/diskclone
#
# dd if=/dev/sda of=desktop.img
156250000+0 records in
156250000+0 records out
80000000000 bytes (80 GB) copied, 7079.64601 seconds, 11.3 MB/s
#
# ls -l
total 78278496
-rw-r--r-- 1 root root 80000000000 2013-05-20 15:47 desktop.img

I then needed to mount the image and take a look at the contents. A flat disk image file is just a block for block copy of the actual disk, so the first step is to look at the partition table listed in sectors and find the offset. The offset will tell mount where the beginning of the file system is.

# losetup /dev/loop0 desktop.img
#
# fdisk -l -u  /dev/loop0

Disk /dev/loop0: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders, total 156250000 sectors
Units = sectors of 1 * 512 = 512 bytes 

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1   *          63   156232124    78116031    7  HPFS/NTFS
#
#

Find the offset by multiplying the 63 (start sector) by 512 bytes ( 63*512 ) and the offset is 32256. Now we can tell mount where the start is.

# mkdir /mnt/diskimage
# mount -t ntfs -o offset=32256,ro desktop.img /mnt/diskimage
#

I mounted readonly so that we don’t mess anything up. You may need to install ntfsprogs to be able to read an NTFS file system (apt-get install ntfsprogs) if you don’t have it installed already

mount iso file in linux

I had to copy the contents of a .iso file. It’s easy to mount it and see what’s in the iso.


# mkdir /mnt/iso
# mount -o loop VMware-VMvisor-Installer-5.1.0-799733.x86_64.iso /mnt/iso
# cd /mnt/disk
# ls
a.b00         ata_pata.v05  boot.cfg      ima_qla4.v00  isolinux.bin  misc_dri.v00  net_e100.v01  net_r816.v00  ohci_usb.v00  sata_sat.v02  scsi_bnx.v00  scsi_meg.v01  scsi_qla.v01  upgrade                  xlibs.v00
ata_pata.v00  ata_pata.v06  chardevs.b00  imgdb.tgz     isolinux.cfg  net_be2n.v00  net_enic.v00  net_r816.v01  safeboot.c32  sata_sat.v03  scsi_fni.v00  scsi_meg.v02  scsi_rst.v00  user.b00                 xorg.v00
ata_pata.v01  ata_pata.v07  efi           imgpayld.tgz  k.b00         net_bnx2.v00  net_forc.v00  net_s2io.v00  sata_ahc.v00  sata_sat.v04  scsi_hps.v00  scsi_mpt.v00  s.v00         useropts.gz
ata_pata.v02  b.b00         efiboot.img   ipmi_ipm.v00  mboot.c32     net_bnx2.v01  net_igb.v00   net_sky2.v00  sata_ata.v00  scsi_aac.v00  scsi_ips.v00  scsi_mpt.v01  tboot.b00     vmware-esx-base-osl.txt
ata_pata.v03  block_cc.v00  ehci_ehc.v00  ipmi_ipm.v01  menu.c32      net_cnic.v00  net_ixgb.v00  net_tg3.v00   sata_sat.v00  scsi_adp.v00  scsi_lpf.v00  scsi_mpt.v02  tools.t00     vmware-esx-base-readme
ata_pata.v04  boot.cat      esx_dvfi.v00  ipmi_ipm.v02  misc_cni.v00  net_e100.v00  net_nx_n.v00  net_vmxn.v00  sata_sat.v01  scsi_aic.v00  scsi_meg.v00  scsi_qla.v00  uhci_usb.v00  weaselin.t00
#

Now the contents of /mnt/disk appear as if you had burned the .iso and put it in the CD drive.