[技術] FreeBSD/Linux的Booting from network

Written on 3:08 下午 by Yu Lai

最近要搞在Mips的板子上搞Embedded Linux,
要透過網路開機來啟動,所以有了幾下的研究。

其概念為client開機時透過網卡的設定呼叫dhcp或bootp取得ip,
並向server以tftp的方式將boot image檔載入執行開機的動作。

在FreeBSD/Linux上可以透過網路開機,
設定的方法依照機器的網路卡功能的支援不同而有所不一樣。
以下是常見的幾種方式和設定方法:
(PS: 以下設定以Linux為主,FreeBSD則會有些許的不同。)

1. rboot
先介紹rboot
1.1 取得rbootd
如果你的網卡支援rboot開機的話,你必須有台Server來負
責handle boot request,所以首先你必須安裝rbootd。

1.2 設定rbootd
安裝完rbootd後需設定rbootd.conf來設定rbootd。
一般而言rbootd會位於/etc/rbootd.conf
設定範例如下:

# ethernet addr        boot file           comments
08:00:09:87:e4:8f lifimage_715 # PA/Linux kernel for 715/33
08:00:09:70:04:b6 lifimage_720 # PA/Linux kernel for 720
1.3 安裝boot file
將在rbootd.conf裡設定的boot file置於rbootd的目錄,一般是/var/lib/rbootd。

2. dhcp/tftp
這是最常見的一種方式,也是目前主流的diskless system建置的方法。

2.1 取得dhcp/tftp
先透過rpm或apt-get等方式來安裝server必要的檔案。
rpm: dhcp tftpd
(FreeBSD可以用Ports安裝/usr/ports/net/isc-dhcp3-server即可)

2.2 設定dhcp/tftp
1.修改/etc/inetd.conf或/etc/xinetd.d/tftp
inetd.conf中加入:
tftp           dgram   udp     wait    nobody  /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
xinetd.d/tftp:
service tftp
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -c -s /tftpboot //加上-c參數
per_source = 11
cps = 100 2
flags = IPv4
}
改完後接著重新啟動inetd或xined。
(FreeBSD則是改/etc/inetd.conf並在/etc/rc.conf中啟動inetd。)
這邊要注意的是我們必須將開機用的檔案放置於/tftpboot中。
2. 參考man 5 dhcpd.conf來修改dhcpd.conf,範例如下:
allow bootp;
default-lease-time 600;
max-lease-time 7200;
# This will tell the box its hostname while booting:
use-host-decl-names on;

subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name "foo.com";
option domain-name-server 192.168.1.4;
}
host tatooine {
hardware ethernet 00:40:05:18:0c:dd;
fixed-address 192.168.1.22;
filename "lifimage-tatooine";
option root-path "/exports/tatooineroot";
}
3. bootp/tftp
這是和dhcp/tftp類似,主要是dhcp已經將bootp的功能包含在一起的關係。
但由於網路架構的關係(e.g. 已有dhcp server),也是個常見的採用方式。

3.1 取得bootp/tftp
先透過rpm或apt-get等方式來安裝server必要的檔案。
rpm: bootp tftpd
(FreeBSD皆已內建其中)

3.2 設定bootp/tftp
1.修改/etc/inetd.conf或/etc/xinetd.d/tftp
inetd.conf中加入:
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
bootps dgram udp wait root /usr/sbin/bootpd bootpd -i -t 120
xinetd.d/tftp和xinetd.d/bootps:
service tftp
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -c -s /tftpboot //加上-c參數
per_source = 11
cps = 100 2
flags = IPv4
}
service bootps
{
disable = no //yes改成no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/bootpd
server_args = -i -t 120
per_source = 11
cps = 100 2
flags = IPv4
}
改完後接著重新啟動inetd或xined。
(FreeBSD則是改/etc/inetd.conf並在/etc/rc.conf中啟動inetd。)
這邊要注意的是我們必須將開機用的檔案放置於/tftpboot中。
2. 參考man 5 bootptab來修改/etc/bootptab,範例如下:
vodka:hd=/tftpboot:\
:rp=/usr/src/parisc/:\
:ht=ethernet:\
:ha=080069088717:\
:ip=140.244.9.208:\
:bf=lifimage:\
:sm=255.255.255.0:\
:to=7200:

If you enjoyed this post Subscribe to our feed

No Comment

張貼留言