4.5. 準備以 TFTP 網路開機用的檔案

如果您的機器連接到了一個區域網路,您可以從網路上的另外一台機器上面透過 TFTP 來開機。如果您傾向從另外一台機器上面啟動安裝系統,則開機檔案需要放在那台機器上面的某個特殊地方,並且設定您的機器從該機器進行開機。

You need to set up a TFTP server, and for many machines a DHCP server, or BOOTP server.

BOOTP is an IP protocol that informs a computer of its IP address and where on the network to obtain a boot image. The DHCP (Dynamic Host Configuration Protocol) is a more flexible, backwards-compatible extension of BOOTP. Some systems can only be configured via DHCP.

普通檔案傳輸協定 (Trivial File Transfer Protocol, TFTP) 能為客戶端提供開機映像。理論上,任何伺服器,在任何平台上只要實做這些協定就都能夠被應用。在這一節的一些例子裡面,我們將提供在 SunOS 4.x、SunOS 5.x (即 Solaris) 和 GNU/Linux 上面的一些操作例子。

[注意] 注意

For a Debian GNU/Linux server we recommend tftpd-hpa. It's written by the same author as the syslinux bootloader and is therefore least likely to cause issues. A good alternative is atftpd.

4.5.1. 設置 DHCP 伺服器

One free software DHCP server is ISC dhcpd. For Debian GNU/Linux, the isc-dhcp-server package is recommended. Here is a sample configuration file for it (see /etc/dhcp/dhcpd.conf):

option domain-name "example.com";
option domain-name-servers ns1.example.com;
option subnet-mask 255.255.255.0;
default-lease-time 600;
max-lease-time 7200;
server-name "servername";

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.200 192.168.1.253;
  option routers 192.168.1.1;
}

host clientname {
  filename "/tftpboot.img";
  server-name "servername";
  next-server servername;
  hardware ethernet 01:23:45:67:89:AB;
  fixed-address 192.168.1.90;
}

在這個例子中,一台伺服器 servername 負責執行包括 DHCP 伺服器、TFTP 伺服器和閘道器在內的所有工作。您需要修改網域名稱選項,以及伺服器名稱和客戶端硬體位址。filename 選項應是要從 TFTP 取得的檔案名稱。

After you have edited the dhcpd configuration file, restart it with /etc/init.d/isc-dhcp-server restart.

4.5.1.1. 在 DHCP 設定中打開 PXE 開機功能

Here is another example for a dhcp.conf using the Pre-boot Execution Environment (PXE) method of TFTP.

option domain-name "example.com";

default-lease-time 600;
max-lease-time 7200;

allow booting;
allow bootp;

# The next paragraph needs to be modified to fit your case
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.200 192.168.1.253;
  option broadcast-address 192.168.1.255;
# the gateway address which can be different
# (access to the internet for instance)
  option routers 192.168.1.1;
# indicate the dns you want to use
  option domain-name-servers 192.168.1.3;
}

group {
  next-server 192.168.1.3;
  host tftpclient {
# tftp client hardware address
  hardware ethernet  00:10:DC:27:6C:15;
  filename "pxelinux.0";
 }
}

Note that for PXE booting, the client filename pxelinux.0 is a boot loader, not a kernel image (see 節 4.5.4, “將 TFTP 映像放到適當的位置” below).

If your machine uses UEFI to boot, you will have to specify a boot loader appropriate for UEFI machines, for example

group {
  next-server 192.168.1.3;
  host tftpclient {
# tftp client hardware address
  hardware ethernet  00:10:DC:27:6C:15;
  filename "debian-installer/amd64/bootnetx64.efi";
 }
}

4.5.2. Setting up a BOOTP server

There are two BOOTP servers available for GNU/Linux. The first is CMU bootpd. The other is actually a DHCP server: ISC dhcpd. In Debian GNU/Linux these are contained in the bootp and isc-dhcp-server packages respectively.

To use CMU bootpd, you must first uncomment (or add) the relevant line in /etc/inetd.conf. On Debian GNU/Linux, you can run update-inetd --enable bootps, then /etc/init.d/inetd reload to do so. Just in case your BOOTP server does not run Debian, the line in question should look like:

bootps  dgram  udp  wait  root  /usr/sbin/bootpd  bootpd -i -t 120

Now, you must create an /etc/bootptab file. This has the same sort of familiar and cryptic format as the good old BSD printcap, termcap, and disktab files. See the bootptab manual page for more information. For CMU bootpd, you will need to know the hardware (MAC) address of the client. Here is an example /etc/bootptab:

client:\
  hd=/tftpboot:\
  bf=tftpboot.img:\
  ip=192.168.1.90:\
  sm=255.255.255.0:\
  sa=192.168.1.1:\
  ha=0123456789AB:

You will need to change at least the ha option, which specifies the hardware address of the client. The bf option specifies the file a client should retrieve via TFTP; see 節 4.5.4, “將 TFTP 映像放到適當的位置” for more details.

By contrast, setting up BOOTP with ISC dhcpd is really easy, because it treats BOOTP clients as a moderately special case of DHCP clients. Some architectures require a complex configuration for booting clients via BOOTP. If yours is one of those, read the section 節 4.5.1, “設置 DHCP 伺服器”. Otherwise you will probably be able to get away with simply adding the allow bootp directive to the configuration block for the subnet containing the client in /etc/dhcp/dhcpd.conf, and restart dhcpd with /etc/init.d/isc-dhcp-server restart.

4.5.3. 啟用 TFTP 伺服器

To get the TFTP server ready to go, you should first make sure that tftpd is enabled.

In the case of tftpd-hpa there are two ways the service can be run. It can be started on demand by the system's inetd daemon, or it can be set up to run as an independent daemon. Which of these methods is used is selected when the package is installed and can be changed by reconfiguring the package.

[注意] 注意

Historically, TFTP servers used /tftpboot as directory to serve images from. However, Debian GNU/Linux packages may use other directories to comply with the Filesystem Hierarchy Standard. For example, tftpd-hpa by default uses /srv/tftp. You may have to adjust the configuration examples in this section accordingly.

All in.tftpd alternatives available in Debian should log TFTP requests to the system logs by default. Some of them support a -v argument to increase verbosity. It is recommended to check these log messages in case of boot problems as they are a good starting point for diagnosing the cause of errors.

4.5.4. 將 TFTP 映像放到適當的位置

Next, place the TFTP boot image you need, as found in 節 4.2.1, “Where to Find Installation Files”, in the tftpd boot image directory. You may have to make a link from that file to the file which tftpd will use for booting a particular client. Unfortunately, the file name is determined by the TFTP client, and there are no strong standards.

For PXE booting, everything you should need is set up in the netboot/netboot.tar.gz tarball. Simply extract this tarball into the tftpd boot image directory. Make sure your dhcp server is configured to pass pxelinux.0 to tftpd as the filename to boot. For UEFI machines, you will need to pass an appropriate EFI boot image name (such as /debian-installer/amd64/bootnetx64.efi).