How to mount an .img file on a loop device?

interpretive language scripts


Moderator: Forum moderators

Post Reply
Clarity
Posts: 3236
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1319 times
Been thanked: 435 times

How to mount an .img file on a loop device?

Post by Clarity »

I am trying to mount an image file on a loop device (similar to how an ISO file is mounted in PUP).

I get the following error in the mount attempt.

Thanks in advance for any guidance

Code: Select all

~$ mkdir /mnt/ddrescue-2GB_SG2D.img
~$ mount /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img /mnt/ddrescue-2GB_SG2D.img -o loop
NTFS signature is missing.
Failed to mount '/dev/loop5': Invalid argument
The device '/dev/loop5' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?
~$ 

P.S. I think the solution could be universal on all PUPs. But if not, I am running this on Slacko64 v8.2.1

Edit: A solution for this is found here on this thread

Last edited by Clarity on Sun Aug 08, 2021 6:20 pm, edited 1 time in total.
williams2
Posts: 1023
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: How to mount an .img file on a loop device?

Post by williams2 »

What are the results of
file /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img
and
fdisk -l /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img

Clarity
Posts: 3236
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1319 times
Been thanked: 435 times

Re: How to mount an .img file on a loop device?

Post by Clarity »

Google this before, but nothing jumps out.

Code: Select all

~$ fdisk -l /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img
Disk /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img: 1.87 GiB, 2004877312 bytes, 3915776 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: 0x841728fb

Device                                    Boot Start     End Sectors  Size Id Type
/mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img1 *     2048   69631   67584   33M  b W95 FAT32
/mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img2      69632 3915775 3846144  1.8G 83 Linux
~$ file /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img
/mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img: DOS/MBR boot sector

Seems the ONLY way I currently know is to continue using QEMU to see contents of any bootable image file: Unless, of course, if you burned it to unit.

Anyone know of other ways to see contents (folders and files) of an image file?

User avatar
rcrsn51
Posts: 1181
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 254 times

Re: How to mount an .img file on a loop device?

Post by rcrsn51 »

Please provide the source of this image file.

HerrBert
Posts: 329
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 17 times
Been thanked: 110 times

Re: How to mount an .img file on a loop device?

Post by HerrBert »

To mount a partition from a disk image file you have to specify an offset in mount command.

offset = Units * Start

Assuming you want to mount the Linux partition

Code: Select all

/mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img2      69632 3915775 3846144  1.8G 83 Linux 

the mount command will be

Code: Select all

mkdir /mnt/ddrescue-2GB_SG2D
mount -o loop,offset=$((512*69632)) /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img /mnt/ddrescue-2GB_SG2D

(mountpoint without extension to avoid confusion...)

User avatar
Grey
Posts: 1984
Joined: Wed Jul 22, 2020 12:33 am
Location: Russia
Has thanked: 75 times
Been thanked: 355 times

Re: How to mount an .img file on a loop device?

Post by Grey »

Clarity wrote: Sun Aug 08, 2021 1:37 pm

Seems the ONLY way I currently know is to continue using QEMU to see contents of any bootable image file: Unless, of course, if you burned it to unit.
Anyone know of other ways to see contents (folders and files) of an image file?

PPM should have AcetoneISO. Last year I installed Furius ISO Mount from somewhere (Fossapup).
Also try unpacking "stupidly" with the latest version of UExtract.

Fossapup OS, Ryzen 5 3600 CPU, 64 GB RAM, GeForce GTX 1050 Ti 4 GB, Sound Blaster Audigy Rx with amplifier + Yamaha speakers for loud sound, USB Sound Blaster X-Fi Surround 5.1 Pro V3 + headphones for quiet sound.

williams2
Posts: 1023
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: How to mount an .img file on a loop device?

Post by williams2 »

@HerrBert is correct.

The image file has 2 partitions.

The first partition is a small fat32 partition for uefi.

The second partition is a Linux partition. Your mount command is trying to mount the img file as an ntfs file system.

In Puppy, mount and umount are scripts. They are buggy, in my experience.
The main reason that mount is a script, is for mounting an ntfs file system using a different driver than the driver that mount-FULL would use by default.

Try something like this:
mount-FULL -o loop,offset=35651584 ddrescue-2GB_SG2D.img /mnt/data/
to mount the Linux partition on /mnt/data/, assuming the img file is in your working dir, and 35651584 is 512*69632.

If it still doesn't get the file system type right, you can try specifying the type, like this:
mount-FULL -t ext2 -o loop,offset=35651584 ddrescue-2GB_SG2D.img /mnt/data/
or
mount-FULL -t ext3 -o loop,offset=35651584 ddrescue-2GB_SG2D.img /mnt/data/
or
mount-FULL -t ext4 -o loop,offset=35651584 ddrescue-2GB_SG2D.img /mnt/data/

If it mounts properly, I would use umount-FULL /mnt/data/ when you are finished with it, rather than using the umount script.

Clarity
Posts: 3236
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1319 times
Been thanked: 435 times

Re: How to mount an .img file on a loop device?

Post by Clarity »

@rcrsn51

Code: Select all

ddrescue

@HerrBert Thanks ever so much in both the understanding as well as the sample. I modified my original command to match you sample suggestion. for the 2nd partition

Code: Select all

~$ mount -o loop,offset=$((512*69632)) /mnt/sdg1/BOOTIMGS/ddrescue-2GB_SG2D.img /mnt/ddrescue-2GB_SG2D.img
~$ 

Excellent and works to mount that individual partition. ROX can be used to see partition's contents in the mounted...same view as when an ISO is clicked. And umount works in this slacko64 v8.2.1 distro.

Code: Select all

~$ umount /mnt/ddrescue-2GB_SG2D.img
~$ 

Even as there is no PUP/DOG utility for such, @HerrBert instructions are as follows;

  1. Interrogate the image file (fdisk -l image-filename.img)

  2. and each partition in the image file is mounted separately based upon its beginning offset value

Thanks, again

Maybe developers can/will include a simple utility to do such in WoofCE or for their distros.

Also thanks, everyone, for helping.

HerrBert
Posts: 329
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 17 times
Been thanked: 110 times

Re: How to mount an .img file on a loop device?

Post by HerrBert »

Even as there is no PUP/DOG utility for such, @HerrBert instructions are as follows;

Interrogate the image file (fdisk -l image-filename.img)

and each partition in the image file is mounted separately based upon its beginning offset value

Caveat (as always) :shock: :
This may work for the given setup, but i'm not sure if it works with other than the endmost partitions.
Theoretically, when mounting the first partition with -o loop,offset=$((512*2048)) subsequent partitions may not be accessible. Maybe in such case the option sizelimit has to be given too. Never tried it though...

User avatar
Jafadmin
Posts: 376
Joined: Tue Aug 04, 2020 4:51 pm
Has thanked: 68 times
Been thanked: 84 times

Re: How to mount an .img file on a loop device?

Post by Jafadmin »

I wrote a util called 'loopimg' last year that handles this. It will mount disk images with multiple partitions, and has a 'unloop' command to unmount it.

LoopImg.tar.gz
(34.72 KiB) Downloaded 150 times

viewtopic.php?f=4&t=1186&start=11

Post Reply

Return to “Scripts”