Red Hat Training

A Red Hat training course is available for RHEL 8

20.4. 为无盘客户端配置导出的文件系统

作为在您的环境中配置远程无盘系统的一部分,您必须为无盘客户端配置一个导出的文件系统。

先决条件

流程

  1. 通过将根目录添加到 /etc/exports 目录中,将网络文件系统(NFS)服务器配置为导出根目录。有关完整的说明,请参阅 部署 NFS 服务器
  2. 将 Red Hat Enterprise Linux 的完整版本安装到根目录中,以容纳整个无盘客户端。为此,您可以安装新的基础系统或克隆现有的安装。

    • 通过使用导出的文件系统的路径替换 exported-root-directory,将 Red Hat Enterprise Linux 安装到导出的位置:

      # yum install @Base kernel dracut-network nfs-utils --installroot=exported-root-directory --releasever=/

      通过将 releasever 选项设置为 /,可以从主机(/)系统中检测到 releasever。

    • 使用 rsync 工具与正在运行的系统同步:

      # rsync -a -e ssh --exclude='/proc/' --exclude='/sys/' \ example.com:/ exported-root-directory
      • 使用要通过 rsync 工具同步的正在运行的系统的主机名替换 example.com
      • 使用导出的文件系统的路径替换 exported-root-directory

        请注意,对于这个选项,您必须有一个单独的现有运行系统,通过以上命令将其克隆到服务器。

您需要完全配置准备导出的文件系统,然后才能将其与无盘客户端一起使用。按照以下流程完成配置。

配置文件系统

  1. 将无盘客户端支持的内核(vmlinuz-_kernel-version_pass:attributes)复制到 tftp 引导目录中:

    # cp /exported-root-directory/boot/vmlinuz-kernel-version /var/lib/tftpboot/pxelinux/
  2. 在本地创建 initramfs-kernel-version.img 文件,并将其移到支持 NFS 的根目录中:

    # dracut --add nfs initramfs-kernel-version.img kernel-version

    例如:

    # dracut --add nfs /exports/root/boot/initramfs-5.14.0-202.el9.x86_64.img 5.14.0-202.el9.x86_64

    创建 initrd 的示例,使用当前运行的内核版本,并覆盖现有镜像:

    # dracut -f --add nfs "boot/initramfs-$(uname -r).img" "$(uname -r)"
  3. initrd 的文件权限改为 0644

    # chmod 0644 /exported-root-directory/boot/initramfs-kernel-version.img
    警告

    如果您不更改 initrd 文件权限,则 pxelinux.0 引导装载程序会失败,并显示 "file not found" 错误。

  4. 将生成的 initramfs-kernel-version.img 文件复制到 tftp 引导目录中:

    # cp /exported-root-directory/boot/initramfs-kernel-version.img /var/lib/tftpboot/pxelinux/
  5. /var/lib/tftpboot/pxelinux/pxelinux.cfg/default 文件中添加以下配置,来编辑使用 initrd 和内核的默认引导配置:

    default menu.c32
    prompt 0
    menu title PXE Boot Menu
    ontimeout rhel8-over-nfsv4.2
    timeout 120
    label rhel8-over-nfsv4.2
      menu label Install diskless rhel8{} nfsv4.2{}
      kernel $vmlinuz
      append initrd=$initramfs root=nfs4:$nfsserv:/:vers=4.2,rw rw panic=60 ipv6.disable=1 console=tty0 console=ttyS0,115200n8
    label rhel8-over-nfsv3
      menu label Install diskless rhel8{} nfsv3{}
      kernel $vmlinuz
      append initrd=$initramfs root=nfs:$nfsserv:$nfsroot:vers=3,rw rw panic=60 ipv6.disable=1 console=tty0 console=ttyS0,115200n8
    • 此配置指示无盘客户端 root 以读/写格式挂载导出的文件系统(/exported-root-directory)。
  6. 可选:使用以下配置编辑 /var/lib/tftpboot/pxelinux/pxelinux.cfg/default 文件,来以 只读 格式挂载文件系统:

    default rhel8
    
    label rhel8
      kernel vmlinuz-kernel-version
      append initrd=initramfs-kernel-version.img root=nfs:server-ip:/exported-root-directory ro
  7. 重启 NFS 服务器:

    # systemctl restart nfs-server.service

现在,您可以将 NFS 共享导出到无盘客户端。这些客户端可以通过预引导执行环境(PXE),通过网络引导。