Can't mount disk image
Solution 1
How to mount a partition in a full disk image that contains a msdos partition table.
Tools:
fdisk
mount
- calculator
Get the partition layout of the image.
sudo fdisk -l -u=sectors /work/loop_test/disk_image.img
Example output:
Disk /work/loop_test/disk_image.img: 29 MB, 29629952 bytes
255 heads, 63 sectors/track, 3 cylinders, total 57871 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: 0x0009d7e5
Device Boot Start End Blocks Id System
/work/loop_test/disk_image.img1 2048 18431 8192 83 Linux
/work/loop_test/disk_image.img2 18432 57343 19456 7 HPFS/NTFS/exFAT
Calculate the offset from the start of the image to the partition start. In this case the ntfs partition.
formula:
Sector size * Start = Offset
512 * 18432 = 9437184
Mount the image, passing the offset for the desired partition.
In this example the ntfs partition.
sudo mount -o loop,offset=9437184 /work/loop_test/disk_image.img /mnt/ntfs_partition
Solution 2
Running losetup -P
will automatically detect partitions and create appropriate /dev/loop0pX
devices for you. No need to perform the calculations manually.
Related videos on Youtube
dangeroushobo
Updated on September 18, 2022Comments
-
dangeroushobo almost 2 years
I have a disk image file I'm trying to mount locally using a loop device. Using parted I can see the image has two partitions, however, I'm not able to mount the first partition and
losetup
thinks the second partition doesn't exist. Anyone know how I can mount the second partition?/m/sf_VMShare ❯❯❯ sudo losetup /dev/loop0 ./imm_image-2017-05-28.img /m/sf_VMShare ❯❯❯ sudo losetup -a /dev/loop0: [0023]:99 (/media/sf_VMShare/imm_image-2017-05-28.img) /m/sf_VMShare ❯❯❯ sudo parted /dev/loop0 print Model: Loopback device (loop) Disk /dev/loop0: 1206MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 10.5MB 360MB 349MB primary ext4 2 361MB 1205MB 844MB primary ext4 /m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p2 /tmp/vdisk mount: special device /dev/loop0p2 does not exist /m/sf_VMShare ❯❯❯ sudo mount -t ext4 /dev/loop0p1 /tmp/vdisk mount: wrong fs type, bad option, bad superblock on /dev/loop0p1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so /m/sf_VMShare ❯❯❯ mount | grep /tmp/vdisk /m/sf_VMShare ❯❯❯ /m/sf_VMShare ❯❯❯ ls /dev/loop* /dev/loop0 /dev/loop1 /dev/loop3 /dev/loop5 /dev/loop7 /dev/loop0p1 /dev/loop2 /dev/loop4 /dev/loop6 /dev/loop-control /m/sf_VMShare ❯❯❯ lsblk -f NAME FSTYPE LABEL MOUNTPOINT sda ├─sda1 / ├─sda2 └─sda5 [SWAP] sdb └─sdb1 /home/foo/workspace sr0 loop0 └─loop0p1
-
John about 7 yearsWhat does
ls /dev/loop*
show? -
Mio Rin about 7 yearsWhat is the output of
lsblk -f
?
-
-
Murmel over 5 yearsInstead of calculating the offset by yourself, you could even use bash's arithemtic evaluation:
sudo mount -o loop,offset=$((512*18432)) ...