Posts Tagged mount
Often, you may need to mount individual partitions of a virtual disk image. Here is a cheat sheet for doing so under Linux:
The first sector of a hard disk contains the Master Boot Record or MBR. In the case of a virtual disk image file, the first 512 bytes of the file represent the MBR.
The disk is divided into partitions, and each partition can be formatted with a different filesystem. In order to mount the filesystem, you need to locate the partition table entry, determine the first sector of the partition, and supply that to the mount command for mounting.
The partition table is located at offset 0x1be (decimal 446). To dump the first partition entry type the following command:
# od -A d -t x1 vdisk0
Locate offset 446 of the print out:
0000432 00 00 00 00 00 00 00 00 55 20 06 00 00 00 80 01
0000448 01 00 83 fe ff 0e 3f 00 00 00 10 f0 bf 00 00 00
The first partition table entry is highlighted in red above. Bytes 9,10,11 and 12 constitute the offset, in sectors, of the beginning of the partition. It is highlighted in green above. Remember that it is in Little Endian byte order, so the 32 bit number is actually 0x0000003f, i.e. 63 decimal. This is in sector count, and each sector is 512 bytes long, so the actual file offset of the beginning of the first partition in file vdisk0 is (63 * 512) i.e. 32256.
Hence, use the following command to mount the first partition of virtual disk file vdisk0
# mount -o loop,offset=32256 ./vdisk0 ./mnt
Now you can ‘cd’ into ‘./mnt’ and view and modify files in the first partition of vdisk0. Remember to umount ./mnt when you are done.