From: Andrey Borzenkov <arvidjaar@gmail.com>
To: Rigoberto Corujo <rcorujo@yahoo.com>
Cc: "help-grub@gnu.org" <help-grub@gnu.org>, grub-devel@gnu.org
Subject: Re: Obtaining the MAC address of the boot NIC for a PXE boot
Date: Wed, 1 May 2013 18:59:34 +0400 [thread overview]
Message-ID: <20130501185934.3f2b9c28@opensuse.site> (raw)
In-Reply-To: <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com>
В Mon, 29 Apr 2013 05:55:32 -0700 (PDT)
Rigoberto Corujo <rcorujo@yahoo.com> пишет:
> Hello everyone,
>
> With pxelinux, you can specify "IPAPPEND 2" in your boot loader configuration file and the MAC address of the boot NIC automatically gets appended to your kernel parameters as "BOOTIF=XX:XX:XX:XX:XX:XX".
>
> I am now trying to become familiar with Grub 2, because if its EFI support. I noticed that with Grub 2, some of the documentation, which may be outdated, says that there is a "net_pxe_mac" variable which, as I understand it, should contain the MAC address of the boot NIC. However, I've built the latest Grub 2 sources and, when I PXE boot and drop into a grub shell prompt, if type "set", I don't see "net_pxe_mac" listed as one of the variables. I know there is a "net_ls_addr" command which prints out something like "efinet8 3c:4a:92:b2:6a:e8 10.1.1.114", but I don't know how to use Grub scripting to parse out the MAC address. I also don't know if there will ever be a case where "net_ls_addr" will print out multiple entries on a PXE boot, making it difficult to determine which one corresponds to the boot NIC.
>
>
> Basically, I'm using the "ksdevice=bootif" kernel parameter when PXE booting my Red Hat kernel. With PXE Linux, "bootif" provides the MAC address of the boot NIC. I was hoping to do something like "ksdevice=${net_pxe_mac}", but since "net_pxe_mac" does not appear to be getting set, I need to find some other method.
>
As it stands currently, net_pxe_* variables are defined on PC BIOS
platform only. For UEFI (which you apparently have) GRUB2 defines
net_efinetNN_* variables where efinetNN is symbolic name for interface
that was used to boot GRUB2.
May be GRUB2 should also define net_pxe_* namespace for the case of
UEFI. There is no real way to find out which interface was used for
booting and even if there were, grub does not support nested
variables substitution or eval'ing (like ${net_${boot_if}_mac).
Probably, adding "eval" support is really the most simple. Could you
test the patch below. What it does, is
- it adds "eval" command (same as known from UNIX shells) which
executes its argument
- it exports boot interface as "efi_boot_interface" variable
This should allow you to do
if $grub_platform = efi ; then
eval "set net_pxe_mac=\$net_${efi_boot_interface}_mac"
fi
and then use $net_pxe_mac on both platforms.
If it works for you, I will clean it up; for consistency this is
probably needed for ieee1275 as well.
---
grub-core/Makefile.core.def | 5 ++++
grub-core/commands/eval.c | 51 ++++++++++++++++++++++++++++++++++++++
grub-core/net/drivers/efi/efinet.c | 2 ++
3 files changed, 58 insertions(+)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 7e19acb..8844f2f 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -699,6 +699,11 @@ module = {
};
module = {
+ name = eval;
+ common = commands/eval.c;
+};
+
+module = {
name = extcmd;
common = commands/extcmd.c;
common = lib/arg.c;
diff --git a/grub-core/commands/eval.c b/grub-core/commands/eval.c
new file mode 100644
index 0000000..a21ff89
--- /dev/null
+++ b/grub-core/commands/eval.c
@@ -0,0 +1,51 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/term.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_eval (grub_extcmd_context_t ctxt __attribute__((__unused__)),
+ int argc, char *argv[])
+{
+ char *dummy[1] = { NULL };
+
+ if (argc != 1)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
+ return grub_script_execute_sourcecode (argv[0], 0, dummy);
+}
+
+static grub_extcmd_t cmd;
+
+GRUB_MOD_INIT(eval)
+{
+ cmd = grub_register_extcmd ("eval", grub_cmd_eval, 0,
+ N_("[STRING]"), N_("Evaluate commands"),
+ NULL);
+}
+
+GRUB_MOD_FINI(eval)
+{
+ grub_unregister_extcmd (cmd);
+}
+
diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c
index 2b344d6..f7d8fd5 100644
--- a/grub-core/net/drivers/efi/efinet.c
+++ b/grub-core/net/drivers/efi/efinet.c
@@ -23,6 +23,7 @@
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
#include <grub/i18n.h>
+#include <grub/env.h>
GRUB_MOD_LICENSE ("GPLv3+");
@@ -250,6 +251,7 @@ grub_efi_net_config_real (grub_efi_handle_t hnd, char **device,
&pxe_mode->dhcp_ack,
sizeof (pxe_mode->dhcp_ack),
1, device, path);
+ grub_env_set ("efi_boot_interface", card->name);
return;
}
}
--
tg: (93daf86..) e/uefi_pxe_vars (depends on: master)
next parent reply other threads:[~2013-05-01 14:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1367240132.58582.YahooMailNeo@web120204.mail.ne1.yahoo.com>
2013-05-01 14:59 ` Andrey Borzenkov [this message]
2013-05-04 21:08 ` Obtaining the MAC address of the boot NIC for a PXE boot Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-04 21:19 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-05 5:17 ` Andrey Borzenkov
2013-05-07 10:03 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-07 17:50 ` Documentation for (Re: Obtaining the MAC address of the boot NIC for a PXE boot) Andrey Borzenkov
2013-05-07 19:45 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-08 14:52 ` Andrey Borzenkov
2013-05-11 16:35 ` New command eval Andrey Borzenkov
2013-05-11 17:02 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-11 17:30 ` Andrey Borzenkov
2013-05-14 6:26 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-12 0:07 ` Seth Goldberg
2013-05-12 5:39 ` Andrey Borzenkov
2013-05-13 5:13 ` Seth Goldberg
2013-05-14 7:21 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-08 17:27 ` Obtaining the MAC address of the boot NIC for a PXE boot Rigoberto Corujo
2013-05-08 19:25 ` Andrey Borzenkov
2013-05-10 16:12 ` Rigoberto Corujo
2013-05-11 4:47 ` Andrey Borzenkov
2013-05-15 17:09 ` Rigoberto Corujo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130501185934.3f2b9c28@opensuse.site \
--to=arvidjaar@gmail.com \
--cc=grub-devel@gnu.org \
--cc=help-grub@gnu.org \
--cc=rcorujo@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).