Saturday 20 September 2014

Mount a disk image file created with dd on Linux

What:

Ubuntu Linux Operating System

Problem:

You have a disk image created with dd, but you can't mount it.
mount disk.img /mnt -o loop
mount: you must specify the filesystem type

Solution:

 

Option 1

 

# fdisk -l disk.img
Disk disk.img: 15.9 GB, 15931539456 bytes
255 heads, 63 sectors/track, 1936 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000981cb

   Device Boot      Start         End      Blocks   Id  System
disk.img1            8192      122879       57344    c  W95 FAT32 (LBA)
disk.img2          122880    31116287    15496704   83  Linux
Partition with data is a Linux partition, which starts on sector 122880, you can use mount with "offset" in bytes to mount that partition. As per above 1 sector is 512 bytes, so 122880 x 512 = 62914560  bytes, which is our offset.
# mount -o ro,loop,offset=62914560 disk.img /mnt

 

Option 2

 

# apt-get install kpartx
Get an overview of partitions:
# kpartx -l disk.img
Create a loop devices :
# kpartx -a disk.img
Mount your parition:
# mount -o ro,loop /dev/mapper/loop0p2 /mnt
 When you finished unmount partitions and disconnect the mapper devices:
# kpartx -d disk.img

No comments:

Post a Comment