Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount -a fails to use UUID if /proc and /sys are to be mounted #1492

Closed
stsp opened this issue Nov 4, 2021 · 17 comments
Closed

mount -a fails to use UUID if /proc and /sys are to be mounted #1492

stsp opened this issue Nov 4, 2021 · 17 comments

Comments

@stsp
Copy link

stsp commented Nov 4, 2021

I am using buildroot with mount from util-linux-2.37.2, libmount 2.37.2.
When my fstab contains UUIDs,
mount at boot fails to find them.
After some experimenting, it seems
that it would need /proc or /sys to
find device by UUID. And the fact
is, that exact "mount -a" at boot is
used to mount /proc and /sys.
So if they were already mounted,
then UUID look-up succeeds. If
they are to be mounted by the
same "mount -a", then UUID fails.

I don't think I've seen this problem
on earlier versions. I suspect
"mount -a" should delay the UUID/LABEL
mounts to the last step, so that
/proc and /sys are always mounted
first.

stsp added a commit to dosemu2/fdpp-buildroot that referenced this issue Nov 4, 2021
Added work-arond for this problem:
util-linux/util-linux#1492
@karelzak
Copy link
Collaborator

And the fact is, that exact "mount -a" at boot is used to mount /proc and /sys."

I don't think so. If I remember classic init scripts then /proc and /sys are always mounted by separate mount(8) calls before mount -a.

The libmount uses libblkid to evaluate the tags (UUID= or LABEL=). The libblkid uses udevd symlinks in /dev/disk/by-* and if not available then it reads /sys to get a list of block devices to scan for the tags. The old versions (before v2.37) use /proc/partitions rather than /sys. Anyway, this dependence on /proc is there for more than 15 years ...

mount -a also uses /proc/self/mountinfo to ignore already mounted filesystems.

Please, use

  mount -t proc proc /proc
  mount -t sysfs sysfs /sys

in your scripts before mount -a. Note that /proc and /sys are often already mounted in initrd.

I don't see any elegant way how to improve it. It would be possible to scan all /dev and try all block devices, but it does not make sense if the kernel provides /sys with all the information.

And postpone UUID= until you get /proc and /sys is against mount -a semantic as it always follows fstab order.

karelzak added a commit that referenced this issue Nov 16, 2021
Addresses: #1492
Signed-off-by: Karel Zak <kzak@redhat.com>
@karelzak
Copy link
Collaborator

Closing, not a bug.

@stsp
Copy link
Author

stsp commented Nov 16, 2021

OK, thanks for you time.
I'll report that to buildroot then.

@stsp
Copy link
Author

stsp commented Nov 16, 2021

And postpone UUID= until you get /proc and /sys is against mount -a semantic as it always follows fstab order.

Hmm, then we actually have
a bug here. The fstab in question:

# <file system> <mount pt>      <type>  <options>       <dump>  <pass>
/dev/root       /               ext2    rw,noauto       0       1
proc            /proc           proc    defaults        0       0
devpts          /dev/pts        devpts  defaults,gid=5,mode=620,ptmxmode=0666
0       0
tmpfs           /dev/shm        tmpfs   mode=0777       0       0
tmpfs           /tmp            tmpfs   mode=1777       0       0
tmpfs           /run            tmpfs   mode=0755,nosuid,nodev  0       0
sysfs           /sys            sysfs   defaults        0       0
UUID="8f1b147f-2756-4d08-bd92-217fff11b182" /mnt/drive_c ext4 rw,nodev,nosuid,no
exec,noatime 0 0

As you can see, /sys is mounted
BEFORE UUID.
And yet that doesn't work.
So should this be re-opened?

@stsp
Copy link
Author

stsp commented Nov 16, 2021

So to be clear:
even if you have /proc and /sys
in fstab before UUID usage, you
still can't use "mount -a" alone.
So why is that?

@karelzak
Copy link
Collaborator

So to be clear: even if you have /proc and /sys in fstab before UUID usage, you still can't use "mount -a" alone. So why is that?

That's a good question. I need to test it with "LIBMOUNT_DEBUG=all LIBBLKID_DEBUG=all mount --all".

@karelzak karelzak reopened this Nov 16, 2021
@karelzak
Copy link
Collaborator

I guess (not tested yet) the problem is

       /* ignore already mounted filesystems */
        rc = mnt_context_is_fs_mounted(cxt, *fs, &mounted);
        if (rc) 
            return rc;

in libmount/src/context_mount.c:mnt_context_next_mount(). There we need to care about situations related to missing /proc or /sys and ignore 'rc' in this case.

@stsp
Copy link
Author

stsp commented Nov 16, 2021

I can test the patch if you want.

karelzak added a commit that referenced this issue Nov 18, 2021
Now 'mount --all' ends with error if /proc is not mounted and there is
some other entry before /proc in fstab. This commit improves this
situation and ignores all mount table related errors if the table is
empty.

This is important for situation when there is for example "/" as the
first line in fstab.

Addresses: #1492
Signed-off-by: Karel Zak <kzak@redhat.com>
@karelzak
Copy link
Collaborator

The problem should be fixed in the git "master" branch. I have tested it in chroot it works for me ;-)

@stsp
Copy link
Author

stsp commented Nov 18, 2021

I applied that specific patch
to 2.37.2 and nothing changed.
I don't think you fixed my problem
also judging from the patch description.
There is no empty mount table in
my case, because buildroot mounts
proc and devtmpfs by hands, before
"mount -a". The only thing that is
missing at the "mount -a" point, is
sysfs. I don't see why this patch
would address that sysfs problem.

@karelzak
Copy link
Collaborator

Well, if /proc is not mounted then the mount table is empty (in libmount).

Can you try "LIBMOUNT_DEBUG=all LIBBLKID_DEBUG=all mount --all for your use-case?

@karelzak
Copy link
Collaborator

... and it would be better to try the current git, not only the patch.

@stsp
Copy link
Author

stsp commented Nov 18, 2021

But /proc IS mounted, because,
as I said, buildroot mounts /proc
and /dev before anything else.
The problem is ONLY unmounted
sysfs.
So should I still do the aforementioned
logging?

@karelzak
Copy link
Collaborator

I probably see where is the issue. There is a cache in libblkid and it does not re-read the cache.

karelzak added a commit that referenced this issue Nov 19, 2021
For "mount --all" we need to read the cache more than once in a short
time. The library checks the delay between probes, and if the delay is
too short, it does not read devices. This is a problem on boot when there
are no /sys, and the cache is empty. In this case, we need to check
for /sys until it's available constantly.

#1492
Signed-off-by: Karel Zak <kzak@redhat.com>
@stsp
Copy link
Author

stsp commented Nov 20, 2021

Sorry, github only posted the comment
via email, but not the fact that the patch
is here, so I didn't know.

Now I tested it and it works, thank you!

The library checks the delay between probes, and if the delay is
too short, it does not read devices.

OMG, nothing is deterministic
these days...

@karelzak
Copy link
Collaborator

karelzak commented Nov 22, 2021

Thanks for your report, test, and patience! ;-) It will be fixed in the next release.

@stsp
Copy link
Author

stsp commented Nov 22, 2021

Good to know, thanks. :)
Note that buildroot already took
your patch, so if by "will be fixed
in the next release" you mean
something else than what is
in the current patch, then
please speak up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants