Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  185] [ 0]  / answers: 1 / hits: 206084  / 2 Years ago, wed, may 4, 2022, 7:55:35

I made an image of my entire disk with



dd if=/dev/sda of=/media/external_media/sda.img


Now the problem is I'd like to mount an ext4 filesystem that was on that disk but



mount -t ext4 -o loop /media/external_media/sda.img /media/sda_image


obviously gives a superblock error since the image contains the whole disk (MBR, other partitions) not just the partition I need. So I guess I should find a way to make the disk image show up in the /dev/ folder...



Does anyone know how to do that?



PS: I can always dd back the image to the original disk, but that would be very inconvenient (I updated the OS and I'd like to keep it as it is)


More From » mount

 Answers
7

Get the partition layout of the image



$ sudo fdisk -lu sda.img
...
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
...
Device Boot Start End Blocks Id System
sda.img1 * 56 6400000 3199972+ c W95 FAT32 (LBA)


Calculate the offset from the start of the image to the partition start



Sector size * Start = (in the case) 512 * 56 = 28672



Mount it on /dev/loop0 using the offset



sudo losetup -o 28672 /dev/loop0 sda.img


Now the partition resides on /dev/loop0. You can fsck it, mount it etc



sudo fsck -fv /dev/loop0
sudo mount /dev/loop0 /mnt


Unmount



sudo umount /mnt
sudo losetup -d /dev/loop0

[#42769] Thursday, May 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anatta

Total Points: 326
Total Questions: 128
Total Answers: 96

Location: Jordan
Member since Sun, Jun 26, 2022
2 Years ago
anatta questions
Sun, Jul 17, 22, 07:13, 2 Years ago
Sun, Jun 6, 21, 12:17, 3 Years ago
Sat, Jun 12, 21, 20:43, 3 Years ago
Thu, Jan 13, 22, 20:49, 2 Years ago
Sat, Jun 5, 21, 05:39, 3 Years ago
;