Obtain a binary image
We have a USB key with a file system on it, and we want to save its content. We do a binary image using:
1 $ dd if=/dev/sda1 of=/home/kevin/usb_key.img
Mount the image file
Get information about the file system of the image file using:
1 $ fdisk -l -u /home/kevin/usb_key.img
This show you something like that:
Disque usb_key.img: 0 Mo, 0 octets
9 têtes, 56 secteurs/piste, 0 cylindres, total 0 sectors
Unités = secteurs de 1 * 512 = 512 octets
Périphérique Boot Start End Blocks Id System
usb_key.img1 56 511559 255752 83 Linux
Get the sector number where the partition start (56) and the size of sectors (512). Multiply the two values:
56 * 512 = 28672
Then setup a loopback block device based on the image:
1 $ losetup -o 28672 /dev/loop0 /home/kevin/usb_key.img
Now you can mount your USB key:
1 $ mount /dev/loop0 /mnt/usb_key/