How to mount raw images (.img) images on Linux
If you have a few .img files coming as disk images from devices like floppies, CDs, DVDs, SD cards, etc, you will realize that you cannot mount the in Linux, because they contain a file system that has to be mounted.
In linux you would need to use the mount command as for any physical device, however you need to know the correct syntax that is based on understanding the information related to the partition(s) available in the image.
First step is to read the partition Start point using fdisk:
Pull up a bash prompt and execute:
sudo fdisk -l imgfile.img
You will see something like this:
Disk imgfile.img: 28.99 GiB, 31104958464 bytes, 60751872 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: dos Disk identifier: 0x6c586e13 Device Boot Start End Sectors Size Id Type dan-octopi-20210407.img1 8192 532479 524288 256M c W95 FAT32 (LBA) dan-octopi-20210407.img2 532480 60751871 60219392 28.7G 83 Linux
As you can see there are two partitions, one that is FAT32 and the other one that it’s ExtFS. This means that to mount the first partition we have to tell Linux that we need to start at the sector 63. Note the sector size is 512 bytes, so to read/modify the data in the first partion:
sudo mkdir /mnt/disk1 sudo mount -t vfat -o loop,offset=$((8192 * 512 )) imgfile.img /mnt/disk1
where:
8192 is the start of the first parition
512 is the sector size
H/T: https://stefanoprenna.com/blog/2014/09/22/tutorial-how-to-mount-raw-images-img-images-on-linux/