VMware部署无盘系统(PXE+NFS)详细指南

部署结构:DHCP + TFTP + PXE + NFS

分为两个部分:

  • ✅ 服务端配置
  • 💻 客户端无盘启动

🧱 一、环境准备

角色 数量 系统版本 内存 硬盘 网络模式
服务端 1 CentOS 8 4GB 50GB NAT
客户端 1 无盘启动 2GB 同一网段

📌 关键提示:

  • 确保两台虚拟机网卡启用 PXE Boot 支持
  • VMware 中需勾选:☑️ Connect at power on

🛠 二、服务端配置(PXE + NFS)

1️⃣ 安装必要服务(CentOS 8)

1
dnf install -y dhcp-server tftp-server nfs-utils syslinux

2️⃣ 配置 DHCP 服务(/etc/dhcp/dhcpd.conf

1
2
3
4
5
6
7
subnet 192.168.136.0 netmask 255.255.255.0 {
range 192.168.136.100 192.168.136.200;
option routers 192.168.136.1;
option domain-name-servers 202.103.44.150;
filename "pxelinux.0"; # PXE 引导文件
next-server 192.168.136.128; # TFTP 服务器 IP(本机 IP)
}
1
systemctl start dhcpd && systemctl enable dhcpd

3️⃣ 配置 TFTP 服务(/var/lib/tftpboot

1
2
cp /usr/share/syslinux/* /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg

创建 PXE 启动配置:

1
2
3
4
5
6
7
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
DEFAULT vesamenu.c32
PROMPT 0
LABEL centos-nfs
KERNEL vmlinuz
APPEND initrd=initrd.img root=/dev/nfs nfsroot=192.168.136.128:/nfsroot ip=dhcp
EOF

设置权限:

1
2
3
sudo chown -R nobody:nobody /var/lib/tftpboot
sudo chmod -R 755 /var/lib/tftpboot
sudo find /var/lib/tftpboot -type f -exec chmod 644 {} \;

📁 从 CentOS ISO 提取以下文件并复制到 TFTP 目录:

  • images/pxeboot/vmlinuz
  • images/pxeboot/initrd.img

👉 目标目录:/var/lib/tftpboot/


4️⃣ 启动 TFTP 服务

1
systemctl start tftp && systemctl enable tftp

5️⃣ 准备 NFS 根文件系统

1
2
3
4
5
6
mkdir /nfsroot

# 复制根文件系统
rsync -a --exclude=/proc --exclude=/sys --exclude=/tmp --exclude=/var/tmp \
--exclude=/etc/mtab --exclude=/nfsroot --exclude=/var/lib/tftpboot \
/* /nfsroot

创建必要目录:

1
cd /nfsroot && mkdir proc sys tmp var/tmp

编辑 /nfsroot/etc/fstab,添加挂载项:

1
192.168.136.128:/nfsroot / nfs defaults 0 0

设置权限:

1
2
sudo chown -R nobody:nobody /nfsroot
sudo chmod -R 755 /nfsroot

6️⃣ 启动 NFS 服务并配置共享

1
2
3
echo "/nfsroot *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports

systemctl start nfs-server && systemctl enable nfs-server

7️⃣ 关闭防火墙与 SELinux

1
2
3
4
5
systemctl stop firewalld && systemctl mask firewalld

setenforce 0

sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config

💻 三、客户端无盘启动

1. 创建虚拟机

  • 新建虚拟机,不添加硬盘
  • 启动时选择 PXE Boot

2. 启动流程观察

1
2
3
4
5
✅ 获取 DHCP IP
✅ 下载 PXE 引导程序
✅ 加载 vmlinuz + initrd.img
✅ 内核启动
✅ 通过 NFS 挂载根目录

🚨 故障排查提示

卡顿阶段 可能原因
PXE 阶段卡住 检查防火墙、TFTP 目录权限
NFS 挂载失败 检查 /etc/exports、客户端 IP 白名单