LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 09-13-2018, 04:10 AM   #1
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Rep: Reputation: 17
Question Defining grub's default entry from network?


Hello folks,

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.

Last edited by devdol; 09-13-2018 at 05:09 AM.
 
Old 09-14-2018, 02:01 AM   #2
Stéphane Ascoët
Member
 
Registered: Feb 2004
Location: Fleury-les-Aubrais, 120 km south of Paris
Distribution: Devuan, Debian, Mandrake, Freeduc (the one I used to work on), Slackware, MacOS X
Posts: 251

Rep: Reputation: 49
Did you explore the Grub documentation on Gnu website?

Otherwise, replacing the file via SSH or a deployment tool like "Fusion Inventory" before the restart?
 
Old 09-14-2018, 03:49 AM   #3
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
Yes, https://www.gnu.org/software/grub/ma...b.html#Network first gave me the idea that grub could also use network somehow.

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
 
Old 09-14-2018, 07:43 AM   #4
Stéphane Ascoët
Member
 
Registered: Feb 2004
Location: Fleury-les-Aubrais, 120 km south of Paris
Distribution: Devuan, Debian, Mandrake, Freeduc (the one I used to work on), Slackware, MacOS X
Posts: 251

Rep: Reputation: 49
Post Another idea

Quote:
Originally Posted by devdol View Post
Yes, https://www.gnu.org/software/grub/ma...b.html#Network first gave me the idea that grub could also use network somehow.
Yeah, but it's limited to PXE functionnality.

Quote:
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.
 
Old 09-15-2018, 03:37 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
question is, why do you need this?

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?
 
Old 09-17-2018, 06:44 AM   #6
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
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.

Last edited by devdol; 09-17-2018 at 06:45 AM.
 
Old 09-17-2018, 01:37 PM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by devdol View Post
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?

Last edited by ondoho; 09-17-2018 at 01:40 PM.
 
Old 09-18-2018, 05:15 AM   #8
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
...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.
 
Old 09-20-2018, 12:09 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by ondoho View Post
maybe look at different bootloaders, e.g. syslinux?
and what about EFI?
https://wiki.archlinux.org/index.php/syslinux
 
Old 09-21-2018, 04:16 AM   #10
devdol
Member
 
Registered: Dec 2005
Distribution: debian (testing/unstable)
Posts: 68

Original Poster
Rep: Reputation: 17
Hmm...

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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
libvirt KVM default network: how to force an MX DNS record entry tshikose Linux - Virtualization and Cloud 6 06-08-2017 06:38 PM
Bash Scripting – Code Structure - Defining Multiple Points Of Entry In Bash Script carlr Programming 10 08-25-2014 02:38 AM
[SOLVED] Problem defining default gateway in CentOS 5.X Vanyel Linux - Networking 5 11-30-2011 12:08 PM
Howto change GRUB default entry to use with VMWARE without restart? grol Linux - Software 11 09-09-2008 10:41 AM
Grub: Change Default Boot Entry luwigie Linux - General 4 08-22-2004 02:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 04:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration