:-)
No, there is no need for any 'if' statement. Instead of 'source' (
https://www.gnu.org/software/grub/manual/grub/html_node/source.html )
the 'configfile' command (
https://www.gnu.org/software/grub/manual/grub/html_node/configfile.html
) should be used.
insmod efinet
net_dhcp
configfile (tftp,172.16.1.1)grub.cfg
configfile /boot/grub/grub.cfg.bak
Tested for both: presence and absence of the TFTP server and seems to
work fine.
Best regards,
Marek
BTW: The above solution works as expected, but for my curiosity I'm
wondering:
Is there any way of just testing if the grub.cfg file on a remote TFTP
server is accessible or not?
I tried:
if [ ! -f (tftp,172.16.1.1)grub.cfg ] ; then ...
or
if ! source (tftp,172.16.1.1)grub.cfg ; then ...
but they don't seem to work :-(
On 10/16/25 9:59 AM, Marek Kozlowski wrote:
Nope. If the tftp is present it loads both. "If" is needed.
On 10/15/25 9:17 PM, Marek Kozlowski wrote:
:-)
Failsafe version:
insmod efinet
net_dhcp
source (tftp,172.16.1.1)grub.cfg
source /boot/grub/grub.cfg.bak
Regards,
/m
On 10/15/25 11:08 AM, Marek Kozlowski wrote:
:-)
Something poorly documented in:
https://www.gnu.org/software/grub/manual/grub/html_node/index.html
and even worse in the documentation of your distro ;-)
that may be useful for some of you, so I summarize my experiments
based on Andrei Borzenkov's proposal and help (thank you very much!).
The goal:
Approximately 200 workstations (in different classrooms) with several
systems, typically (Arch)Linux and Windows 10. We want to be able to
remotely decide if the default OS to be booted in a classroom is
Linux, Windows or sth else. Moreover for Linux we want to be able to
remotely change boot parameters.
Solution:
Install a simple TFTP server (let's say at: 172.16.1.1) and copy
grub.cfg for workstations to it.
On workstations manually create the grub.cfg as follows:
insmod efinet
net_dhcp
source (tftp,172.16.1.1)grub.cfg
The tips:
1. First check if it can properly initialize a NIC for a GRUB. As
described in a previous post, on my ThinkPad it requires two settings
in BIOS: in addition to "UEFI IPv4 Network Stack [x]" also the
"[Diagnostic]" mode for booting (I guess it's a bug):
grub> insmod_efinet
grub> net_ls_cards
2. The "source" in the GRUB _shell_ downloads the file and runs it (I
set the "terminus-font" in grub.cfg and it changes) but it doesn't
automatically display a menu, while the above config does. Don't worry.
3. I don't know why, but for the "source" command a relative name of
the grub.cfg must be specified. If the TFTP configuration is as
follows (tftp-hpa):
$ cat /etc/conf.d/tftpd
TFTPD_ARGS="--secure /srv/tftp/
that means, the GRUB config file is:
/srv/tftp/grub.cfg
then:
source (tftp,172.16.1.1)/srv/tftp/grub.cfg
doesn't work, while:
source (tftp,172.16.1.1)grub.cfg
does.
I hope the above comments may be useful,
best regards,
Marek