Issue mounting img files I've created

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
OlivierM
Level 2
Level 2
Posts: 69
Joined: Tue Jan 20, 2015 4:33 am

Issue mounting img files I've created

Post by OlivierM » Mon Aug 01, 2016 5:19 am

Hello guys,

I am encountering a recurrent issue when trying to mount multi-partition disk images (.img) I have created.
Whether it is images from raspbian, or from other "live" distros I have created (one on a USB key, based on SlackOS, for an arcade machine I've created for a laptop motherboard without hard drive, for instance).
The boot partition always mounts correctly, whereas the second partition gives me this error, every time :

Code: Select all

Error mounting /dev/loop0p2 at /media/olivier/Mame: Command-line `mount -t "ext4" -o "uhelper=udisks2,nodev,nosuid" "/dev/loop0p2" "/media/olivier/Mame"' exited with non-zero exit status 32: mount: block device /dev/loop0p2 is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/loop0p2,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
I use the following command to create them, after switching to su (not sudo) in the terminal:

Code: Select all

dd if=/dev/sdf | pv | dd of=/path/to.img
.dev/sdf contains a boot partition (/dev/sdf1) and a data partition (/dev/sdf2). The second partition is always an ext4 one.

When I rewrite the image using the same command, to a sd card or a usb drive, everything works fine.
Is there something I can do to correct this behaviour?
Thanks in advance.

P.S. as suggested by the error message,

Code: Select all

[95791.389145]  loop0: p1 p2
[95795.387134] EXT4-fs (loop0p2): INFO: recovery required on readonly filesystem
[95795.387136] EXT4-fs (loop0p2): write access unavailable, cannot proceed
[95801.345272] EXT4-fs (loop0p2): INFO: recovery required on readonly filesystem
[95801.345277] EXT4-fs (loop0p2): write access unavailable, cannot proceed
[95802.335846] EXT4-fs (loop0p2): INFO: recovery required on readonly filesystem
[95802.335854] EXT4-fs (loop0p2): write access unavailable, cannot proceed
XFCE Mint 17.3 & 18.1. Various laptops and desktops.

User avatar
WharfRat
Level 21
Level 21
Posts: 13159
Joined: Thu Apr 07, 2011 8:15 pm

Re: Issue mounting img files I've created

Post by WharfRat » Mon Aug 01, 2016 9:54 am

Are you using kpartx to setup device maps for the partitions :?:
ImageImage

OlivierM
Level 2
Level 2
Posts: 69
Joined: Tue Jan 20, 2015 4:33 am

Re: Issue mounting img files I've created

Post by OlivierM » Mon Aug 01, 2016 11:58 am

No, I'm just using dd.
The blank usb or sd disks are formated using gparted
XFCE Mint 17.3 & 18.1. Various laptops and desktops.

User avatar
WharfRat
Level 21
Level 21
Posts: 13159
Joined: Thu Apr 07, 2011 8:15 pm

Re: Issue mounting img files I've created

Post by WharfRat » Mon Aug 01, 2016 12:42 pm

OlivierM wrote:No, I'm just using dd.
The blank usb or sd disks are formated using gparted
You can only mount partitions, not images of entire disks. Therefore, kpartx is required to identify and map the partitions.

Just to be sure I know what I'm talking about here, change to the folder that houses the image file and paste back

Code: Select all

sudo kpartx -l the.image
Naturally you're going to substitute the actual image file name in place of 'the.image'
ImageImage

OlivierM
Level 2
Level 2
Posts: 69
Joined: Tue Jan 20, 2015 4:33 am

Re: Issue mounting img files I've created

Post by OlivierM » Mon Aug 01, 2016 12:48 pm

Ah ok, I misunderstood and thought you were talking about the partitions table's creation. My bad.

There is the result of the command :

Code: Select all

loop0p1 : 0 8390593 /dev/loop0 63
loop0p2 : 0 54126592 /dev/loop0 8390656
loop deleted : /dev/loop0
(32 BG image)
XFCE Mint 17.3 & 18.1. Various laptops and desktops.

User avatar
WharfRat
Level 21
Level 21
Posts: 13159
Joined: Thu Apr 07, 2011 8:15 pm

Re: Issue mounting img files I've created

Post by WharfRat » Mon Aug 01, 2016 1:00 pm

OK, there we go. Now enter

Code: Select all

sudo kpartx -a -v the.image
What you will get is, add map loop0p1 or some other map name, but loop0p1 is the one you want to use for mounting, There could be a couple of them named loop0p2 etc.

Now you would mount the mapped device to your mountpoint

Code: Select all

sudo mount /dev/mapper/loop0p1 /media/someplace
Now if you

Code: Select all

ls /media/someplace
you're content should be available.

Again you'll have to figure out if the mapped device is the ext4 partition or a swap partition in which case it can't be mounted.

Oh, and when you're done unmount and remove mappings

Code: Select all

sudo umount /media/someplace
sudo kpartx -d -v the.image
ImageImage

OlivierM
Level 2
Level 2
Posts: 69
Joined: Tue Jan 20, 2015 4:33 am

Re: Issue mounting img files I've created

Post by OlivierM » Mon Aug 01, 2016 2:33 pm

Thanks a lot WhafRat, that worked really well.

It's a pity Thunar doesn't do this automatically, instead of trying to mount the partition and giving an error.
XFCE Mint 17.3 & 18.1. Various laptops and desktops.

User avatar
WharfRat
Level 21
Level 21
Posts: 13159
Joined: Thu Apr 07, 2011 8:15 pm

Re: Issue mounting img files I've created

Post by WharfRat » Mon Aug 01, 2016 2:52 pm

OlivierM wrote:Thanks a lot WhafRat, that worked really well.

It's a pity Thunar doesn't do this automatically, instead of trying to mount the partition and giving an error.
It's not Thunar's job - it's not a partition manager, it's a file manager :wink:
ImageImage

OlivierM
Level 2
Level 2
Posts: 69
Joined: Tue Jan 20, 2015 4:33 am

Re: Issue mounting img files I've created

Post by OlivierM » Tue Aug 02, 2016 2:57 am

That's true, but as a matter of fact, it is possible to right-click the image and select the "mount" option. Then the drives contained in the image appear in the "drives" column in Thunar. The first partition always mounts correctly, the second one doesn't.

Now I have understood the why and how, thanks to you, but I still think Thunar should be able to automatize the procedure (asking for admin password) and correctly mount both partitions, instead of displaying an esoteric error message.

Anyway, thanks again, today I learnt something useful :)
XFCE Mint 17.3 & 18.1. Various laptops and desktops.

Post Reply

Return to “Newbie Questions”