Copying USB stick fails with device errors

Bryn M. Reeves bmr at redhat.com
Fri Jun 8 16:02:30 UTC 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 06/08/2012 04:03 PM, Alex wrote:
> Hi,
> 
>>>> Use an offset, e.g.
>>>> 
>>>> # mount -o loop,offset=4 ....
>>> 
>>> Thanks, I should have thought of that. Alas, it didn't work.
>>> 
>>> # mount -o loop,offset=4 -t vfat myusb_sdb.dd /media/desktop/ 
>>> 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
>>> 
>> 
>> I believe the offset is in bytes, not sectors.  If I'm right,
>> then you need: mount -o loop,offset=2048 -t vfat myusb_sdb.dd
>> /media/desktop/
> 
> That was it. Thanks so much. It's now mounted successfully.

If you're trying to access partitions within a disk image it's usually
much easier to use the loop device and kpartx (from multipath-tools
but installed in a separate sub-package in recent Fedora).

Bind the image to a loop device:

# losetup /dev/loop0 /tmp/sda.img
# kpartx -a /dev/loop0

This will map partitions defined in the image as new device-mapper
devices with names like /dev/mapper/loop0p1 (for the partition one)
and has the advantage of supporting all common partition tables and
making all partitions available with a single command.

The resulting device-mapper devices can then be mounted directly as
any other block device.

Options are available to control the delimiter ('p' by default) used
and whether to include it always or only when the device name ends in
a digit.

When done you can tear down a (non-busy) map with:

# kpartx -d /dev/loop0

If that fails for any reason (e.g. you removed the partition table
while the maps were active) then you can clean up manually with
"dmsetup remove <name>".

If you find yourself working with partitioned images a lot then it's
worth taking a look at libguestfs and guestfish - these are tools
designed for working with VM images but they should work just as well
with any partitioned disk image.

Regards,
Bryn.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/SIhYACgkQ6YSQoMYUY95BnQCfXhn83BajEd6u4licNlqBLcyH
PIkAn1FqCiCo9ZjXJ1EJu1386eENc1id
=HRlw
-----END PGP SIGNATURE-----


More information about the users mailing list