Several ways to mount a harddisk/usb disk image

I've got an image of a USB disk that was created with the command dd. How can we mount it and access files? The file is named smosimg

Method 1: fdisk and bash

# fdisk -l smosimg
 
Disk smosimg: 1993 MB, 1993342976 bytes, 3893248 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: 0x000336e0
 
  Device Boot      Start         End      Blocks   Id  System
smosimg1   *        2048     1230847      614400   83  Linux
smosimg2         1230848     3893247     1331200   83  Linux

I want to mount the second partition that starts at block 1230848. The block size is 512 bytes, so we multiply 1230848 by 512:

mkdir target
mount -o loop,offset=$((1230848*512)) smosimg target

Method 2: kpartx

mkdir target
kpartx -a smosimg
mount /dev/mapper/loop0p2 target -o loop
kpartx -d smosimg

Method 3: losetup

mkdir target
losetup --partscan --find --show disk.img
mount /dev/loop0p2 target
losetup -d /dev/loop0

I've personally tested all three methods, and on my Fedora 18 machine, they all work.

© GeekLabInfo Several ways to mount a harddisk/usb disk image is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
Categories: IT

Leave a Reply