Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
we have lots of dual-boot installations (Linux/Windows), all of them booting via grub. Often it would be very handy if admins could control the default boot behavior for subsequent unattended reboots from a central network location, e.g. from an PXE or web server.
Is there any way to make grub read its grub.cfg from a central network location (instead of /boot/grub) or to fetch its default declaration (normally 'set default="0"') from an url?
P.S. I already tried
Code:
set default=$( curl http://myserver.mydomain /boot/grub/$HOSTNAME )
which resolves fine at the running system, but as you might expect, not during grub's early stage.
Thinking more about it, one might speculate that grub just doesn't build up full TCP/IP network functionality but remains somewhat limited to ARP/MAC level and DHCP only. But even that would be all right: In order to receive nothing more than just a simple integer value from the server (i.e. the currently desired default boot option), a DHCP parameter and TFTP should also be sufficient. However, this value would have to be taken into account when evaluating the grub.cfg, and I couldn't find anything on this issue in the docs.
Unfortunately, as this is not my main area of expertise, so I hope that we can find a solution here together. I'm quite sure that would be useful for a lot of people. (Maybe that's why it would make sense to make a feature request - would http://savannah.gnu.org/bugs/?group=grub be the right place for it? There are only bug reports, no suggestions.)
Other possibilities , unfortunately, range from less attractive to completely unusable: Replacing the file via SSH is more cumbersome than maintaining a central configuration, and especially not possible when Windows is running (and needs several reboots into the same OS, for example).
Last edited by devdol; 09-14-2018 at 04:15 AM.
Reason: clarification
Unfortunately, as this is not my main area of expertise, so I hope that we can find a solution here together. I'm quite sure that would be useful for a lot of people. (Maybe that's why it would make sense to make a feature request - would http://savannah.gnu.org/bugs/?group=grub be the right place for it? There are only bug reports, no suggestions.)
I don't know but yes, I think you should suggest it.
Quote:
Other possibilities , unfortunately, range from less attractive to completely unusable: Replacing the file via SSH is more cumbersome than maintaining a central configuration, and especially not possible when Windows is running (and needs several reboots into the same OS, for example).
So another way to do it: make the computers always boot on GNU/Linux. Create a script that read a value inside a file on the network. This script will be launched at GNU/Linux boot. Put in this file the system you want to boot, by it's name, a number, a code, whatever! You will catch this value in your script. If the value is "m$" for example, send the order to reboot on the m$ entry. I don't remember how, but I know that Grub can do it.
is it possible to determine what the next reboot should be like at shutdown?
if so, i once had a script that would directly edit grub.cfg to choose which OS it will boot into. it's very simple, just some sed iirc (script is long gone, i don't dual boot anymore).
another wild idea: boot grub from net (PXE?), then piont it back to opne of the OSs on the local machine it is called form.
in any case, there seems to be a lot to try out in this, did you? what works, what doesn't?
A more detailed answer: the entry "GRUB_DEFAULT=<zero-based integer>", which is not accessible from Windows at all and can only be changed from Linux by calling "update-grub" after changing the "set-default-line" to /etc/default/grub, decides which operating system starts by default on dualboot installations.
Reconfiguring this on-site everey time is an awkward way, because (1) repeated restarts take time, and (2) as soon as Windows is entered as the default OS to start, you have to physically visit the computer in order to make a change, only to manually select Linux again from the boot menu and then manually change the grub configuration - after all, the grub menu isn't accessible via ssh.
It would therefore be a great advantage if every locally installed grub could just read it's default "default menuentry number" from a network resource. Here it could be easily changed if necessary, and the admin would have a good overview of which machines boot which OS by default.
And no, often is it not possible to determine what the next reboot should be like at shutdown, because if suddenly an update is announced under Windows that requires several restarts on the same system to be fully executed, you have no easy opportunity to change the grub configuration, while on the PXE server, that would be a trifle.
The "wild idea" of booting an OS from the net to reconfigure the local Linux would indeed be a bit more automated, but also time-consuming (and probably more error-prone).
Remember: everything a really elegant solution for grub would need would be to read a single byte from a network resource of any kind.
Just to check if grub-mknetdir might open up an opportunity to do so, even if you don't really boot via PXE at all, I tested: GRUB_DEFAULT=$( cat (tftp)/default-grub/TEST )
This doesn't need bash, wget or curl, but it doesn't work that way either.
the entry "GRUB_DEFAULT=<zero-based integer>", which is not accessible from Windows at all and can only be changed from Linux by calling "update-grub" after changing the "set-default-line" to /etc/default/grub
both is not true!
an equivalent entry exists in /boot/grub/grub.cfg:
Code:
set default=0
- this can be replaced with anything you need, you can even override the last_boot functionality.
it's not beautiful, but it's possible.
you can edit text files on your linux partitions from windows, too
with that in mind, iot is easy to script something that takes the desired grub menu entry from some other resource and edits grub.cfg directly, and before the reboot.
but in the end you're right, none of this is a satisfying solution if grub does not offer such functionality.
maybe look at different bootloaders, e.g. syslinux?
and what about EFI?
...exactly. Of course you can mount ext4 somehow in Windows, or use a separate FAT32 /boot partition, but everything is a little risky in its own way, and sometimes a *single* reboot overridden with grub-once etc. indeed might be enough (but not always). So none of this is a satisfying solution, as - at the most - a permanent need for decentralized administration of a two-digit or larger number of clients becomes unpleasant.
The most important point might be to estimate the effort that a network lookup feature like the one discussed above would mean for the developers. I'm not a developer; I took a look into the source code anyway, but really can't judge it. In any case, the "feature request" is now available at http://savannah.gnu.org/bugs/?54671.
On the other hand, since I'm not sure if I missed anything useful in the docs and the web, I started this thread. Maybe someone else has another idea? I'd really like to try it out.
syslinux: As far as I can see, syslinux doesn't offer more functionality than grub2, especially not in the sense of the given task (which can be summarized as: essentially boot locally only with the option to read one single parameter from a central server). Which is probably why grub is the top dog, so to speak ,-)
UEFI: Apart from the fact that not all our devices actually do boot via UEFI at all, I can't imagine anything concrete here - what have you been thinking about?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.