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.

什么是无盘机？
一台无盘机器是一台没有任何诸如硬盘、软盘驱动器或CD-ROM等常见引导设备的PC. 无盘节点引导自网络，并需要一台服务器来提供当作本地硬盘来使用的存储空间. 从现在开始，服务器将称为“master”，而无盘机器将称为“slave”（从名字中能看出来什么？：）. slave节点需要一块支持PXE引导或Etherboot的网络适配器；支持的列表可以查看Etherboot.org. 现在大多数的卡都支持PXE，很多主机集成的适配器也同样可以.

开始之前
Gentoo应该安装在master节点，并且master有足够的空间来为slave节点提供文件系统的储存. 同时要确保还有一块独立于本地连接的网卡用于接入互联网.

关于内核
内核是一个介于硬件和其它装载于本地软件之间的软件，也就是基于内核的操作系统的心脏. 当一台计算机启动，BIOS运行在硬盘预留引导空间的找到的指令. 这些指令通常是一个用于加载内核的引导器. 当内核被加载后，所有的进程都由内核来处理.

关于内核及内核配置的更多信息，可访问内核HOWTO.

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

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

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

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

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

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

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

关于slave的内核
建议将slave的内核编译成无任何模块，因为通过远程引导加载和安装他们是一个困难并且没必要的过程. 另外，为了有效的从网络引导，slave的内核应该尽可能的小和精简. slave的内核将在和配置master同样的位置进行编译.

为了避免混乱和浪费时间，键入以下命令来备份master的配置文件将会是一个好主意：

现在，slave的内核已经配置得和master的内核的kernel一样时尚了. 如果需要一个全新的配置文件，可以键入以下命令来还原默认文件：

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

确保将以下的选项选择为内建而不是内核模块.

现在的slave需要进行编译. 这里要小心不要覆盖或者弄乱为master编译的模块（如果有的话）：

现在在master上创建用来保持slave自己的及必须的系统文件的目录. 这里使用的是，但是仍然在这可以选择任何更好的位置. 现在复制slave的bzImage到目录：

配置一个slave的初步文件系统
master和slave的文件系统可以调整并变更一些. 现在的兴趣点是获得一个有合适的配置文件和挂载点的初始的文件系统. 首先需要在中为第一个slave创建目录. 由于共享同一系统文件将会造成权限问题及硬崩溃，每个slave需要它们各自的根文件系统. 这些目录可以叫作任何管理员觉得合理的名字，但是作者建议使用惟一的并且不会混乱的slave的IP地址. 第一个slave的静态IP将以 为例：

中的许多配置文件需要改变为slave所使用的. 键入以下命令复制master的目录到新slave的根：

这个文件系统仍然没有完成，因为它需要许多挂载点和目录. 键入以下命令去创建它们：

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.

尽管会在稍后被 占据，仍然需要创建条目. 否则，将会遇到“unable to open initial console”（无法开启初始化控制台）错误信息.

关于DHCP服务器
DHCP代表着动态主机配置协议. DHCP服务器将是当slave从网络启动时第一个通信的计算机. DHCP服务器的主机作用是指派IP地址. DHCP服务器能基于主机以太网的MAC地址来指派IP地址. 一旦slave拥有一个IP地址，DHCP服务器将告诉slave去哪里获得它的初始化文件系统及内核.

开始之前
在它们正确工作之前，有一些事情需要确认. 首先检查网络连通性：

确认有一个eth0设备运行. 它看起来应该像这样：

它说MULTICAST是非常重要的，如果不是即必须重新编译包括有多播支持的内核.

安装DHCP服务器
如果网络中还没有安装一台DHCP服务器，现在就需要安装一台：

如果网络中已经安装有一台DHCP服务器，编辑配置文件来使PXE引导能正常工作.

配置DHCP服务器
在启动DHCP服务器之前，只需要编辑一个配置文件：. 复制并编辑提供的示例文件：

通常文件应该做成一个时尚的缩进式布局，看起来像这样：

块是可选的，并且应该用于需要将IP指派到同一网络拓扑中. 至少一个 应该被声明并且可选的 块允许选项中其中被分组. 一个好的示例看起来像这样：

跟在 后面的IP地址将会被查询指定的. 这个IP地址应该是tftp服务器的IP，通常就是master的IP地址. 是相对于目录的（这将会在稍后提到的tftp服务器选项中指定）. 在 块内， 选项指定一个MAC地址，同时 指派一个固定IP地址到那个特有的MAC地址. 这里有一个相当不错的的man页解释这篇HOWTO中所使用的选项. 可以键入以下命令来阅读这个man页：

启动DHCP服务器
在启动dhcp初始化脚本之前，编辑文件让它看起来像这样：

变量是DHCP服务器将要运行的设备，在这里是. 添加更多参数到 变量对于一个拥有多网卡的复杂网络拓扑环境将相当有用. 键入以下命令来启动dhcp服务器：

键入以下命令添加dhcp服务器到开机自启动脚本：

排查DHCP服务器
通过查看可以知道是否引导了一个节点. 如果一个节点成功引导，文件将会有一些看起来像是下面的这些行：

如果出现下面的信息，它大概是说配置文件有什么错误，但是DHCP服务器在正常的广播.

在每一次更改配置文件后，DHCP服务器必须重启. 键入以下命令重启服务器：

关于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).