Diskless nodes/zh-cn

这篇HOWTO将帮助创建和安装Gentoo Linux的无盘节点.

关于这篇HOWTO
This HOWTO will help setting up diskless workstations based on the Gentoo Linux distribution. This is guide is intended to make the process as user friendly as possible and cater to the Linux newbie, because everyone was at a certain point :) While an experienced user could easily tie the multiple HOWTOs available on diskless nodes and networking together it's hoped that this guide can ease the installation for all interested users, geeks or not.

什么是无盘机？
A diskless machine is a PC without any of the usual boot devices such as hard disks, floppy drives or CD-ROMs. The diskless node boots off the network and needs a server that will provide it with storage space as a local hard disk would. From now on the server will be the master, while the diskless machine gets called the slave (what's in a name :). The slave node needs a network adapter that supports PXE booting or Etherboot; check Etherboot.org for support listings. Most modern cards support PXE and many built-in adapters on motherboards will also work.

开始之前
Gentoo should be installed on the master node and enough space on the master to store the file systems of the slave nodes that are going to be hosted. Also make sure there is one interface to the internet separated from the local area connection.

关于内核
The kernel is the software that sits between the hardware and all other software that is loaded on the machine, essentially the heart of a kernel based operating system. When a computer is started, the BIOS executes the instructions found at the reserved boot space of the hard drive. These instructions are typically a boot loader that loads a kernel. After a kernel has been loaded all processes are handled by the kernel.

For more information on kernels and kernel configuration check out the kernel HOWTO.

配置master的内核
master的内核可以很大也可以按照需要来定制，但是这些内核选项必须要选中. 输入以下命令进入内核配置菜单：

这里有用来替代手动编辑文件的一个灰色和蓝色的GUI. 如果这个内核当前工作正常，退出GUI并输入以下命令来保留当前的配置文件将会是一个好的主意：

进入下面的子目录并确保列出的条目都选择为内建（而非模块）. 下面的选项是取自于2.6.10版本的内核. 如果使用不同版本的内核，文字或者顺序可能会不同. 只需确保至少选择了以下这些.

如果需要通过master节点访问互联网和/或需要一个安全防火墙，确保添加了对iptables的支持：

如果还需要包过滤，一会再将剩下的作为模块添加. 确保已阅读在Gentoo安全手册中关于防火墙的章节来让它正常工作.

在重新配置master的内核之后，需要对它进行重建：

然后根据所使用引导器的不同，在或中为新内核添加一个条目，并确保新内核是默认的那个. 现在新的bzImage已经复制到了boot目录，所有所做的这些是为了在重启系统后可以载入这些新的选项.

关于slave的内核
It is recommended that the slave kernel be compiled without any modules, since loading and setting them up via remote boot is a difficult and unnecessary process. Additionally, the slave kernel should be as small and compact as possible in order to efficiently boot from the network. The slave's kernel is going to be compiled in the same place where the master was configured.

To avoid confusion and wasting time it is probably a good idea to backup the master's configuration file by typing:

The slave's kernel is now to be configured in the same fashion as the master's kernel. If a fresh configuration file is needed it can be recovered from the default file by typing:

现在键入以下命令进入GUI配置：

Make sure to select the following options as built-in and NOT as kernel modules:

Now the slave's kernel needs to be compiled. Be careful here not to overwrite or mess up the modules (if any) that have been built for the master:

Now create the directory on the master that will be used to hold slaves' files and required system files. The is used but any location preferred may be chosen here. Now copy the slave's bzImage into the directory:

配置一个slave的初步文件系统
The master and slave filesystems can be tweaked and changed a lot. Right now the only point of interest is in getting a preliminary filesystem of appropriate configuration files and mount points. First it's required to create a directory within for the first slave. Each slave needs its own root file system because sharing certain system files will cause permission problems and hard crashes. These directories can be called anything the administrator deems appropriate but the author suggests using the slaves IP addresses as they are unique and not confusing. The static IP of the first slave will be, for instance,  :

Various configuration files in need to be altered to work on the slave. Copy the master's directory onto the new slave root by typing:

Still this filesystem isn't ready because it needs various mount points and directories. To create them, type:

Most of these "stubs" should be recognizable; stubs like,  or  will be populated when the slave starts, the others will be mounted later. The file should also be changed to reflect the hostname of the slave. Binaries, libraries and other files will be populated later in this HOWTO right before attempting to boot the slave.

Even though is populated by   later on, the  entry needs to be created. If not, the error message "unable to open initial console" will be encountered.

关于DHCP服务器
DHCP stands for Dynamic Host Configuration Protocol. The DHCP server is the first computer the slaves will communicate with when they PXE boot. The primary purpose of the DHCP server is to assign IP addresses. The DHCP server can assign IP addresses based on hosts ethernet MAC addresses. Once the slave has an IP address, the DHCP server will tell the slave where to get its initial file system and kernel.

开始之前
There are several things to make sure of, that they are working properly before beginning. First check the network connectivity:

Make sure there is an eth0 device running. It should look something like this:

It's important that it says MULTICAST, if it doesn't then the kernel will have to be recompiled to include multicast support.

安装DHCP服务器
If the network does not already have a DHCP server installed, one needs to be installed now:

If the network already has a DHCP server installed, edit the configuration file to get the PXE boot to function correctly.

配置DHCP服务器
There is only one configuration file that needs to be edited before starting the DHCP server:. Copy and edit the provided sample file:

The general layout of the file is set up in an indented fashion and looks like this:

The  block is optional and should be used for IPs that are required to be assigned that belong to the same network topology. At least one  must be declared and the optional   block allows options to be grouped between items. A good example of looks like this:

The IP address after  will be asked for the specified. This IP address should be the IP of the tftp server, usually the same as the master's IP address. The  is relative to the  directory (this is due to the tftp server specific options which will be covered later). Inside the  block, the   option specifies a MAC address, and   assigns a fixed IP address to that particular MAC address. There is a pretty good man page on with options that are beyond the scope of this HOWTO. The man page can be read by typing:

启动DHCP服务器
Before starting the dhcp initialization script edit the file so that it looks something like this:

The  variable is the device that the DHCP server will be running on, in this case. Adding more arguments to the  variable can be useful for a complex network topology with multiple Ethernet cards. To start the dhcp server type:

To add the dhcp server to the start-up scripts type:

排查DHCP服务器
To see if a node boots, take a look at. If the node successfully boots, the file should have some lines at the bottom looking like this:

If the following message is encountered it probably means there is something wrong in the configuration file but that the DHCP server is broadcasting correctly.

Every time after changing the configuration file the DHCP server must be restarted. To restart the server type:

关于TFTP服务器
TFTP stands for Trivial File Transfer Protocol. The TFTP server is going to supply the slaves with a kernel and an initial filesystem. All of the slave kernels and filesystems will be stored on the TFTP server, so it's probably a good idea to make the master the TFTP server.

安装TFTP服务器
A highly recommended tftp server is available as the tftp-hpa package. This tftp server happens to be written by the author of SYSLINUX and it works very well with pxelinux. To install simply type:

配置TFTP服务器
Edit. The tftproot directory needs to specified with  and any command line options with. It should look something like this:

The  option indicates that this server listens in stand alone mode so inetd does not have to be run. The  indicates that log/error messages should be verbose. The  specifies the root of the tftp server.

启动TFTP服务器
To start the tftp server type:

This should start the tftp server with the options that were specified in the. If this server is to be automatically started at boot type:

关于PXELINUX
This section is not required if only Etherboot is being used. PXELINUX is the network bootloader equivalent to LILO or GRUB and will be served via TFTP. It is essentially a tiny set of instructions that tells the client where to locate its kernel and initial filesystem and allows for various kernel options.

开始之前
Now the file pxelinux.0 is required, which comes in the SYSLINUX package by H. Peter Anvin. This package can be installed by typing:

安装PXELINUX
Before starting the tftp server pxelinux needs to be set up. First copy the pxelinux binary into the directory:

This will create a default bootloader configuration file. The binary will look in the  directory for a file whose name is the client's IP address in hexadecimal. If it does not find that file it will remove the rightmost digit from the file name and try again until it runs out of digits. Versions 2.05 and later of syslinux first perform a search for a file named after the MAC address. If no file is found, it starts the previously mentioned discovery routine. If none is found, the file is used.

Let's start with the file:

The  tag directs pxelinux to the kernel bzImage that was compiled earlier. The  tag appends kernel initialisation options. Since the slave kernel was compiled with , the nfsroot will be specified here. The first IP is the master's IP and the second IP is the directory that was created in to store the slave's initial filesystem.

关于Etherboot
Etherboot boots network boot images from a TFTP server. As the PXE this is equivalent to LILO or GRUB. The  utility enables the creation of different images using different options.

开始之前
The  (utility for making tagged kernel images useful for netbooting) package is needed to create the Etherboot images. This tool will create a preconfigured kernel image from the original kernel. This contains the boot options as shown further down.

安装Etherboot
In this section a simple etherboot image will be created. As the dhcp server gives out the clients root-path in the "option root-path" dhcp.conf, this does not have to be included here. More details can be found in the mknbi manual.

Making the boot images. This will create a ELF bootable image capable of passing dhcp and the rootpath to the kernel. Also forcing the kernel to browse the network for a dhcp server.

排查网络启动过程
There are a few things that can be done to debug the network boot process. Primarily a tool called  can be used. To install  type:

Now various network traffic can be listened to, to make sure the client/server interactions are functioning. If something isn't working there are a few things that could be checked. First make sure that the client/server is physically connected properly and that the networking cables are not damaged. If the client/server is not receiving requests on a particular port make sure that there is no firewall interference. To listen to interaction between two computers type:

The  command can also be configured to listen on particular port such as the tftp port by typing:

A common error that might be received is: "PXE-E32: TFTP open time-out". This is probably due to firewall issues. If  is being used, it might be worth checking  and  and make sure that they are configured properly. The client should be allowed to connect to the server.

关于NFS服务器
NFS stands for Network File System. The NFS server will be used to serve directories to the slave. This part can be somewhat personalized later, but right now all that is wanted is a preliminary slave node to boot diskless.

关于Portmapper
Various client/server services do not listen on a particular port, but instead rely on RPCs (Remote Procedure Calls). When the service is initialised it listens on a random port and then registers this port with the Portmapper utility. NFS relies on RPCs and thus requires Portmapper to be running before it is started.

开始之前
The NFS Server needs kernel level support so if the kernel does not have this, the master's kernel needs to be recompiled. To double check the master's kernel configuration type:

The output should look something like this if the kernel has been properly configured:

安装NFS服务器
The NFS package that can be acquired through portage by typing:

This package will emerge a portmapping utility, nfs server, and nfs client utilities and will automatically handle initialisation dependencies.

配置NFS服务器
There are three major configuration files that will have to be edited:

The file specifies how, to who and what to export through NFS. The slave's fstab will be altered so that it can mount the NFS filesystems that the master is exporting.

A typical for the master should look something like this:

The first field indicates the directory to be exported and the next field indicates to who and how. This field can be divided in two parts: who should be allowed to mount that particular directory, and what the mounting client can do to the filesystem:  for read only,   for read/write;   and   are important for diskless clients that are writing to the disk, so that they don't get "squashed" when making I/O requests. The slave's fstab file,, should look like this:

In this example, master is just the hostname of the master but it could easily be the IP of the master. The first field indicates the directory to be mounted and the second field indicates where. The third field describes the filesystem and should be NFS for any NFS mounted directory. The fourth field indicates various options that will be used in the mounting process (see mount(1) for info on mount options). Some people have had difficulties with soft mount points so here they are made hard mounts, a look into various options should be done to make the cluster more efficient.

The last file that should be edited is which describes a few options for nfs when it is initialised and looks like this:

The  should be changed to the number of diskless nodes on the network.

启动NFS服务器
The nfs server should be started with its init script located in by typing:

If this script is to be started every time the system boots simply type:

复制缺失的文件
Now the slave's file system will be made in sync with the master's and provide the necessary binaries while still preserving slave specific files.

配置无盘网络
In order to prevent the networking initscript from killing the connection to the NFS server, an option needs to be added to on the diskless client's filesystem.

初始化脚本
Init scripts for slaves are located under for services needed on the diskless nodes. Each slave can be set up and customized here, it all depends on what each slave is meant to do.

Now is a good time to boot the slave and cross some fingers. It works? Congratulations, you are now the proud owner of (a) diskless node(s).