First of all you can check what are the current disks mounted on your machine:

ubuntu@ubuntu:~$ lsblk
 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
 sda      8:0    0 238.5G  0 disk 
 └─sda1   8:1    0   128M  0 part 
 sdb      8:16   1  28.7G  0 disk 
 ├─sdb1   8:17   1  24.7G  0 part /cdrom
 └─sdb2   8:18   1     4G  0 part /media/ubuntu/casper-rw1
 sdc      8:32   0 298.1G  0 disk 
 └─sdc1   8:33   0 298.1G  0 part /media/ubuntu/GOODRAM1

Next – create the folder under which you want your disk to be mounted:

ubuntu@ubuntu:~$ sudo mkdir /mnt/myDiskName

Once the folder is created, we have to check what are the contents of the .img file and where is the starting block of the partition. To do so type:

ubuntu@ubuntu:/pathToMyImage$ fdisk -l myImageFile.img
 Disk myImageFile.img: 14.86 GiB, 15931539456 bytes, 31116288 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: 0x768808d1
 Device           Boot Start      End  Sectors  Size Id Type
 myImageFile.img1       8192    96663    88472 43.2M  c W95 
 myImageFile.img2      98304 31116287 31017984 14.8G 83 Linu

Now when you know what is the Start sector (here it is 98304) and what is the sector size in bytes (here is 512) we can count where is the starting point in bytes 98304*512=50331648 bytes. Then to mount the disk you can simply type:

ubuntu@ubuntu:/pathToMyImage$ sudo mount -o loop,offset=50331648 myImageFile.img /mnt/myDiskName/

Now just check if the disk is mounted:

ubuntu@ubuntu:~$ lsblk
 NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
 loop0    7:6    0  14.8G  0 loop /mnt/myDiskName
 sda      8:0    0 238.5G  0 disk 
 └─sda1   8:1    0   128M  0 part 
 sdb      8:16   1  28.7G  0 disk 
 ├─sdb1   8:17   1  24.7G  0 part /cdrom
 └─sdb2   8:18   1     4G  0 part /media/ubuntu/casper-rw1
 sdc      8:32   0 298.1G  0 disk 
 └─sdc1   8:33   0 298.1G  0 part /media/ubuntu/GOODRAM1

In order to unmount the disk simply run:

ubuntu@ubuntu:~$ sudo umount /mnt/myDiskName

You can generate list of commands below:


lsblk
sudo mkdir {{ destinationFolder }}
cd {{ sourceFolder }}
fdisk -l {{ imageName }}
sudo mount -o loop,offset={{ offset }} {{ imageName }} {{ destinationFolder }}
lsblk
sudo umount {{ destinationFolder }}