PXEの使い方

 

PXE(Preboot eXecution Environment)は、Intelの作成した、ネットワークブートの為の規格であり、サーバおよびクライアントが従うべきプロトコルなどが規定されている。PXE準拠のNIC(Network Interface Card)は、これに準拠したソフトウエアを、そのROM上にもっており、PXEサーバが用意されたネットワーク環境において、ネットワークブートが可能となる。サーバとして、PXEサーバ(ProxyDHCP、(M)TFTPサーバ)と、DHCP(またはBOOTPサーバ)を動作させる必要がある。規格の詳細については最後のリファレンスを参照されたい。

  1. DHCPサーバーの導入と設定
  2. Proxy DHCPサーバーの導入と設定
  3. (M)TFTPサーバの設定
  4. DHCP設定のその他例
  5. Linux のディスクレスクライアントの実現
  6. Bpbatch Intel PXE server との比較
  7. 参照文献

1. DHCPの導入

  配布元 www.isc.org
    Install: (SoftwareDesign誌によると、2.0pl15を使用し3は使わない方が無難とのこと)
  # configure; make; make instal
Install についての問題はREADME を参照。(今回は問題なかった)
Linuxでの問題
The all-ones broadcast address
(not subnet.255 but 255.255.255.255 Win95DHCPclient problem)
Linux 2.1 ip_bootp_agent enabling, (RedHat6.1,2ではなし)
echo 1 >/proc/sys/net/ipv4/ip_bootp_agent
operations with more than one network interface.( 問題なし)
コンパイル上の問題
There are also two potential compilation/runtime problems for Linux 2.1/2.2: the "SO_ATTACH_FILTER undeclared" problem and the "protocol not configured"
注意
config file(/etc/dhcpd.conf) 変更後は kill ?HUP ではだめ、再起動が必要。
/var/state/dhcp/dhcpd.lease をあらかじめ touch で作っておく必要がある。
/var/state/dhcp/dhcpd.lease をあらかじめ touch で作っておく必要がある。
最初のうちはconfigfileのデバックの為にも ?d オプションで起動
/etc/dhcpd.conf の設定
例 (詳しくはマニアルを参照)
# dhcpd.conf      
#
全てに共通な部分.
use-host-decl-names on;
  ← host名と、config file host名が同じになる
default-lease-time 600;
max-lease-time 7200;

# サブネットに共通な部分。 他にgroup という記述子でホストをグループ化可能
subnet 192.168.197.0 netmask 255.255.255.0 {
# range 204.254.239.10 204.254.239.20;
   ←動的IP address 割り当ての時
 option domain-name "dc2.kek.jp";
 option broadcast-address 192.168.197.255;
 option routers 192.168.197.1;
}

#host entities  以下は静的IP address 割り当てをしている。(bootp)
host n011 {
  ←use-host-decl-namesonなので、これが実際のホスト名として送られる。
 hardware ethernet 00:D0:B7:1B:12:ED; ← MAC アドレス
 fixed-address 192.168.197.31;     ← n011への静的IP アドレス割り当て
 option dhcp-class-identifier "PXEClient"; ← PXEに必須
 option next-server 192.168.197.11;   ← PXEサーバを指定、menu等のオプションは
                      PXEProxy DHCPサーバから供給される。
}
# vendor-encapusulated option
が含まれない場合は、next-server PXEサーバを指定

 

2. PXE (Proxy DHCP)サーバの導入

PXE 0_1-20 が、RedHat 7 にある。RedHat6.2 にはそれより古いバージョン 0_1-14 がある。内容の違いはしらない。
PXEは、それ単体では動作せず(動いても良さそうだが)、DHCPまたは、Bootp とともに動作させる必要がある。その場合、DHCPとPXE serverに
  1. 別々のマシンを使用する場合
    PXE.conf の UseDHCPPort を1に指定する。
  2. 同じマシンを使用する場合

    PXE.conf の UseDHCPPort を0に指定する。これにより、PXEサーバに含まれる Proxy DHCPが DHCPポート67を使用しなくなる。(注1)

    2-1. DHCP を使用する場合

    dhcpd.conf の対象のhostに対して
     option dhcp-class-identifier “PXEClient” を入れる。また、
     option vender-encapsulated-option は「含まない」こと。

    2-2. Bootp を使用する場合

    T60=505845436C69656E74 を入れる

注1) Preboot Execution Environment(PXE) Specification (from intel homepage) Version2.1 の 2.2.3 Proxy DHCP に、DHCPOFFER (クライアントからのブロードキャスト問い合わせに対する)DHCP または Bootp サーバからの返答に、RFC1084(2132) Option60 = “PXEClient”があって、かつ Option43(encapsulated option)が無い場合には、以降クライアントは port=4011に対して DHCPREQUESTを出すとある。Proxy DHCPサーバはport=4011を使用するように設定が可能である(pxe.conf)ため、DHCP/bootpサーバと ProxyDHCP(PXEサーバ)を同じホストに用意することができる。
さらに、高度な技として、Option43 のTag6 PXE_DISCOVERY_CONTROL を使用する方法がある。
注2) 基本的な仕組みとして、PXEは最初に DHCPにより自機の IPアドレス等を得た後(DHCPDISCOVER step)、bootserverの情報を得るために再度 DHCPプロトコルを使用する(BootServerRequest step)。DHCPではサーバが過程により流す情報を変化させるようにはできていないので、2番目のステップはProxy DHCP(PXE サーバによる)で行うことになる。これら2つのサーバ(DHCPとDHCP Proxy)が同じポートを使用できないので、注意1が必要となる。
一般に、DHCPサーバが担うのは、Client IPの解決などだけで、あとは DHCP-proxy(PXE)サーバにまかせるが、DHCPからの情報に、bootserver,file情報(linux.0,1,2を供給する PXEのブートサーバとは別)bootserverPXE_TAGの TAG=6,7,8,9,10を含むことが可能である。 dhcpd.confのをここに示す。ただし、この場合、BootServerRequest step bootサーバがこれらの情報を再びクライアントに告げないことが必要である。
参考:いくつかのセッションの tcpdump 出力  1  2 (MS-word format)
注3) DHCPからの応答に、PXE encapsulated-option を不完全に含めると、PXE client からTAG XXX が足りないと言われる。
/etc/pxe.conf の例
# ******* PXE CONFIGURATION FILE ******* ← #で始まる行はコメント
# PXEをどのinterfaceで行うか。interfaceが指定されれば
#自動的にIp addressは取得してつかう。
[Network_Interface_Name]
eth0
# もし自動で取得できなければ、下をつかう(オプション)
[OurIpAddress]
#192.215.100.202
#MTTPDのベースディレクトリー  [Mtftpd_Root_Directory]
/tftpboot
# 同じマシンでDHCPを使うなら、0に指定して、port67を使わないようにする。
[UseDHCPPort]
0
#ProxyDHCPを使うなら1,そうでなければ0
[StartProxy]
1
# PXEBootServerとして使うなら1,そうでなければ0
[startBootService]
1
[MasterProxy]
1

# 0 ? broadcast discovery is enabled; 1 - broadcast discovery is disabled
[Discovery_BCast_Disabled]
0
# 0 ? multicast discovery is enabled; 1 - multicast discovery is disabled
[Discovery_MCast_Disabled]
0
# Multicast Discovery address. The boot server would listen on this address 
# for multicast boot server packets.
[Discovery_MCast_Addr]
224.0.1.2
# DHCPPrompt to display on the user screen DHCP Option43, TAG9 で送られる
# format of this entry: timeout,<string>
[Prompt]
10,Press F8 to view menu ...
# This entry is set to 1 if the client should accept only responses
# from servers in this list
# 0ならどこからでも受け付ける。
[Discovery_Server_List_Only]
0
# the format of the discovery_list entry is as follows
# type of the server(すきな数字。サーバのグループの識別に必要),
# of entries, Ip address of each entry
# separated by commas DHCP Option43,TAG8で送られる。
[Discovery_List]
#3,2,192.215.100.49,192.215.100.99
#65535,1,192.215.100.45
#In some systems, the all '1' broadcast address 255.255.255.255 won't work 
#as the system will fail with a
# network unreachable message. In those cases, you can use the 'route add -host 255.255.255.255 eth0'
# command to add a route. Or else, you can define the host portion of the
# address alone as '1' in the following entry.
# This entry is not required if your system is set up to transmit broadcast 
#packets on 255.255.255.255
[Broadcast_ip_address]
#192.215.100.255

# Architectures supported
# format : <arch-type>,<arch-string>
[PROC_ARCH]
0,X86PC

# Boot server types supported. type は[Dscorvery_list]の番号と対応するとおもわれる。
[Service_Types]    ← 以下でいう、サーバタイプ
0,Bstrap
13,linux-install
14,linux-boot

# Menu string that will be displayed on the client screen after F8 is pressed.
#最初の数字は[Service_types]の最初の数字と対応する。DHCP Option43 TAG9 
#でおくられる。
[X86PC/UNDI/MENU]
13,Remote Install Linux
0,Local Boot
14,Remote Boot Linux

# Image file name for Linux install boot server type
# format : <min layer #> <max layer #> <base file name>
[X86PC/UNDI/linux-install/ImageFile_Name] ←サーバタイプ=13用
0
2
linux

# Image file name for Linux boot server type
# format : <min layer #> <max layer #> <base file name>
[X86PC/UNDI/linux-boot/ImageFile_Name] ←サーバタイプ14用
0
1
linux

# Image file name for BStrap boot server
# format : <min layer #> <max layer #> <base file name>
# bstrap.0 は現在もう使われていないようである。
[X86PC/UNDI/BStrap/ImageFile_Name]
0
0
bstrap

# List of plug-ins. The PXEClientTester is the plug-in that
# validates received packets for PXE compliance. By default, this
# plug-in is DISBALED. Remove the '#" in front of it, if you want
# packet validation to happen

[Parsers]
# PXEClientTester
PxeParser
[Parsers/PxeParser/MainFunction]
PxeParser
[Parsers/PxeParser/DllPath]
/usr/lib/libpxeParser.so
[Parsers/PXEClientTester/MainFunction]
PXEClientTester
[Parsers/PXEClientTester/DllPath]
/usr/lib/libpxeTester.so
# Even if the PXEClientTester is loaded, you still need to
# turn this flag to '1' for packet validation.
[TestOn]
1

# Directory where the results of the packet validation by PXEClientTester
# will be written to. Under this directory, there will be
# sub-directories with the last 8 digits of the MAc address of
# each client.
[TestPath]
/tmp
# Option DLL for BStrap
[X86PC/UNDI/BStrap/Vendor_Dll]
/usr/lib/libBstrapOpts.so
# Fill in a NT server name that will be contacted by the client
# to log back in for APitest
[ServerName]
#vviswana-desk2
# Specify whether the above server is in a domain or a workgroup
[IsDomain]
0
# specify the name of the workgroup or domain of the server
[Domain]
dc2.kek.jp
# All debug related stuff here
# If this entry is set to 1, pxe services will write more debug info to the 
#system log using syslog()
[DEBUG/PxeServices_DebugOutToWindow_On]
1
# If this entry is set to 1, pxe parser will write more debug info to the system log using syslog()
[DEBUG/PxeParsers_DebugOutToWindow_On]
1
# If this entry is set to 1, pxe services will write more debug info to the file mentioned
# under the entry [DEBUG/PxeServices_Debug_FileName]
[DEBUG/PxeServices_DebugOutToFile_On]
1
# If this entry is set to 1, pxe parser will write  more debug info to the file mentioned
# under the entry [DEBUG/PxeParsers_Debug_FileName]
[DEBUG/PxeParsers_DebugOutToFile_On]
1
[DEBUG/PxeServices_Debug_FileName]
/PxeServiceLog.txt
[DEBUG/PxeParsers_Debug_FileName]
/PxeParserLog.txt
[End]

 

/etc/services にPXEの設定を入れる。
pxe   67/udp
pxe   4011/udp 

 

3.TFTPの設定
次に一般的な (M)TFTPの設定が必要である。 /etc/servicesにtftp、mtftp を加える。

tftp       69/udp
mtftp      1759/udp            # mtftp for pxe

 

/etc/inetd.conf に tftpまたは mtftp を加える。inetdのHUP killを忘れないように。

mtftp  dgram  udp   wait  root  /usr/sbin/tcpd in.mtftpd   /tftpboot
 
(M)TFTPにより、クライアントがブートのためダウンロードするファイルイメージを用意する。

/tftpboot/X86PC/UNDI/linux-install/linux.0      ← PXEサーバパッケージに添付されている。
                        linux.1   ← Linux kernel イメージ、普通に 
                                                                     make bzImageで作成されるもの。
                        linux2      ← RAMdiskをrootにするなら、initrdイメージ
/tftpboot/X86PC/UNDI/Bstrap/bstrap.0    ← PXEサーバパッケージに添付されている。
                               (現在は不要?)

4. DHCP設定のその他例

PXEクライアントは、DHCP/BOOTPまたはProxy DHCPサーバより送られる、vendor encapsulated option の情報から以後の挙動(boot server (download server) request stepの挙動)を決める。(PXE spec 2.1 より vendor encapsulated option の概要)

vendor encapsulated option は、dhcpd.conf においては、 "option vendor-encapsulated-options"キーワードについづいて、TAG NO.(1バイト):TAG長(1バイト):TAG内容(可変長)を複数個列挙できる。
TAG No. TAG Length(byte) 内容および説明
6 01  boot server(BS)を探索するときの指針
       bit0 =1  disable broadcast discovery
              bit1 =1  disable multicast discovery
              bit2 =1  only accept from TAG=8 servers
              bit3 =1  do not prompt/meu/discover (use 'boot file name')

   if (client support multicast discovery) & (TAG 6 bit1=0) & (TAG 7 has addr)
      then use MULTICAST
   else if (TAG 6 bit0=0)
      then use BROADCAST
   else if (TAG 8 exist)
      then use UNICAST 

例: 06:01: 00  

7 04 BSMulticastアクセスで探索する際のアドレス

例: 07:04: e0:00:01:02  pxe.conf[Discovery_MCast_Addr]に対応

8 可変長 BSUnicastアクセスする際のアドレスリスト(複数可能 ()内はバイト数)

Serv_Type(2),IPcnt(1),addr(4*IPcnt) [,Serv_Type以下繰り返し]

:
 08:0e:
 00:0d: 01: C0:A8:C5:0C:  ←Serv_type=13192.168.197.12をエントリ
     00:0e: 01:C0:A8:C5:0C:  ←Serv_type=14192.168.197.12をエントリ
(以下例では、13install program, 14NFSブートの2つのタイプを定義しているが、13,14という数字を選んだのはたまたま)

Serv_type  サーバタイプ(サーバの識別番号)
0=loca  (HDなどからのローカルブート)
9以下の数字はリザーブされている。
pxe.conf Service Typeに対応する
IPcnt  そのサーバ種類の台数
addr  サーバのアドレス
9 可変長 Sが複数のタイプ(Serv_type)ある時、選択メニュー(クライアントの画面に表示される)文字列の指定

Serv_Type(2),文字列長(1),文字列(可変) [,Serv_Type以下繰り返し]

例:
09:29: 00:00: 0a: 4c:6f:63:61:6c:20:62:6f:6f:74:  ←Serv_type=0 "Local Boot"
    00:0d: 0a: 6b:69:63:6b:20:73:74:61:72:74: ← Serv_type=13 "kick start"
        00:0e: 0c: 6e:65:74:77:6f:72:6b:20:62:6f:6f:74: ←    =14 "network boot"

10 可変長 「選択メニューを出すには<F8>を押せ」などのクライアントに出力される文字列。

timeout(1),文字列(可変)

例:0a:13: 0a: 54:79:70:65:20:3c:46:38:3e:20:66:6f:72:20:6d:65:6e:75:

255  終端

次に dhcpd.conf での応用例を挙げる。ここでは、DHCPサーバで DHCP-proxyサーバの役割を行うという技を使っている。

例1
前記dhcpd.conf例の、ホストに共通なパラメータは省略しているので注意
host n11 {
 hardware ethernet 00:D0:B7:1B:12:ED;
 fixed-address 192.168.197.31;
 option dhcp-class-identifier "PXEClient";
 filename "/distr/ks/ks.cfg"; ← kickstart config file など dhcpで送りたい情報を書ける。
 
next-server 192.168.197.12;  ← bootserver のアドレスも指定できるが、そのアドレスは
                        
vendor-encap.で指定しているので、next-serverには、
                        ネットワークブートでの
NFSサーバや、kickstart での 
                      
config file サーバのアドレスを指定するなど他の用途に利用できる。
 
option root-path "/distr/netboot";   ← ネットワークブートでのNFS root が書ける。
 
option vendor-encapsulated-options
   06:01:00: 
       07:04:e0:00:01:02: ←bootserver discovery multicast を使う。pxe.confと一致の必要
  
09:29:                vendor-encapsulateをつけるときは、TAG=9は必須。
#Server_type=00 local boot
       00:00:0a:4c:6f:63:61:6c:20:62:6f:6f:74:
#Server_type=0D network-install(kickstart)
       00:0d:0a:6b:69:63:6b:20:73:74:61:72:74:
#Server_type=0E diskless boot
       00:0e:0c:6e:65:74:77:6f:72:6b:20:62:6f:6f:74:
#
   0a:13:0a:54:79:70:65:20:3c:46:38:3e:20:66:6f:72:20:6d:65:6e:75:ff;
#
    ↑ vendor-encapsulate をつけるときは、TAG=10は必須
}

上の例では、PXEサーバの((M)TFTPの)bootserverを見つけるのに、Multicast を使用する。クライアント画面 にLocal Boot, kick start, network boot と出力し、それぞれServer_type を 0,13,14とする。pxe.confにも[Service_Types]、[X86PC/UNDI/linux-install/ImageFile_Name]等に対応するところを書くこと。vendor-encapsulatedで bootserver discovery にmulticastを指定するようにしているので、DHCP のnext-server option をNFSサーバの指定などに使うことができるようになる。

例2
host n11 {
 hardware ethernet 00:D0:B7:1B:12:ED;
 fixed-address 192.168.197.31;
 option dhcp-class-identifier "PXEClient";
 filename "/distr/ks/ks.cfg";
 next-server 192.168.197.12;
 option root-path "/distr/netboot";
 option vendor-encapsulated-options
  06:01:03: 08:0e:00:0d:01:C0:A8:C5:0C:00:0e:01:C0:A8:C5:0C:
  09:29:00:00:0a:4c:6f:63:61:6c:20:62:6f:6f:74:00:0d:0a:6b:69:63:6b:20:73:
    74:61:72:74:00:0e:0c:6e:65:74:77:6f:72:6b:20:62:6f:6f:74:
  0a:13:0a:54:79:70:65:20:3c:46:38:3e:20:66:6f:72:20:6d:65:6e:75:ff;

この例では、bootserverを探すのに、unicast を使用するTAG=8 を使用している。multicastを抑止するため、TAG=63broadcast,multicastの抑止)を指定している。

5. Linux のディスクレスクライアントの実現

カーネルの再コンパイル
root file system を NFSにし、NFSサーバ名と root file system のパス名をbootp(またはDHCP)から得る(3)には、kernelの再コンパイルが必要である。また、network driver moduleでなく、静的リンクしておく必要がある(1)

再コンパイル手順(/usr/src/linux で make xconfig 必ず以下の順序で)

  1. Ethernet のところで、使用するnetwork driveryにチェック
  2. Networking Options で、IP: kernel level auto configuration BOOTP support y
  3. Network File systems NFS Filesystem support をy、Root file system on NFSy
  4. make dep; make bzImage
  5. kernel image /usr/src/linux/arch/i386/boot/bzImage にできるので、これを PXEサーバの指定の場所(例え/tftpboot/X86PC/UNDI/linux-boot/linux.1 へ移動する。
  6. root file system NFSに変更する。

    mkdev /dev/boot255 c 0 255; rdev linux.1 /dev/boot255; rm /dev/boot25

    /dev/boot255はカーネルにroot pathNFSにあるということを指定する方便。詳しくは /usr/src/linux/Documentation/nfsroot.txtを参照のこと。
    また、
    root file system rwにしておいた方がいいであろう

    rdev -R linux.1 0; rdev -R linux.1

    で確認。

  7. /usr/src/linux/System.mapも新しい root にコピーしておかないと、警告メッセージがうるさい。
  8. NFS rootを用意する。/etc/exportsを書き換えて、exportsするのを忘れずに、

例:

/raid/md0   130.87.57.225(rw)   192.168.197.0/255.255.255.0(rw,no_root_squash)

この後、exportfs -auv; exportfs -av とやるわけだが、exportfs -vできちんと出来ているかチェックすること。

  1. hostに特有な /var /etcは個別に用意すること。

    /etc/fstab は例えば
    dcpf001:/raid/md0/bt/rl / nfs defaults 0 0
    /proc /proc proc defaults 0 0

     

  2. /dev MAKEDEV をのこして消去し、./MAKEDEV generic として作成しておく。
dhcpd.tab root_path に書けるのはなぜか16文字未満のようである。それ以上にすると、なぜか /tftpboot/host_name をマウントしようとする。

6.Bpbatch Intel PXE server との比較

Bpbathはバイナリーしかない、PXEサーバはソースがある。
Bpbatchは、kernel にオプション引数を渡すことができるが、PXEでは渡せない。single user modeで立ち上げるにはどうすればいいんだ!
その後、RedHat 7.3に含まれている pxe-0.1に付属している pxe-linux/nbp.linux/linux.0 (linux.0についてはここ)では、立ち上がり時にクライアントで kernel option を聞いてくるようになった。しかし、クライアント側のコンソールで人間がタイプインする必要があるので、あまりうれしくない。
Bpbatch.comによると、PXEは不安定らしい。(とくにMTFTPが)

7.参考文献

  1. ソフトウエアデザイン 2000.10月号 48ページ、200011月号100ページ
  2. PXE specification ver.2.1
  3. Intel Preboot Execution Environment INTERNET DRAFT
  4. Multicast TFTP in the Intel PXE Remote Boot Envirnment
  5. DHCP Options and BOOTP Vendor Extensinos RFC2132