execution of update-grub in chroots might fail
[Please Cc me on replies as I'm not subscribed to the ML but read/write through gmane. Thanks]
Hi,
as reported in #550337 update-grub might fail inside chroots. I'm providing detailed information about this issue in this mail as discussed on IRC in #grub.
Situation
=========
For example postinst of memtest86+ uses:
if [ "$1" = "configure" ] && [ -x "`which update-grub2 2>/dev/null`" ] ; then
update-grub2
fiwhich is the recommended and suggested way to install grub menu entries.
Problem
=======
When executing update-grub the command might fail. For example it *does* fail inside chroots on openvz containers (see end of mail for full details regarding the setup in question):
# update-grub2 grub-probe: error: cannot find a device for /.
Then the installation of for example the memtest86+ package fails. Recommended fixes were (binded) mounting /proc, /sys and /dev, though this is already present and doesn't help.
The problem is NOT the grub package itself (it installs and updates just fine). The problem exists in packages that call update-grub but don't have a clean interface *when* (and how) to execute it. See #481468 and #550337 for example.
Affected: The problem affects at least (verified) current Debian/unstable and Debian/testing.
Rationale
=========
People having to deal with chroots for deployments or building live systems usually want to ship grub as bootloader. Then grub needs to be installed as *package* inside the chroot *without* the need for an existing grub.cfg and having grub in the boot sector of any physical device of the build system. Instead grub is being used as bootloader on the later deployed system/live system instead. So grub being installed in a chroot without directly accessing/using it there is necessary and common practice. This works for the grub package itself just fine, but fails for any package that wants to install additional menu files through update-grub.
Implementing the according logic (when to execute update-grub and when not) inside the non-grub packages isn't a reasonable approach IMHO because it would require changes in *any* single package as soon as *something* needs to be changed, instead of adjusting just the interface script once when necessary.
What I'm searching for
======================
An official and clean way how packages can interact with grub without failing in situations like the mentioned openvz setup.
Addon: It would be nice if there's a way to skip grub commands inside chroots completely (and that there's no need for mount --bind of /dev). It's often not needed as the hardware of the chroot doesn't match the system where grub is finally being used (for example also see #538118).
Possible solutions
==================
1) Maintainer scripts of non-grub packages use 'update-grub || true' so the grub-probe call doesn't cause the package to fail its installation (which doesn't affect chroots only but is just a workaround then).
2) The grub package provides a way to disable any grub related commands like update-grub, grub-install,... so they can be just called by the maintainer scripts of non-grub packages without having to deal with situations like openvz. (Could be realized by preseeding and/or a configuration file.) Could be combined with a dpkg trigger.
3) grub-probe learns how to deal with the openvz situation (though this might fail in other similar and existing situations and doesn't really solve the interface issue AFAICT).
4) The grub package provides an official interface to update-grub for maintainer scripts. Like policy-rc.d exists for invoke-rc.d a specific interface for grub would provide maintainers as well as admins a way to configure grub setup and its command execution according to their needs. Could be combined with a dpkg trigger as well.
Details regarding /proc/mounts of the setup in question
=======================================================
On the host system:
# mount /dev/md1 on / type ext3 (rw,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) procbususb on /proc/bus/usb type usbfs (rw) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) # cat /proc/mounts none /sys sysfs rw,nosuid,nodev,noexec 0 0 none /proc proc rw,nosuid,nodev,noexec 0 0 udev /dev tmpfs rw,size=10240k,mode=755 0 0 /dev/md1 / ext3 rw,errors=remount-ro,data=ordered 0 0 tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0 usbfs /proc/bus/usb usbfs rw,nosuid,nodev,noexec 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /dev/pts devpts rw,nosuid,noexec,gid=5,mode=620 0 0 /var/lib/vz/private/3000 /var/lib/vz/root/3000 simfs rw 0 0 tmpfs /var/lib/vz/root/3000/lib/init/rw tmpfs rw,nosuid,mode=755 0 0 proc /var/lib/vz/root/3000/proc proc rw,nosuid,nodev,noexec 0 0 sysfs /var/lib/vz/root/3000/sys sysfs rw,nosuid,nodev,noexec 0 0 tmpfs /var/lib/vz/root/3000/dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /var/lib/vz/root/3000/dev/pts devpts rw,nosuid,noexec,gid=5,mode=620 0 0 [...]
Inside the openvz container:
# vzctl enter 3001 entered into VE 3001 # mount tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) simfs on / type simfs (rw) # cat /proc/mounts simfs / simfs rw 0 0 tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0 proc /proc proc rw,nosuid,nodev,noexec 0 0 sysfs /sys sysfs rw,nosuid,nodev,noexec 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /dev/pts devpts rw,nosuid,noexec,mode=600 0 0
Inside the chroot:
# mount --bind /dev /grml/grml-live/grml_chroot/dev # chroot /grml/grml-live/grml_chroot # mount -t proc none /proc # mount -t sysfs none /sys # mount sysfs on /sys type sysfs (rw) none on /proc type proc (rw) none on /sys type sysfs (rw) # cat /proc/mounts simfs /dev simfs rw 0 0 none /proc proc rw 0 0 none /sys sysfs rw 0 0
=====================================================================================
If I can provide any further information/help/... please let me know, I can easily reproduce the above mentioned issue.
-mika-
Quoted 3 lines · Michael Prokop
as reported in #550337 update-grub might fail inside chroots. I'm providing detailed information about this issue in this mail as discussed on IRC in #grub.
[...]
Quoted 4 lines
The problem is NOT the grub package itself (it installs and updates just fine). The problem exists in packages that call update-grub but don't have a clean interface *when* (and how) to execute it. See #481468 and #550337 for example.
[...]
Sorry for not being explicit enough: the mentioned bug ids refer to Debian's bug tracking system, so
#550337 refers to http://bugs.debian.org/550337
#481468 refers to http://bugs.debian.org/481468
#550337 refers to http://bugs.debian.org/550337
etc.
regards,
-mika-
Quoted 3 lines · Michael Prokop
as reported in #550337 update-grub might fail inside chroots. I'm providing detailed information about this issue in this mail as discussed on IRC in #grub.
update-grub is actually a Debian-specific wrapper around grub-mkconfig. While some of the issues you raise might be fixed in grub-mkconfig, I think that the necessary change may well actually be in the Debian packaging.
Quoted 10 lines
Situation
=========For example postinst of memtest86+ uses:
if [ "$1" = "configure" ] && [ -x "`which update-grub2 2>/dev/null`" ] ; then update-grub2 fiwhich is the recommended and suggested way to install grub menu entries.
Recommended where? (This implies the existence of documentation on the subject, which I wasn't aware of ...)
Quoted 10 lines
Problem
=======When executing update-grub the command might fail. For example it *does* fail inside chroots on openvz containers (see end of mail for full details regarding the setup in question):
# update-grub2 grub-probe: error: cannot find a device for /.
Quoted 8 lines
Then the installation of for example the memtest86+ package fails. Recommended fixes were (binded) mounting /proc, /sys and /dev, though this is already present and doesn't help.
The problem is NOT the grub package itself (it installs and updates just fine). The problem exists in packages that call update-grub but don't have a clean interface *when* (and how) to execute it. See #481468 and #550337 for example.
The simplest fix is to add '&& [ -e /boot/grub/grub.cfg ]' to the test in memtest86+; that is, if the configuration file hasn't been generated already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as for other reasons why GRUB might not actually be being used as a boot loader.
You're right that it is suboptimal that every package has to implement the check itself. My instinct is that the semantics of update-grub ought to change slightly, so that it really is an *update* - that is, it shouldn't by default generate a configuration file if there isn't one already. It could have a --force option (or better name?) for convenience, for use by the grub2 packaging itself, and for use by the installer. Anything much more complex than that smells of overengineering to me.
Note, though, that care would need to be taken to ensure that grub-installer is changed in step; it's important to minimise the chances of consequential installer brokenness. There's little urgency on this so we could afford the time for a proper transition. For example, update-grub could accept but ignore the new option for a while; then, after the relevant version of grub2 has moved to testing, grub-installer could be updated to use it; then, at some later point, the default semantics of update-grub could change.
If that's too complicated, we could just add an --if-exists option or something that does what memtest86+ and other similar packages need. There are very few packages in this boat, so it may not be worth very much effort to deal with them.
Robert, Felix, what do you think?
Signature · 1 line
Colin Watson [[email protected]]
Am Montag, den 14.12.2009, 11:56 +0000 schrieb Colin Watson:
Quoted 5 lines · Michael Prokop
Quoted 3 lines
For example postinst of memtest86+ uses:
if [ "$1" = "configure" ] && [ -x "`which update-grub22>/dev/null`" ] ; then
Quoted 8 lines
Quoted 4 lines
update-grub2
fiwhich is the recommended and suggested way to install grub menu
entries.
Recommended where? (This implies the existence of documentation on the subject, which I wasn't aware of ...)
I wonder too why he wrote that. When I talked with him on IRC yesterday, I mainly said that using `update-grub || true' would be wrong. And neither me nor Robert (at leat until I was on IRC which was though later then he wrote this mail) not at all anything that says there's a written policy for interacting with GRUB things or even that the above thing is the recommended and suggested way.
Quoted 20 lines
Quoted 7 lines
Problem
=======When executing update-grub the command might fail. For example it *does* fail inside chroots on openvz containers (see end of mail for full details regarding the setup in question):
Quoted 5 lines
# update-grub2 grub-probe: error: cannot find a device for /.Then the installation of for example the memtest86+ package fails. Recommended fixes were (binded) mounting /proc, /sys and /dev,
though
Quoted 6 lines
this is already present and doesn't help.
The problem is NOT the grub package itself (it installs and updates just fine). The problem exists in packages that call update-grub but don't have a clean interface *when* (and how) to execute it. See #481468 and #550337 for example.
Quoted 8 lines
The simplest fix is to add '&& [ -e
/boot/grub/grub.cfg]' to the test in memtest86+; that is, if the configuration file hasn't been generated
already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as for
other reasons why GRUB might not actually be being used as a boot loader.
We have alredy changed our postinst some time ago to only execute when either grub.cfg already exists or when grub-install gets run in the postinst.
Quoted 21 lines
You're right that it is suboptimal that every package has to implement the check itself. My instinct is that the semantics of update-grub ought
to change slightly, so that it really is an *update* - that is, it shouldn't by default generate a configuration file if there isn't one already. It could have a --force option (or better name?) for convenience, for use by the grub2 packaging itself, and for use by the installer. Anything much more complex than that smells of overengineering to me.Note, though, that care would need to be taken to ensure that grub-installer is changed in step; it's important to minimise the chances of consequential installer brokenness. There's little urgency on
this so we could afford the time for a proper transition. For example, update-grub could accept but ignore the new option for a while; then, after the relevant version of grub2 has moved to testing, grub-installer
could be updated to use it; then, at some later point, the default semantics of update-grub could change.
Quoted 7 lines
If that's too complicated, we could just add an --if-exists option or something that does what memtest86+ and other similar packages need. There are very few packages in this boat, so it may not be worth very much effort to deal with them.
Robert, Felix, what do you think?
Why so complicated?
We use just `touch /boot/grub/grub.cfg' in the grub-pc/install_devices part and then at the end of postinst we check if it exists and then run update-grub
The same could be done in grub-installer now without needing to modify anything else.
Sad that we can't make update-grub a trigger. At least as long as nobody comes up with a great solution which makes sure the system is always bootable even if it's not run or that the trigger is always run even if the dpkg/apt run aborts.
Then we could control when update-grub gets run in our postinst instead of every package which wants/needs to run it.
Then if we add a check for grub.cfg in the update-grub stub, the only question is if we should print a warning that it doestn't do anything or not in case grub.cfg doesn't exist.
Signature · 2 lines
Felix Zielcke Proud Debian Maintainer and GNU GRUB developer
Quoted 13 lines · Felix Zielcke
Am Montag, den 14.12.2009, 11:56 +0000 schrieb Colin Watson:
Quoted 11 lines · Michael Prokop
Quoted 7 lines
For example postinst of memtest86+ uses:
if [ "$1" = "configure" ] && [ -x "`which update-grub2 >> 2>/dev/null`" ] ; then update-grub2 fiwhich is the recommended and suggested way to install grub menu entries.
Recommended where? (This implies the existence of documentation on the subject, which I wasn't aware of ...)
Quoted 6 lines
I wonder too why he wrote that. When I talked with him on IRC yesterday, I mainly said that using `update-grub || true' would be wrong. And neither me nor Robert (at leat until I was on IRC which was though later then he wrote this mail) not at all anything that says there's a written policy for interacting with GRUB things or even that the above thing is the recommended and suggested way.
Sorry, my fault for not being specific enough. I just meant update-grub itself, nothing else. I was refering to:
18:10:29< nyu> mika: it's intentional. it means add-on packages are free to run update-grub to plug their stuff in
Quoted 6 lines
Quoted 6 lines
The simplest fix is to add '&& [ -e
/boot/grub/grub.cfg]' to the test in memtest86+; that is, if the configuration file hasn't been generated already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as for other reasons why GRUB might not actually be being used as a boot loader.
Is the memtest86+ maintainer of Debian aware of this (at least temporary but working) solution or should I ping him?
regards,
-mika-
Am Montag, den 14.12.2009, 13:36 +0100 schrieb Michael Prokop:
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
The simplest fix is to add '&& [ -e
/boot/grub/grub.cfg]' to the test in memtest86+; that is, if the configuration file hasn't been generated already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as for other reasons why GRUB might not actually be being used as a boot loader.
Quoted 5 lines
Is the memtest86+ maintainer of Debian aware of this (at least temporary but working) solution or should I ping him?
regards,
-mika-
I doubt he is if that has not been mentioned in any memtest86 or memtest86+ (He maintains both) bug reports.
Signature · 2 lines
Felix Zielcke Proud Debian Maintainer and GNU GRUB developer
Quoted 2 lines · Colin Watson
The simplest fix is to add '&& [ -e
/boot/grub/grub.cfg]' to the test in memtest86+;
Uhm should we make this check part of update-grub? Or even part of grub-mkconfig?
Quoted 24 lines
that is, if the configuration file hasn't been generated already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as for other reasons why GRUB might not actually be being used as a boot loader.
You're right that it is suboptimal that every package has to implement the check itself. My instinct is that the semantics of update-grub ought to change slightly, so that it really is an *update* - that is, it shouldn't by default generate a configuration file if there isn't one already. It could have a --force option (or better name?) for convenience, for use by the grub2 packaging itself, and for use by the installer. Anything much more complex than that smells of overengineering to me.
Note, though, that care would need to be taken to ensure that grub-installer is changed in step; it's important to minimise the chances of consequential installer brokenness. There's little urgency on this so we could afford the time for a proper transition. For example, update-grub could accept but ignore the new option for a while; then, after the relevant version of grub2 has moved to testing, grub-installer could be updated to use it; then, at some later point, the default semantics of update-grub could change.
Quoted 6 lines
If that's too complicated, we could just add an --if-exists option or something that does what memtest86+ and other similar packages need. There are very few packages in this boat, so it may not be worth very much effort to deal with them.
Robert, Felix, what do you think?
I think it's fine to make this update conditional. My only concern is that external packages have a mechanism to add their stuff into grub.cfg (this was one of the key motivations for initial grub-mkconfig design).
Signature · 3 lines
Robert Millan "Be the change you want to see in the world" -- Gandhi
Am Donnerstag, den 24.12.2009, 22:28 +0100 schrieb Robert Millan:
Quoted 7 lines · Colin Watson
Quoted 1 line
The simplest fix is to add '&& [ -e
/boot/grub/grub.cfg]' to thetest
Quoted 1 line
in memtest86+;
Uhm should we make this check part of update-grub? Or even part of grub-mkconfig?
I don't think grub-mkconfig should check for that. And if it does then we should make it optional by adding something like --update as option to it.
If people of other distributions compile GRUB 2 they should be able to just use grub-mkconfig directly to create their initial config without much hassle.
Quoted 40 lines
Quoted 3 lines
that is, if the configuration file hasn't been generated already, it shouldn't be updated. (This check is in the memtest86+ postinst in Ubuntu.) This accounts for the OpenVZ problem as well as
for
Quoted 4 lines
other reasons why GRUB might not actually be being used as a boot loader.
You're right that it is suboptimal that every package has to
implement
Quoted 1 line
the check itself. My instinct is that the semantics of update-grub
ought
Quoted 2 lines
to change slightly, so that it really is an *update* - that is, it shouldn't by default generate a configuration file if there isn't
one
Quoted 2 lines
already. It could have a --force option (or better name?) for convenience, for use by the grub2 packaging itself, and for use by
the
Quoted 6 lines
installer. Anything much more complex than that smells of overengineering to me.
Note, though, that care would need to be taken to ensure that grub-installer is changed in step; it's important to minimise the chances of consequential installer brokenness. There's little
urgency on
Quoted 1 line
this so we could afford the time for a proper transition. For
example,
Quoted 1 line
update-grub could accept but ignore the new option for a while;
then,
Quoted 1 line
after the relevant version of grub2 has moved to testing,
grub-installer
Quoted 4 lines
could be updated to use it; then, at some later point, the default semantics of update-grub could change.
If that's too complicated, we could just add an --if-exists option
or
Quoted 2 lines
something that does what memtest86+ and other similar packages need. There are very few packages in this boat, so it may not be worth
very
Quoted 2 lines
much effort to deal with them.
Quoted 8 lines
Quoted 1 line
Robert, Felix, what do you think?
I think it's fine to make this update conditional. My only concern is that
external packages have a mechanism to add their stuff into grub.cfg (this
was one of the key motivations for initial grub-mkconfig design).
In Debian at least they probable all rely that grub-pc etc. is installed first.
If you have grub2 installed but no config then you probable don't want that e.g. memtest86+ suddenly creates it.
Signature · 2 lines
Felix Zielcke Proud Debian Maintainer and GNU GRUB developer