Redhat

如何將參數從 PXE 命令行傳遞到 kickstart %pre, %post 腳本?

  • June 15, 2017

基本上我想要在 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. 

甜的!?所以這意味著在 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、遮罩、網關,然後將網路更改為類似

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

如此處所述

然後這為我們的廚師客戶執行設置了 %post。

我的問題是。聽起來這行得通嗎?有沒有更好的辦法?以前肯定有人這樣做過嗎?

更新(基於答案實施的解決方案)

在 PXE 命令行上,我最終傳遞了選項

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

(之後的所有內容linux都放在 /proc/cmdline 上。hotbox是 PXE 標籤。)然後%post我解析 /proc/cmdline (在 Ruby 中)尋找與 /prefix_*/ 匹配的所有變數並將它們轉換為雜湊。這導致將其傳遞給主廚,以根據 Web 請求的結果進行進一步配置。

注意:當我做這一切時,Razor 並不在身邊。我個人對剃須刀並不滿意,我們或多或少仍在使用上述方法。

使用簡單的布爾選項,我已經完成了grepin /proc/cmdline,這很容易。對於鍵值選項,這個set技巧似乎很方便,儘管我沒有嘗試過。您的問題的具體答案:

1)是的,聽起來這會奏效。我用 kickstart 和/proc/cmdline.

2)不,我不相信有更好的方法。核心在 中公開其命令行選項/proc/cmdline,並且 kickstart 不提供任何高級機制來處理核心命令行選項。

  1. 是的,這已經完成了。試試看,如果你不能讓它工作,就回來。

一些額外的想法:

1)不要在命令行選項之間放置逗號(只需用空格分隔它們)。

append2) 使用 pxelinux,使用一條線會很有幫助。例如:

append initrd=f16-x86_64/initrd.img ks=nfs:server.example.com:/path/to/f16.ks mycustomflag mykey=myval

3)網路設置(如您提供的主機名範例)通常由 DHCP 提供更好的服務。

引用自:https://serverfault.com/questions/372609