July 31, 2023
Mounting partitions (ext4 and LVM2) inside a ‘dd’ image
A hard disk image may be taken using ‘dd’ or a similar too. This image can be used for later analysis or recovery.
The image exists as a single file: image.img
View the partition table of the image
# fdisk -lu image.img
Disk image.img: 953.87 GiB, 1024209543168 bytes, 2000409264 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
Disklabel type: gpt
Disk identifier: C08CDF4A-C6C5-411E-××××-××××××××××××
Device Start End Sectors Size Type
image.img 2048 1050623 1048576 512M EFI System
image.img 1050624 2050047 999424 488M Linux filesystem
image.img 2050048 2000408575 1998358528 952.9G Linux filesystem
Mount the ext4 partition (2nd partition)
Calculate the offset: start sector * 512
1050624 * 512 = 537919488
mkdir image_part2
mount -o loop,ro,offset=537919488 image.img image_part2
The second partition is now mounted in the directory ‘image_part2’
Mount an LVM2 Volume (3rd partition)
In this example, the 3rd partition is an LVM2 volume.
Calculate the offset: start sector * 512
2050048 * 512 = 1049624576
losetup -f --show -o 1049624576 image.img
vgscan
vgchange -ay
pvdisplay
--- Physical volume ---
PV Name /dev/loop8
VG Name vg_mypc
PV Size …
# Note the loop device name for later
lvdisplay
--- Logical volume ---
LV Path /dev/vg_mypc/home
LV Name home
VG Name vg_mypc
LV UUID …
mkdir mountPoint
mount /dev/vg_mypc/home mountPoint
The LVM2 Volume ‘home’ is now available in the mountPoint directory.
Cleanup
When finished, unmount the volume, update the active LVMs volumes and remove the unused loop device.
umount mountPoint
# identify loop device in use:
losetup
lvchange -an /dev/vg_mypc/home
losetup -d /dev/loop8
