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

基本上我需要在PXE命令行上使用ARGV,但我看不到任何文档来执行此操作。

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

scientific-linux-6 HOSTNAME VLAN

然后在%pre命中一些API来获取我需要的networking信息将其附加到KSconfiguration。 这个部分很简单,如果我有参数。

最后在%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. 

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

 scientific-linux-6 linux ARGV_APPEND 

对?

然后把事情变成%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 

所以这意味着我可以说

 scientific-linux-6 linux HOSTNAME=foo.example.com, VLAN=ddd 

对?

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

打我的API获取IP,掩码,网关,然后改变networking类似

 network --bootproto=static --ip=10.0.2.15 --netmask=255.255.255.0 --gateway=10.0.2.254 --nameserver=10.0.2.1 

如此处所述

然后,我们在我们的主厨客户端运行%post。

我的问题是。 这听起来像这样会起作用吗? 有没有更好的办法? 其他人肯定有这样做过?

更新(根据答案实施解决scheme)

在PXE命令行我结束了传递选项

 $ hotbox linux prefix_varname="foo" prefix_another_var="bar" 

(在linux之后的所有东西放在/ proc / cmdline上, hotbox是PXE标签)然后在%post我分析了/ proc / cmdline(在Ruby中)寻找匹配/前缀_ * /的所有variables, 。 这导致基于Web请求的结果将其从主厨传递给进一步的configuration。

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

使用简单的布尔选项,我已经在/proc/cmdline做了一个grep ,这非常简单。 对于键值选项, 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 

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

我能够使用以下命令将所有的键值对parsing为variables:

 # Get the kernel parameters params=`cat /proc/cmdline` # Split them on spaces params_split=(${params// / }) # Go through each of them for p in "${params_split[@]}"; do # And if it's a key value pair if [[ $p =~ "=" ]]; then # And if the key doesn't have a period in it p_split=(${p//=/ }) if [[ !($p_split[0] =~ ".") ]]; then # Then set the key to the value eval $p; fi; fi done 

应该是

 if [[ ! ($p_split[0] =~ ".") ]]; then ^^^ 

你可能想用下面的方法来包围它:

 #raw ... #end raw 

所以不会有补鞋匠/猎豹模板插值的问题。