LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Trouble mounting dd image file. (https://www.linuxquestions.org/questions/linux-general-1/trouble-mounting-dd-image-file-644362/)

mpmackenna 05-23-2008 03:20 PM

Trouble mounting dd image file.
 
I created an image of a Windows PC using the dd command. I want to mount the image in SuSE 10.3. Whenever I issue the command
Code:

mount -o loop file.name /mnt/dir
it says file type must be specified. When I attempt to specify file type there are no options for fat32 or ntfs (I am pretty sure it was a fat32 system). I tried using vfat by using the command
Code:

mount -t vfat -o loop file.name /mnt/dir
but I get the following error.
Code:

mikem-mininote:/home/mike # mount -t vfat -o loop dianer /mnt/diane
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      missing codepage or helper program, or other error
      In some cases useful info is found in syslog - try
      dmesg | tail  or so

mikem-mininote:/home/mike # dmesg | tail
VFS: Can't find a valid FAT filesystem on dev loop0.
NTFS driver 2.1.28 [Flags: R/W MODULE].
NTFS-fs warning (device loop0): is_boot_sector_ntfs(): Invalid boot sector checksum.
NTFS-fs error (device loop0): read_ntfs_boot_sector(): Primary boot sector is invalid.
NTFS-fs error (device loop0): read_ntfs_boot_sector(): Mount option errors=recover not used. Aborting without trying to recover.
NTFS-fs error (device loop0): ntfs_fill_super(): Not an NTFS volume.
FAT: invalid media value (0xb9)
VFS: Can't find a valid FAT filesystem on dev loop0.
FAT: invalid media value (0xb9)
VFS: Can't find a valid FAT filesystem on dev loop0.
mikem-mininote:/home/mike #

Can anyone tell me how to resolve this issue? Any help is greatly appreciated! Thanks so much. Mike

jschiwal 05-23-2008 03:28 PM

Use vfat as the filesystem for fat32 filesystems. Did you backup a partition ( e.g. /dev/sda1 ) or the entire drive (e.g. /dev/sda ). You may need to use losetup with an offset so the device starts at the correct place.

Look at the output of "file -s <imagefile>". It will tell you what is on the file if it can.

mpmackenna 05-23-2008 03:50 PM

Quote:

Originally Posted by jschiwal (Post 3162799)
Use vfat as the filesystem for fat32 filesystems. Did you backup a partition ( e.g. /dev/sda1 ) or the entire drive (e.g. /dev/sda ). You may need to use losetup with an offset so the device starts at the correct place.

Look at the output of "file -s <imagefile>". It will tell you what is on the file if it can.

I did the whole drive. My command was something to the matter of fact of
Code:

dd bs=16m if=/dev/sda | bzip2 -z | dd bs=16m of=/mnt/sdb2/dianer.bz2
I successfully decompressed the file so now it is just dianer, and I am attempting the mount of that image file.
Here is the results of the file command.
Code:

mikem-mininote:/home/mike # file -s dianer
dianer: x86 boot sector, Microsoft Windows XP MBR, Serial 0xc766c766
mikem-mininote:/home/mike #

I am confused about how I would set the offset for this image file with the losetup command. I issue a command previous to mount like
Code:

losetup -o 512
?

Then issue the command
Code:

mount -t vfat filename /mnt/dir
?

Thanks so much for the help!
Mike

jschiwal 05-24-2008 07:58 AM

You need to include the loop-device or -f option and include the image filename when using losetup. Be sure to read the info page. Another thing is that the first partition begins on cylinder 1 and not sector 1. So your offset is probably wrong.

Here I tried a simple experiment. I used fdisk to list the partition table. I used the -u option so that the offsets are listed in 512 byte sectors. Then I used dd to cut out a small part of the partition and save it as a file, and then used the "file" command to examine that file.
Code:

Disk /dev/sda: 100.0 GB, 100030242816 bytes
255 heads, 63 sectors/track, 12161 cylinders, total 195371568 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x94e494e4

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          63    60818636    30409287    7  HPFS/NTFS
/dev/sda2        60822090    63970829    1574370  82  Linux swap / Solaris
/dev/sda3        63970830  195366464    65697817+  f  W95 Ext'd (LBA)
/dev/sda5        63970893    74461274    5245191  83  Linux
/dev/sda6        74461338  195366464    60452563+  83  Linux
jschiwal@hpamd64:~> sudo dd if=/dev/sda of=test.img skip=63 bs=512 count=4096
4096+0 records in
4096+0 records out
2097152 bytes (2.1 MB) copied, 0.0675431 s, 31.0 MB/s
jschiwal@hpamd64:~> file -s test.img
test.img: x86 boot sector, code offset 0x52, OEM-ID "NTFS    ", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 255, hidden sectors 63, dos < 4.0 BootSector (0x80)

I prefer using fdisk with the -u option and setting the block size of dd (bs=512) to 512 bytes to match the "-u" fdisk option. It is easier to match the offsets in the different commands this way, and 512 is the lowest common denominator for various utilities dealing with block sizes.

Here is another experiment more applicable to your situation. I copied a portion of /dev/sda to a file. Then I used losetup. Then I used file to examine the loop device.
Code:

sudo dd if=/dev/sda of=test.img  bs=512 count=280000
280000+0 records in
280000+0 records out
143360000 bytes (143 MB) copied, 10.1309 s, 14.2 MB/s
jschiwal@hpamd64:~> file test.img
test.img: x86 boot sector, LInux i386 boot LOader; partition 2: ID=0x82, starthead 254, startsector 60822090, 3148740 sectors; partition 3: ID=0xf, starthead 254, startsector 63970830, 131395635 sectors, code offset 0x48
jschiwal@hpamd64:~> sudo /sbin/losetup -f -o $((63*512)) test.img
jschiwal@hpamd64:~> sudo /sbin/losetup -a
/dev/loop0: [0805]:48001 (/suse/openSUSE-10.3-GM-DVD-x86_64.iso)
/dev/loop1: [0806]:7018459 (test.img), offset 32256
jschiwal@hpamd64:~> sudo file -s /dev/loop1
/dev/loop1: x86 boot sector, code offset 0x52, OEM-ID "NTFS    ", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 255, hidden sectors 63, dos < 4.0 BootSector (0x80)

If I had copied the entire device using dd, then I should be able to mount the file using:
sudo mount -t ntfs /dev/loop1 testdir

One thing I can't answer is what you do to limit the extent of /dev/loop1 when you have more than one partition. The mounting process will prevent you from writing past the first partition.

Another thing I'm not sure about is if you need to create the loop devices in reverse order (top-down) so that the last partition is created first.

Also, whether it is possible to mount a loop device for the entire file (including the partition table and MBR) and have the separate partitions show up as devices in /dev/ without needing more loop devices.

----

Making an image of a partiton instead might be a better idea. You could make a separate backup of the MBR as well. Restoring the MBR will partition the new drive. Then you can use dd to restore th e partition.

In a slightly unrelated topic, before creating an image backup of a disk or partition, consider filling the partition(s) with files containing zeroes. Then delete these files before creating the images. The drive or partition will compress to a much smaller size if the empty spaces contain old file patterns. I tested out this idea using my /boot/ partition on my desktop and the difference in sizes was dramatic.

Code:

df /boot
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/sda1              155543    24602    122911  17% /boot
jschiwal@hpmedia:~> sudo dd if=/dev/zero of=/boot/zero.file bs=1024 count=122910
122910+0 records in
122910+0 records out
125859840 bytes (126 MB) copied, 1.6724 s, 75.3 MB/s
jschiwal@hpmedia:~> df /boot
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/sda1              155543    147996        0 100% /boot
jschiwal@hpmedia:~> sudo rm /boot/zero.file

Notice how I matched the unit size again. 1024 bytes this time. I subtracted 1 from the available blocks to leave room for any extension to the directory.
Code:

sudo dd if=/dev/sda1 | bzip2 - >boot.img.bz2
321237+0 records in
321237+0 records out
164473344 bytes (164 MB) copied, 26.7602 s, 6.1 MB/s
jschiwal@hpmedia:~> ls -lh boot.img.bz2
-rw-r----- 1 jschiwal jschiwal 19M 2008-05-24 08:17 boot.img.bz2
jschiwal@hpmedia:~> file boot.img.bz2
boot.img.bz2: bzip2 compressed data, block size = 900k
jschiwal@hpmedia:~> bunzip boot.img.bz2
-bash: bunzip: command not found
jschiwal@hpmedia:~> bunzip2 boot.img.bz2
jschiwal@hpmedia:~> file -s boot.img
boot.img: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, 1st sector stage2 0x6441, GRUB version 0.97, code offset 0x48
jschiwal@hpmedia:~> ls -l boot.img
-rw-r----- 1 jschiwal jschiwal 164473344 2008-05-24 08:17 boot.img
jschiwal@hpmedia:~> ls -lh boot.img
-rw-r----- 1 jschiwal jschiwal 157M 2008-05-24 08:17 boot.img


mpmackenna 05-27-2008 08:59 AM

I think you lost me. I read the losetup info page, but I am still having a hard time determining what offset I should use in order to mount the file with my back up image. Perhaps I am thinking about it all wrong. I just assumed that I could mount the image even though my image was of the entire disk because the disk contained only one partition. I didn't think about the fact that the MBR may cause issues with mounting the image. I should have just created an image of the partition instead of the entire disk, but it is too late now because I assumed it worked and overwrote the old disk. All I really need to do is extract some files from the partition contained in this image. I thought perhaps mounting the image file would be the easiest way to do so, but perhaps because I imaged the whole disk that is not the case. I could restore the image to disk I guess and then browse through the files I need and perhaps then just image the partition this time. Thanks for the help. If you have tips on determining my offset in order to mount this image I would love to hear them. Otherwise I think I am going to get started on restoring the whole image file to a disk. Thanks again! Next time I will be sure to image the partition in these cases instead of the whole disk. Mike

shadowlord42 08-27-2009 11:15 PM

In case no one figured it out or someone needs clearer info...
 
I recently had the same conundrum. I imaged my vista laptop's drive in anticipation of upgrading to window's 7. I then realized that I couldn't actually access the partitions as I imaged the whole drive itself rather than a partition (using a really helpful windows version of DD). Of course, how else are you going to restore the drive precisely...(NOTE: If you do it this way, using the \\?\Device\Harddisk0\DR0 backs up the entire disk...)

Here's what you can do to map/mount the partitions if you don't know anything about the image...as root (or via sudo...):

1. # file -s <image_file>
E.g. # file -s vista.img
vista.img: x86 boot sector; partition 2: ID=0x7, active, starthead 239, startsector 36136960, 354582528 sectors


2. # fdisk -ul <image_file> (optional: as you can see, file successfully guessed the offset above)
E.g. # fdisk -ul vista.img
You must set cylinders.
You can do this from the extra functions menu.

Disk vista.img: 0 MB, 0 bytes
240 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x7d760e5b

Device Boot Start End Blocks Id System
vista.img1 63 36136799 18068368+ 27 Unknown
Partition 1 has different physical/logical endings:
phys=(1023, 239, 63) logical=(2389, 239, 63)
vista.img2 * 36136960 390719487 177291264 7 HPFS/NTFS
Partition 2 has different physical/logical beginnings (non-Linux?):
phys=(1023, 239, 63) logical=(2390, 2, 35)
Partition 2 has different physical/logical endings:
phys=(1023, 239, 63) logical=(25841, 56, 40)


Not sure if you *have* to set cylinders...see how modern fdisk automagically figured out my partitions?

3. Take the partition's offset you want to access, in my case Partition 2/vista.img2 (partition1/vista.img1, I believe, is my laptop's recovery drive or possibly some vista/magic waste of space partition).

losetup -f -o $((<offset> * 512)) <image_file>
E.g. losetup -f -o $((36136960 * 512)) vista.img

You can also alternately mount the device image with an offset via the mount -o ro,loop,offset=########## -t ntfs <image_file> /some/dir command.

E.g. mount -o ro,loop,offset=18502123520 vista.img /tmp/test

4. You can check the file here if you'd like: file -s /dev/loop#
...Note: it uses the first available loopback device...
E.g. # file -s /dev/loop0
/dev/loop0: x86 boot sector, code offset 0x52, OEM-ID "NTFS ", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 240, hidden sectors 36136960, dos < 4.0 BootSector (0x80)


5. Mount the loopback device: mount -t ntfs /dev/loop# /some/dir
E.g. # mount /dev/loop0 /tmp/test
# ls -l /tmp/test
total 6578280
-r-------- 1 root root 24 2006-09-18 16:43 autoexec.bat
dr-x------ 1 root root 4096 2009-07-11 18:42 Boot
-r-------- 1 root root 333257 2009-04-10 23:36 bootmgr
-r-------- 1 root root 8192 2006-11-09 17:32 BOOTSECT.BAK
-r-------- 4 root root 10 2006-09-18 16:43 config.sys
dr-x------ 1 root root 0 2006-11-02 07:02 Documents and Settings
dr-x------ 1 root root 4096 2009-05-12 07:51 DRIVERS
-r-------- 1 root root 3211051008 2009-08-27 17:04 hiberfil.sys
dr-x------ 1 root root 0 2009-05-12 07:51 Icons
dr-x------ 1 root root 0 2009-05-12 07:51 Intel
-r-------- 1 root root 0 2009-08-16 12:07 IO.SYS
-r-------- 1 root root 0 2009-08-16 12:07 MSDOS.SYS
-r-------- 1 root root 3524628480 2009-08-27 17:04 pagefile.sys
dr-x------ 1 root root 0 2009-04-11 19:37 PerfLogs
dr-x------ 1 root root 4096 2009-06-21 03:03 ProgramData
dr-x------ 1 root root 12288 2009-08-05 22:08 Program Files
dr-x------ 1 root root 4096 2009-05-12 07:51 $Recycle.Bin
-r-------- 1 root root 53 2009-04-09 14:56 syslevel.lgl
dr-x------ 1 root root 32768 2009-08-27 17:29 System Volume Information
dr-x------ 1 root root 4096 2009-07-11 03:04 temp
dr-x------ 1 root root 4096 2009-05-12 07:51 Users
dr-x------ 1 root root 49152 2009-07-30 17:50 Windows


Hope this helps!

For total newbs:
To unmount: umount /tmp/test
To remove the looback device: losetup -d /dev/loop0

References:
http://www.linuxquestions.org/questi...43#post3165943
http://www.vistaheads.com/forums/sec...-aug-18th.html

mpmackenna 08-28-2009 08:01 AM

thanks
 
Quote:

Originally Posted by shadowlord42 (Post 3660310)
I recently had the same conundrum. I imaged my vista laptop's drive in anticipation of upgrading to window's 7. I then realized that I couldn't actually access the partitions as I imaged the whole drive itself rather than a partition (using a really helpful windows version of DD). Of course, how else are you going to restore the drive precisely...(NOTE: If you do it this way, using the \\?\Device\Harddisk0\DR0 backs up the entire disk...)

Here's what you can do to map/mount the partitions if you don't know anything about the image...as root (or via sudo...):

1. # file -s <image_file>
E.g. # file -s vista.img
vista.img: x86 boot sector; partition 2: ID=0x7, active, starthead 239, startsector 36136960, 354582528 sectors


2. # fdisk -ul <image_file> (optional: as you can see, file successfully guessed the offset above)
E.g. # fdisk -ul vista.img
You must set cylinders.
You can do this from the extra functions menu.

Disk vista.img: 0 MB, 0 bytes
240 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x7d760e5b

Device Boot Start End Blocks Id System
vista.img1 63 36136799 18068368+ 27 Unknown
Partition 1 has different physical/logical endings:
phys=(1023, 239, 63) logical=(2389, 239, 63)
vista.img2 * 36136960 390719487 177291264 7 HPFS/NTFS
Partition 2 has different physical/logical beginnings (non-Linux?):
phys=(1023, 239, 63) logical=(2390, 2, 35)
Partition 2 has different physical/logical endings:
phys=(1023, 239, 63) logical=(25841, 56, 40)


Not sure if you *have* to set cylinders...see how modern fdisk automagically figured out my partitions?

3. Take the partition's offset you want to access, in my case Partition 2/vista.img2 (partition1/vista.img1, I believe, is my laptop's recovery drive or possibly some vista/magic waste of space partition).

losetup -f -o $((<offset> * 512)) <image_file>
E.g. losetup -f -o $((36136960 * 512)) vista.img

You can also alternately mount the device image with an offset via the mount -o ro,loop,offset=########## -t ntfs <image_file> /some/dir command.

E.g. mount -o ro,loop,offset=18502123520 vista.img /tmp/test

4. You can check the file here if you'd like: file -s /dev/loop#
...Note: it uses the first available loopback device...
E.g. # file -s /dev/loop0
/dev/loop0: x86 boot sector, code offset 0x52, OEM-ID "NTFS ", sectors/cluster 8, reserved sectors 0, Media descriptor 0xf8, heads 240, hidden sectors 36136960, dos < 4.0 BootSector (0x80)


5. Mount the loopback device: mount -t ntfs /dev/loop# /some/dir
E.g. # mount /dev/loop0 /tmp/test
# ls -l /tmp/test
total 6578280
-r-------- 1 root root 24 2006-09-18 16:43 autoexec.bat
dr-x------ 1 root root 4096 2009-07-11 18:42 Boot
-r-------- 1 root root 333257 2009-04-10 23:36 bootmgr
-r-------- 1 root root 8192 2006-11-09 17:32 BOOTSECT.BAK
-r-------- 4 root root 10 2006-09-18 16:43 config.sys
dr-x------ 1 root root 0 2006-11-02 07:02 Documents and Settings
dr-x------ 1 root root 4096 2009-05-12 07:51 DRIVERS
-r-------- 1 root root 3211051008 2009-08-27 17:04 hiberfil.sys
dr-x------ 1 root root 0 2009-05-12 07:51 Icons
dr-x------ 1 root root 0 2009-05-12 07:51 Intel
-r-------- 1 root root 0 2009-08-16 12:07 IO.SYS
-r-------- 1 root root 0 2009-08-16 12:07 MSDOS.SYS
-r-------- 1 root root 3524628480 2009-08-27 17:04 pagefile.sys
dr-x------ 1 root root 0 2009-04-11 19:37 PerfLogs
dr-x------ 1 root root 4096 2009-06-21 03:03 ProgramData
dr-x------ 1 root root 12288 2009-08-05 22:08 Program Files
dr-x------ 1 root root 4096 2009-05-12 07:51 $Recycle.Bin
-r-------- 1 root root 53 2009-04-09 14:56 syslevel.lgl
dr-x------ 1 root root 32768 2009-08-27 17:29 System Volume Information
dr-x------ 1 root root 4096 2009-07-11 03:04 temp
dr-x------ 1 root root 4096 2009-05-12 07:51 Users
dr-x------ 1 root root 49152 2009-07-30 17:50 Windows


Hope this helps!

For total newbs:
To unmount: umount /tmp/test
To remove the looback device: losetup -d /dev/loop0

References:
http://www.linuxquestions.org/questi...43#post3165943
http://www.vistaheads.com/forums/sec...-aug-18th.html

Thanks for posting this update.

Mike

Technik007[CZ] 02-11-2014 06:51 AM

...

Technik007[CZ] 02-11-2014 06:56 AM

...

rknichols 02-11-2014 09:47 AM

A much simpler solution would be to run kpartx to create mappings for the partitions in the image.
Code:

# kpartx -a -v /var/tmp/test.img
add map loop1p1 (253:4): 0 5876512 linear /dev/loop1 32
add map loop1p2 (253:5): 0 2020544 linear /dev/loop1 5876544
# ll /dev/mapper/loop*
brw-rw----. 1 root disk 253, 4 2014-02-11 09:44:00 /dev/mapper/loop1p1
brw-rw----. 1 root disk 253, 5 2014-02-11 09:44:01 /dev/mapper/loop1p2



All times are GMT -5. The time now is 11:29 AM.