Bug#918700: grub2-common: update-grub fails with bogus error messages if it doesn't like the current dir

Colin Watson cjwatson at debian.org
Tue Jan 8 22:16:48 GMT 2019


On Wed, Jan 09, 2019 at 12:05:53AM +1100, Russell Coker wrote:
> Below is one example of the problem.  A trivial fix for this sort of problem
> would be to have the /usr/sbin/update-grub shell script do "cd /" before
> running grub-mkconfig (as update-grub is the documented way of doing things
> on Debian).  But a better solution would be to make grub-mkconfig either give
> useful error messages, or even better just not care about whether it can read
> the current directory.

This is in grub-probe, which is called by grub-mkconfig.  It's searching
/dev for a device, and doing that by changing to each directory as it
goes, which means it needs to save the initial directory so that it can
change back at the end.

The reason for this is opaque, because it goes back to the original
addition of the relevant section of code in the early days of GRUB 2,
but I'm going to guess that it's a performance optimisation to reduce
repeated path lookups; there can be quite a lot of inodes in /dev and
grub-probe can be quite slow as it is, so it's possible that this could
actually be worthwhile.

The ideal approach these days is probably to use the *at family of
syscalls where they're available, which would preserve the efficiency
gain without having to save and restore the current directory.  It would
take a bit of work, especially since that code is used on more than just
Linux, but shouldn't be prohibitively difficult.

However, since GRUB already uses Gnulib, a quicker fix would be to use
its save-cwd module, which knows how to use open/fchdir rather than
getcwd/chdir on systems that support it.

-- 
Colin Watson                                       [cjwatson at debian.org]



More information about the Pkg-grub-devel mailing list