如何将参数从 PXE 命令行传递到 kickstart %pre、%post 脚本?

Ena*_*ane 7 redhat kickstart pxe-boot anaconda scientific-linux

基本上我想在 PXE 命令行上使用类似 ARGV 的用法,但我看不到任何文档来执行此操作。

基本上我想通过类似的东西

science-linux-6 主机名 VLAN

然后在 %pre 中点击一些 API 来获取网络信息,我需要将它附加到 KS 配置中。如果我有参数,这部分很容易。

最后在 %post 我想开始厨师运行和引导到厨师服务器。这也需要知道主机名/域名(基本上有主机名 -f 不会爆炸),但如果我能完成上面的内容,这应该不会太糟糕。可悲的是,这是我最初的目标,但是当我意识到我还没有设置主机名时它失败了。

这是我到目前为止所学到的。

$ cat linux-install/msgs/param.msg 



                        09Kernel Parameter Help07

Some kernel parameters can be specified on the command line and will be
passed to the running kernel.  This does not include options to modules
such as ethernet cards or devices such as CD-ROM drives.

To pass an option to the kernel, use the following format:
     0flinux <options>07
If a different installation mode is desired, enter it after the option(s).

For example, to install on a system with 128MB of RAM using expert mode, 
type the following:
     0flinux mem=128M expert07

To pass options to modules, you will need to use the expert mode to disable
PCI autoprobing.  When the installation asks for your device type that needs
an option or parameter passed to it, there will be a place to type those
in at that time. 
Run Code Online (Sandbox Code Playgroud)

甜的!?所以这意味着在 PXE 上我可以像...

scientific-linux-6 linux ARGV_APPEND
Run Code Online (Sandbox Code Playgroud)

对?

然后把东西放到 %pre 和 %post 我发现这个演示文稿和其他一些提及

Stick this at the top of the %pre section, and it will take anything of the form var=value
from /proc/cmdline and turn it into a variable you can use directly

set -- `cat /proc/cmdline`

for I in $*; do case "$I" in *=*) eval $I;; esac; done
Run Code Online (Sandbox Code Playgroud)

所以这意味着我可以说

scientific-linux-6 linux HOSTNAME=foo.example.com, VLAN=ddd
Run Code Online (Sandbox Code Playgroud)

对?

然后在 %pre 这意味着我可以

点击我的 API 获取 IP、掩码、网关,然后将网络更改为类似

network --bootproto=static --ip=10.0.2.15 --netmask=255.255.255.0
 --gateway=10.0.2.254 --nameserver=10.0.2.1
Run Code Online (Sandbox Code Playgroud)

如上所述这里

然后,我们将在 %post 中设置我们的厨师客户端运行。

我的问题是。听起来这会奏效吗?有没有更好的办法?肯定有人以前做过这个吗?

更新(基于答案实施的解决方案)

在 PXE 命令行上,我最终传递了选项

$ hotbox linux prefix_varname="foo" prefix_another_var="bar"
Run Code Online (Sandbox Code Playgroud)

(之后的所有内容linux都放在 /proc/cmdline 上。hotbox是 PXE 标签。)然后在%post我解析 /proc/cmdline(在 Ruby 中)寻找与 /prefix_*/ 匹配的所有变量并将它们转换为哈希值。这导致将其传递给厨师以根据 Web 请求的结果进行进一步配置。

注意:当我做这一切时,剃刀不在身边。我个人对剃须刀并不满意,我们或多或少仍在使用上述方法。

amc*_*abb 4

通过简单的布尔选项,我做了一个grepin /proc/cmdline,这非常简单。对于键值选项,这个set技巧似乎很方便,尽管我还没有尝试过。针对您的问题具体解答:

1)是的,听起来这会起作用。我已经用 kickstart 和 做了非常类似的事情/proc/cmdline

2)不,我不相信还有更好的方法。内核在 中公开其命令行选项/proc/cmdline,并且 kickstart 不提供任何处理内核命令行选项的高级机制。

3)是的,以前已经这样做过。尝试一下,如果不行就回来。

一些额外的想法:

1)不要在命令行选项之间放置逗号(只需用空格分隔)。

2) 对于 pxelinux,使用一条线会很有帮助append。例如:

append initrd=f16-x86_64/initrd.img ks=nfs:server.example.com:/path/to/f16.ks mycustomflag mykey=myval
Run Code Online (Sandbox Code Playgroud)

3) 网络设置(如您提供的主机名示例)通常由 DHCP 提供更好的服务。