Page 1 of 1
How to mount an .img file on a loop device?
Posted: Sat Aug 07, 2021 10:09 pm
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
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 7:06 am
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
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 1:37 pm
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?
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 2:22 pm
by rcrsn51
Please provide the source of this image file.
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 2:30 pm
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...)
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 3:53 pm
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.
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 6:03 pm
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.
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 6:07 pm
by Clarity
@rcrsn51
@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;
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
Thanks, again
Maybe developers can/will include a simple utility to do such in WoofCE or for their distros.
Also thanks, everyone, for helping.
Re: How to mount an .img file on a loop device?
Posted: Sun Aug 08, 2021 7:24 pm
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) :
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...
Re: How to mount an .img file on a loop device?
Posted: Mon Aug 09, 2021 3:11 pm
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.
viewtopic.php?f=4&t=1186&start=11