Ein mit dd erstelltes Image mounten - Mount an Image created with dd (DE / EN)

in deutsch •  3 years ago 

(English Below / Englisch unten)

Ein mit dd erstelltes Image mounten - Mount an Image created with dd (DE / EN)

Es kommt leider vor das USB Sticks kaputt gehen.
Manchmal hat man das Glück das die Daten wenigstens noch mit dd oder ddrescue
ausgelesen werden können.

Ausgelesen wird mit dd z.b wie folgt:

dd if=/dev/sdc of=/home/user/sandisk32.img

In diesem Fall hat man nach erfolgreicher Rettung der Daten erstmal nur eine 32Gigabyte grosse Datei. Wie bekommt man nun die Einzeldateien da raus? Naja in der Datei ist ja das gleiche Dateisystem wie es auf dem USB Stick enthalten war. Wie kommt man da aber ran, ein einfacher mount Befehl funktioniert in diesem Fall nicht. Das Mounten eines mittels dd erstellten Images einer Festplatte, USB Stick etc erfordert mehrere Schritte:


Der Pfad zur Datei im Beispiel ist:
/home/user/sandisk32.img

Erstmal muss mit fdisk die Partitionstabelle aus der Datei ausgelesen werden:

fdisk -lu /home/user/sandisk32.img

Die Ausgabe sieht dann so aus:

Disk sandisk32.img: 30.8 GB, 30751834112 bytes
255 heads, 63 sectors/track, 3738 cylinders, total 60062176 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: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
sandisk32.img1   *        2048    58595327    29296640   83  Linux
sandisk32.img2        58595328    60062499      733586   82  Linux swap / Solaris

Jetzt muss der Einsprungpunkt fuer die erste Partition ausgerechnet werden:
Sektorengrösse * Startblock = Einsprungpunkt
512 * 2048 = 1048576

Jetzt wird Einsprungpunkt ueber Loopback gemounted:

sudo losetup -o 1048576 /dev/loop0 /home/user/sandisk32.img

(Das Kommando muss mit root rechten ausgeführt werden)

Jetzt wird die eigentliche Partition ins Dateisystem des Hosts eingebunden.

mount /dev/loop0 /mnt

Danach ist schreiblese Zugriff auf das Image moöglich. Um das Image wieder auszuhängen:

umount /mnt

Das erstellte Loop Device kann dann wieder gelöscht werden.

losetup -d /dev/loop0

English Version

Unfortunately it happens that USB sticks break.
Sometimes you have the luck that the data at least still with dd or ddrescue
can be read out.

Readout is done with dd e.g. as follows:

dd if=/dev/sdc of=/home/user/sandisk32.img

In this case, after successfully rescuing the data, you only have a 32 gigabyte file. How do you get the individual files out of it? Well, the file contains the same file system as it was on the USB stick. But how do you get to it? A simple mount command does not work in this case. Mounting an image of a hard disk, USB stick etc created by dd requires several steps:


The path to the file in the example is:
/home/user/sandisk32.img

First you have to read the partition table from the file with fdisk:

fdisk -lu /home/user/sandisk32.img

The output then looks like this:

Disk sandisk32.img: 30.8 GB, 30751834112 bytes
255 heads, 63 sectors/track, 3738 cylinders, total 60062176 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: 0x00000000

        Device Boot      Start         End      Blocks   Id  System
sandisk32.img1   *        2048    58595327    29296640   83  Linux
sandisk32.img2        58595328    60062499      733586   82  Linux swap / Solaris

Now the entry point for the first partition must be calculated:
sector size * start block = entry point
512 * 2048 = 1048576

Now the entry point is mounted via loopback:

sudo losetup -o 1048576 /dev/loop0 /home/user/sandisk32.img

(The command must be executed with root rights).

Now the partition is mounted into the file system of the host.

mount /dev/loop0 /mnt

After that, read-write access to the image is possible. To export the image again:

umount /mnt

After use, the created loop device can then be deleted.

losetup -d /dev/loop0
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!