How to mount a disk image from the command line

disk-imagemount

I know how to mount a drive that has a corresponding device file in /dev, but I don't know how to do this for a disk image that does not represent a physical device and does not have an analogue in /dev (e.g. an ISO file or a floppy image). I know I can do this in Mac OS X by double-clicking on the disk image's icon in Finder, which will mount the drive automatically, but I would like to be able to do this from the terminal. I'm not sure if there is a general Unix way of doing this, or if this is platform-specific.

Best Answer

If it was a hard-drive image with a MBR partition table, I would fdisk the image to find the offset for the partition I need to mount.

fdisk -lu /path/disk.img

Then I would mount it passing the offset.

mount -o loop,offset=xxxx /path/disk.img /mnt/disk.img.partition

The offset value is in bytes, whereas fdisk shows a block count, so you should multiply the value from the "Begin" or "Start" column of the fdisk output by 512 (or whatever the block size is) to obtain the offset to mount at.

Related Question