組み込み用途でmulti-call binary として非常に有名なBusybox と、
それを包括してクロスコンパイラ環境などを整えてくれるBuildroot

Firebox をDHCP&PXE サーバにするため、
CompactFlash にBuildroot を用いてBusybox 入りLinux 環境を作り込んだ。

そもそもcramfs はread-only イメージで書き込みはできないので、
環境構築時にproject_build_$ARCH/root 以下に設定ファイルを組み込んでおく。
udhcpd 起動スクリプト中でleases ファイルが作成されるように追記。

# /etc/init.d/S80udhcpd
<snip>
if [ ! -f /var/lib/misc/udhcpd.leases ]; then touch /var/lib/misc/udhcpd.leases; fi
<snip>
以下は、192.168.1.10 から192.168.1.19 まで10IP を割り振るようにした例。
# /etc/udhcpd.conf
start 192.168.1.10
end 192.168.1.19
max_leases 10
lease_file /var/lib/misc/udhcpd.leases
interface eth0
opt dns 192.168.1.1
opt subnet 255.255.255.0
opt router 192.168.1.1
opt lease 86400
opt bootfile /pxelinux.0

opt bootfile はdhcp option 67(0x43) に設定される文字列で、
ここに入れた文字列がそのままTFTP サーバから読み込むファイル名となる。
その他のオプションについては、option.c を参照。
TFTP サーバも、Busybox のinetd + tftpd を使う。

# /etc/inetd.conf
69 dgram udp nowait root tftpd tftpd /tftpboot
syslinux/core にあるpxelinux.0 を/tftpboot に置き、
pxelinux 設定ファイル(/tftpboot/pxelinux.cfg/default) を適当に書いて、
memtest86+ のbootable binary を/tftpboot に置いて起動テストを行う。
# /tftpboot/pxelinux.cfg/default
label memtest
  kernel memtest-plus-2.01

普通はこれで上がってくるはずなんだけど、
手元で作ったBusybox のudhcpd がbootfile 文字列の末尾にゴミを付ける場合があり、
tftpd がFile not found を返してしまう。
こちらについては後でコードを見るとして、仕方がないので、
Buildroot の設定をちょっと変更し、ISC DHCPd を使うようにした。

# /etc/dhcpd.conf
ddns-update-style none;
ignore client-updates;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.19;
    option broadcast-address 192.168.1.255;
    option routers 192.168.1.1;
    option domain-name-servers 192.168.1.1;
    option root-path "/tftpboot";
    filename "pxelinux.0";
}

こちらだと問題なく上がってきた。
ISC DHCPd を含めたことで、バイナリのサイズがちょっと増えたけど良しとしましょう。
これでOS の再インストールなどの諸作業が楽にできるようになった。

ここまで解説しておいて、dnsmasq を使った方が楽とか言えない・・・。
おわり。

組み込みLINUXシステム構築組み込みLINUXシステム構築
Karim Yaghmour 林 秀幸

オライリージャパン 2003-11
売り上げランキング : 132937
おすすめ平均

Amazonで詳しく見る
by G-Tools