WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Mounting disk image fails  (Read 493 times)

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Mounting disk image fails
« on: July 16, 2020, 01:56:44 PM »
Running TinyCore on x86, when I try to mount piCore disk image, it fails, not sure why:

Code: [Select]
sudo mount -o loop,offset=8192 piCore-11.0.img mountpoint where mountpoint is the directory I created right before this command.

I get the error as
Code: [Select]
mount: mounting /dev/loop32 on mountpoint1 failed: Invalid argument
How do I specify where the disk img should be mounted?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8104
Re: Mounting disk image fails
« Reply #1 on: July 16, 2020, 02:06:10 PM »
Hi ashfame
Try this:
Code: [Select]
# You will need the util-linux version of losetup and lsblk.
# First we want the image to look like a device.
tc@E310:~/PiCore/TC9$ sudo losetup --show --find --partscan piCore-9.0.3.img
/dev/loop332
tc@E310:~/PiCore/TC9$
# Next we want some information about the device.
tc@E310:~/PiCore/TC9$ sudo lsblk -f /dev/loop332
NAME        FSTYPE LABEL  UUID                                 MOUNTPOINT
loop332                                                       
|-loop332p1 vfat   piCore 58E0-9B9D                           
`-loop332p2 ext4          ab8d10da-a8b7-4852-b39d-f7328f492c6b
tc@E310:~/PiCore/TC9$
# It has 2 partitions, so we create 2 mountpoints.
mkdir P1 P2
# Finally, we mount the 2 partitions so we can access them.
tc@E310:~/PiCore/TC9$ sudo mount /dev/loop332p1 P1
tc@E310:~/PiCore/TC9$ sudo mount /dev/loop332p2 P2
tc@E310:~/PiCore/TC9$
# And we see they are mounted.
tc@E310:~/PiCore/TC9$ sudo lsblk -f /dev/loop332
NAME        FSTYPE LABEL  UUID                                 MOUNTPOINT
loop332                                                       
|-loop332p1 vfat   piCore 58E0-9B9D                            /home/tc/PiCore/TC9/P1
`-loop332p2 ext4          ab8d10da-a8b7-4852-b39d-f7328f492c6b /home/tc/PiCore/TC9/P2
tc@E310:~/PiCore/TC9$

    [EDIT]: Changed  losetup --show  to  sudo losetup --show.  Rich
« Last Edit: July 26, 2020, 01:10:21 PM by Rich »

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #2 on: July 16, 2020, 03:45:16 PM »
Hi ashfame
Try this:
Code: [Select]
# You will need the util-linux version of losetup and lsblk.

Hi Rich,

I ran into this pretty quick I think. I get an error "losetup: unrecognized option --show. Busybox v1.31.1" and for --find too, which makes me think I need a diff losetup running.

When you said util-linux version of losetup and lsblk, did you mean something other than "util-linux.tcz"?

P.S. - Wondering if remastering piCore on TinyCore instead of any other linux distro, to avoid file permissions issue might be more trouble than just figuring out the right permissions needed and setting them. Thoughts?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8104
Re: Mounting disk image fails
« Reply #3 on: July 16, 2020, 06:45:21 PM »
Hi ashfame
... When you said util-linux version of losetup and lsblk, did you mean something other than "util-linux.tcz"? ...
Yes, that's exactly what I meant.

As far as this is concerned:
Code: [Select]
sudo mount -o loop,offset=8192 piCore-11.0.img mountpoint

It should be:
Code: [Select]
sudo mount -o loop,offset=$((512 * 8192)),sizelimit=$((512 * $Sectors)) piCore-11.0.img mountpoint
offset  and  sizelimit  is in bytes so it needs to be multiplied by the sector size (512).

sizelimit is required because the image has multiple partitions. Without it you will get an  overlapping loop device  error when you
try to mount the second partition. You can get the correct value for  $Sectors  by running:
Code: [Select]
fdisk -l piCore-11.0.imgThere will be a column called  Sectors.

Regardless, you will still need util-linux for this to work. Using  losetup  as I showed in reply #1 takes care of offset/sizelimit for you
and simplifies the resulting mount commands.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #4 on: July 17, 2020, 03:35:40 AM »
Hi Rich,

Hi ashfame
... When you said util-linux version of losetup and lsblk, did you mean something other than "util-linux.tcz"? ...
Yes, that's exactly what I meant.

That's exactly what I installed and it still gave me that error. Perhaps a diff between piCore v9 vs v11?

As far as this is concerned:
Code: [Select]
sudo mount -o loop,offset=8192 piCore-11.0.img mountpoint

It should be:
Code: [Select]
sudo mount -o loop,offset=$((512 * 8192)),sizelimit=$((512 * $Sectors)) piCore-11.0.img mountpoint
offset  and  sizelimit  is in bytes so it needs to be multiplied by the sector size (512).

sizelimit is required because the image has multiple partitions. Without it you will get an  overlapping loop device  error when you
try to mount the second partition. You can get the correct value for  $Sectors  by running:
Code: [Select]
fdisk -l piCore-11.0.imgThere will be a column called  Sectors.

Regardless, you will still need util-linux for this to work. Using  losetup  as I showed in reply #1 takes care of offset/sizelimit for you
and simplifies the resulting mount commands.

I was able to do it without it in ubuntu, I guess it must be figuring out the end of the partition by itself cuz your explanation makes sense. But the ability to not having to specify that in a bash script is ideal :)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8104
Re: Mounting disk image fails
« Reply #5 on: July 17, 2020, 07:22:12 AM »
Hi ashfame
... That's exactly what I installed and it still gave me that error. ...
Are you sure? You said:
...  I get an error "losetup: unrecognized option --show. Busybox v1.31.1" and for --find too, ...
If  util-linux.tcz  was installed, it should have defaulted to  /usr/local/sbin/losetup  instead of the  busybox version. What does this return:
Code: [Select]
tce-load -i util-linux
which losetup

If you use the  --help  parameter you should see something like this:
Code: [Select]
tc@E310:~$ losetup --help

Usage:
 losetup [options] [<loopdev>]
 losetup [options] -f | <loopdev> <file>

Set up and control loop devices.

Options:
 -a, --all                     list all used devices
 -d, --detach <loopdev>...     detach one or more devices
 -D, --detach-all              detach all used devices
 -f, --find                    find first unused device
 -c, --set-capacity <loopdev>  resize the device
 -j, --associated <file>       list all devices associated with <file>
 -L, --nooverlap               avoid possible conflict between devices

 -o, --offset <num>            start at offset <num> into file
     --sizelimit <num>         device is limited to <num> bytes of the file
 -b  --sector-size <num>       set the logical sector size to <num>
 -P, --partscan                create a partitioned loop device
 -r, --read-only               set up a read-only loop device
     --direct-io[=<on|off>]    open backing file with O_DIRECT
     --show                    print device name after setup (with -f)
 -v, --verbose                 verbose mode

 -J, --json                    use JSON --list output format
 -l, --list                    list info about all or specified (default)
 -n, --noheadings              don't print headings for --list output
 -O, --output <cols>           specify columns to output for --list
     --raw                     use raw --list output format

 -h, --help                    display this help
 -V, --version                 display version

Available output columns:
         NAME  loop device name
    AUTOCLEAR  autoclear flag set
    BACK-FILE  device backing file
     BACK-INO  backing file inode number
 BACK-MAJ:MIN  backing file major:minor device number
      MAJ:MIN  loop device major:minor number
       OFFSET  offset from the beginning
     PARTSCAN  partscan flag set
           RO  read-only device
    SIZELIMIT  size limit of the file in bytes
          DIO  access backing file with direct-io
      LOG-SEC  logical sector size in bytes

For more details see losetup(8).
tc@E310:~$

Quote
... Perhaps a diff between piCore v9 vs v11? ...
I don't have any Pi hardware. I just happened to select a piCore v9 image to see what's involved in mounting it. I'm using x86
hardware running TC10.
The  losetup  program is present in  util-linux:
http://tinycorelinux.net/11.x/armv6/tcz/util-linux.tcz.list

Quote
... I was able to do it without it in ubuntu, I guess it must be figuring out the end of the partition by itself cuz your explanation makes sense. ...
It just occurred to me the  busybox mount  command might not work either. So I tried it, and it doesn't. Another look at:
http://tinycorelinux.net/11.x/armv6/tcz/util-linux.tcz.list
shows that the  mount  command is missing from this extension. I searched all of the other extensions in the repository and the
mount  command didn't show up in any of them.

The  mount  command was last present here:
http://tinycorelinux.net/7.x/armv6/tcz/util-linux.tcz.list

Looking here shows why  mount  is missing:
http://tinycorelinux.net/8.x/armv6/tcz/src/util-linux/util-linux.build
It includes the following commands:
Code: [Select]
# Remove files part of base

rm -f $TMPDIR/usr/local/lib/libblkid.*
rm -f $TMPDIR/usr/local/lib/libuuid.*
rm -f $TMPDIR/usr/local/lib/libmount.*

rm -f $TMPDIR/usr/local/sbin/blkid

rm -f $TMPDIR/usr/local/bin/mount
rm -f $TMPDIR/usr/local/bin/umount

rm -f $TMPDIR/usr/local/lib/pkgconfig/blkid.pc
rm -f $TMPDIR/usr/local/lib/pkgconfig/uuid.pc
rm -f $TMPDIR/usr/local/lib/pkgconfig/mount.pc

rm -r -f $TMPDIR/usr/local/include/blkid
rm -r -f $TMPDIR/usr/local/include/uuid
rm -r -f $TMPDIR/usr/local/include/libmount

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 617
Re: Mounting disk image fails
« Reply #6 on: July 17, 2020, 08:21:29 AM »
Busybox mount has been problematic in the past, it seems to change every release....   11.x is using busybox mount, so we'll need to add the full mount/libmount back to util-linux.   My build system is in a toolchain build configuration right now, so it might take a few days to rebuild...
« Last Edit: July 17, 2020, 08:23:04 AM by Paul_123 »

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #7 on: July 17, 2020, 12:30:19 PM »
Hi ashfame
... That's exactly what I installed and it still gave me that error. ...
Are you sure? You said:
...  I get an error "losetup: unrecognized option --show. Busybox v1.31.1" and for --find too, ...
If  util-linux.tcz  was installed, it should have defaulted to  /usr/local/sbin/losetup  instead of the  busybox version. What does this return:
Code: [Select]
tce-load -i util-linux
which losetup

Yeah, tce-load tells me its already installed and which losetup points me to /usr/local/sbin/losetup



If you use the  --help  parameter you should see something like this:
Code: [Select]
tc@E310:~$ losetup --help

Usage:
 losetup [options] [<loopdev>]
 losetup [options] -f | <loopdev> <file>

Set up and control loop devices.

Options:
 -a, --all                     list all used devices
 -d, --detach <loopdev>...     detach one or more devices
 -D, --detach-all              detach all used devices
 -f, --find                    find first unused device
 -c, --set-capacity <loopdev>  resize the device
 -j, --associated <file>       list all devices associated with <file>
 -L, --nooverlap               avoid possible conflict between devices

 -o, --offset <num>            start at offset <num> into file
     --sizelimit <num>         device is limited to <num> bytes of the file
 -b  --sector-size <num>       set the logical sector size to <num>
 -P, --partscan                create a partitioned loop device
 -r, --read-only               set up a read-only loop device
     --direct-io[=<on|off>]    open backing file with O_DIRECT
     --show                    print device name after setup (with -f)
 -v, --verbose                 verbose mode

 -J, --json                    use JSON --list output format
 -l, --list                    list info about all or specified (default)
 -n, --noheadings              don't print headings for --list output
 -O, --output <cols>           specify columns to output for --list
     --raw                     use raw --list output format

 -h, --help                    display this help
 -V, --version                 display version

Available output columns:
         NAME  loop device name
    AUTOCLEAR  autoclear flag set
    BACK-FILE  device backing file
     BACK-INO  backing file inode number
 BACK-MAJ:MIN  backing file major:minor device number
      MAJ:MIN  loop device major:minor number
       OFFSET  offset from the beginning
     PARTSCAN  partscan flag set
           RO  read-only device
    SIZELIMIT  size limit of the file in bytes
          DIO  access backing file with direct-io
      LOG-SEC  logical sector size in bytes

For more details see losetup(8).
tc@E310:~$

Yep, I see this when I do losetup --help

but now trying the mount command says can't find an unused loop device,

Quote
... Perhaps a diff between piCore v9 vs v11? ...
I don't have any Pi hardware. I just happened to select a piCore v9 image to see what's involved in mounting it. I'm using x86
hardware running TC10.
The  losetup  program is present in  util-linux:
http://tinycorelinux.net/11.x/armv6/tcz/util-linux.tcz.list

Quote
... I was able to do it without it in ubuntu, I guess it must be figuring out the end of the partition by itself cuz your explanation makes sense. ...
It just occurred to me the  busybox mount  command might not work either. So I tried it, and it doesn't. Another look at:
http://tinycorelinux.net/11.x/armv6/tcz/util-linux.tcz.list
shows that the  mount  command is missing from this extension. I searched all of the other extensions in the repository and the
mount  command didn't show up in any of them.

The  mount  command was last present here:
http://tinycorelinux.net/7.x/armv6/tcz/util-linux.tcz.list

Looking here shows why  mount  is missing:
http://tinycorelinux.net/8.x/armv6/tcz/src/util-linux/util-linux.build
It includes the following commands:
Code: [Select]
# Remove files part of base

rm -f $TMPDIR/usr/local/lib/libblkid.*
rm -f $TMPDIR/usr/local/lib/libuuid.*
rm -f $TMPDIR/usr/local/lib/libmount.*

rm -f $TMPDIR/usr/local/sbin/blkid

rm -f $TMPDIR/usr/local/bin/mount
rm -f $TMPDIR/usr/local/bin/umount

rm -f $TMPDIR/usr/local/lib/pkgconfig/blkid.pc
rm -f $TMPDIR/usr/local/lib/pkgconfig/uuid.pc
rm -f $TMPDIR/usr/local/lib/pkgconfig/mount.pc

rm -r -f $TMPDIR/usr/local/include/blkid
rm -r -f $TMPDIR/usr/local/include/uuid
rm -r -f $TMPDIR/usr/local/include/libmount

Ok, I guess I will go back to running this on ubuntu box for now and do other customizations before this is fixed as Paul said?

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #8 on: July 17, 2020, 12:30:53 PM »
Busybox mount has been problematic in the past, it seems to change every release....   11.x is using busybox mount, so we'll need to add the full mount/libmount back to util-linux.   My build system is in a toolchain build configuration right now, so it might take a few days to rebuild...

Hi Paul,

Let me know when you do have an update for us :)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8104
Re: Mounting disk image fails
« Reply #9 on: July 17, 2020, 12:49:54 PM »
Hi ashfame
... Ok, I guess I will go back to running this on ubuntu box for now and do other customizations before this is fixed as Paul said?
Or you could do it on an x86 box running Tinycore.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #10 on: July 17, 2020, 03:39:05 PM »
Hi ashfame
... Ok, I guess I will go back to running this on ubuntu box for now and do other customizations before this is fixed as Paul said?
Or you could do it on an x86 box running Tinycore.

Hi Rich, I have been doing this on an x86 box running Tinycore in virtualbox only. This topic was entirely about that. My first post says so too.

It was only few days back, when you mentioned file permissions might be an issue while remastering if I am not doing it on TC, that I tried running my script (generate the final disk image off piCore disk img) on TC which I initially wrote on/for ubuntu. So that's why I mentioned I might as well go back to Ubuntu to continue building my bash script to make further changes, while mount command gets fixed in util-linux.tcz

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12385
Re: Mounting disk image fails
« Reply #11 on: July 18, 2020, 10:11:14 PM »
updated util-linux posted

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 8104
Re: Mounting disk image fails
« Reply #12 on: July 26, 2020, 01:31:36 PM »
Hi ashfame
It seems I owe you an apology.
... Yep, I see this when I do losetup --help

but now trying the mount command says can't find an unused loop device, ...
I guessing you meant the  losetup  command. I just tried following my instructions in reply #5:
http://forum.tinycorelinux.net/index.php/topic,24063.msg151721.html#msg151721

I too received a  "can't find an unused loop device"  message. So I created a couple of loop devices and it worked, or so I thought.
The device it created did not have separate partitions so it could not be properly accessed.

After some puzzling, I decided to reboot the machine and try again. Same results. Then I noticed the  lsblk  commands had  sudo  in
front of them, which doesn't sound necessary. So I tried  sudo losetup ...  and everything worked correctly. This would have been
much more obvious had the  losetup  command printed out a  Permission denied  message. Reply #5 has been corrected.

  Sorry for any problems this may have caused you.

Offline ashfame

  • Full Member
  • ***
  • Posts: 112
Re: Mounting disk image fails
« Reply #13 on: July 31, 2020, 05:03:19 AM »
Hi ashfame
It seems I owe you an apology.
... Yep, I see this when I do losetup --help

but now trying the mount command says can't find an unused loop device, ...
I guessing you meant the  losetup  command. I just tried following my instructions in reply #5:
http://forum.tinycorelinux.net/index.php/topic,24063.msg151721.html#msg151721

I too received a  "can't find an unused loop device"  message. So I created a couple of loop devices and it worked, or so I thought.
The device it created did not have separate partitions so it could not be properly accessed.

After some puzzling, I decided to reboot the machine and try again. Same results. Then I noticed the  lsblk  commands had  sudo  in
front of them, which doesn't sound necessary. So I tried  sudo losetup ...  and everything worked correctly. This would have been
much more obvious had the  losetup  command printed out a  Permission denied  message. Reply #5 has been corrected.

  Sorry for any problems this may have caused you.

Hi Rich, thanks for letting me know! No apologies necessary :)

You are right, that wasn't an obvious error. Glad its sorted. Currently, modifying the image and setting user permissions on it afterwards have been working well :)