diff --git a/content/post/pxe-dnsmasq.md b/content/post/pxe-dnsmasq.md deleted file mode 100644 index a7c9c5d..0000000 --- a/content/post/pxe-dnsmasq.md +++ /dev/null @@ -1,98 +0,0 @@ ---- -title: "Dnsmasq 实现网络 PXE 装机" -date: 2019-11-08T15:52:55+08:00 -lastmod: 2019-11-08T15:52:55+08:00 -tags: ["dnsmasq", "pxe"] -categories: ["OS"] ---- - -## 把 dnsmasq 配置成 pxe 服务器 -- 安装 dnsmasq - ```bash - # rhel - yum install dnsmasq - # archlinux - pacman -S dnsmasq - ``` -- 修改配置 /etc/dnsmasq.conf - ```ini - port=0 # 用不着 dns 功能,可以关闭 - #interface=ens8u2u4u1 # 指定网卡 - dhcp-range=10.0.86.1,10.0.86.9,255.255.255.0,1h - #dhcp-boot=pxelinux.0 # bios 引导 - dhcp-boot=grubx64.efi # efi 引导 - enable-tftp - tftp-root=/var/ftpd - ``` -- 启动 dnsmasq - ```bash - systemctl start dnsmasq - ``` - -## 安装 CentOS7/8 -- **本次测试使用 CentOS7.7 和 CentOS8.0 镜像** - -### 挂载系统镜像,提供软件源服务 -- 下载 centos7/8 镜像到 dnsmasq 服务器 -- 挂载镜像到 /mnt 目录 - ```bash - mount -o loop xxxx.iso /mnt - ``` -- 直接在系统镜像的挂载目录(/mnt)启动 http 服务 - ```bash - cd /mnt - python2 -m SimpleHTTPServer 10086 - # 或者使用 python3 - python3 -m http.server 10086 - ``` - -### 网络 BIOS 引导 -- 复制 centos7/8 镜像里的启动文件到 dnsmasq 服务器的 /var/ftpd/ 下 - ```bash - cd /var/ftpd - cp /mnt/isolinux/* . - mkidr pxelinux.cfg - mv isolinux.cfg pxelinux.cfg/default - ``` -- 打开 /var/ftpd/pxelinux.cfg/default,修改第一个启动项 - ``` - label linux - menu label ^Install CentOS 7/8 - kernel vmlinuz - append initrd=initrd.img inst.repo=http://10.0.86.1:10086/ quiet - # ks 参数: inst.ks= - ``` -- 在 centos7/8 上安装 syslinux - ```bash - yum install syslinux # centos7 - dnf install syslinux # centos 8 - ``` -- 把 /user/share/syslinux/pxelinux.0 复制到 dnsmasq 服务器的 /var/ftpd/ 下 -- 修改文件权限,确保 dnsmasq 用户可读 - ```bash - chown -R dnsmasq.dnsmasq /var/ftpd/ - ``` - -### 网络 EFI 引导 -- **不支持 secure boot** -- 复制 centos7/8 镜像里的启动文件到 dnsmasq 服务器的 /var/ftpd/ 下 - ```bash - cp -a /mnt/EFI/BOOT/* /var/ftpd/ - ``` -- 打开 /var/ftpd/grub.cfg,修改第一个启动项 - ``` - menuentry 'Install CentOS 7/8' --class fedora --class gnu-linux --class gnu --class os { - linuxefi vmlinuz inst.repo=http://10.0.86.1:10086/ quiet - initrdefi initrd.img - } - # ks 参数: inst.ks= - ``` -- 修改文件权限,确保 dnsmasq 用户可读 - ```bash - chown -R dnsmasq.dnsmasq /var/ftpd/ - ``` - -## 装机 -- 把待安装机器和 dnsmasq 服务器接入同一个交换机(无其他 dhcp 广播) -- 启动待安装机器,选择 pxe 引导,从第一个启动项启动 - diff --git a/content/post/pxe.md b/content/post/pxe.md new file mode 100644 index 0000000..862c9e8 --- /dev/null +++ b/content/post/pxe.md @@ -0,0 +1,150 @@ +--- +title: "PXE 网络装机" +date: 2019-11-08T15:52:55+08:00 +lastmod: 2024-11-08T18:17:00+08:00 +tags: ["pxe"] +categories: ["OS"] +--- + +## 部署 dhcp 和 tft 服务 +- 安装 dnsmasq + ```bash + # rhel + yum install dnsmasq + # archlinux + pacman -S dnsmasq + ``` + +- 修改配置 /etc/dnsmasq.conf + ```ini + port=0 # 用不着 dns 功能,可以关闭 + dhcp-range=10.0.86.2,10.0.86.9,255.255.255.0,1h + #dhcp-boot=pxelinux.0 # bios 引导(未测试) + dhcp-boot=grubx64.efi # efi 引导 + enable-tftp + tftp-root=/var/ftp + ``` + +- 在其中一个网卡上配置 ip: 10.0.86.1/24 +- 启动 dnsmasq + ```bash + systemctl start dnsmasq + ``` + +## 挂载操作系统镜像 +- 目前已测试过的操作系统 + * centos 7/8/9 + * rockyLinux 8/9 + * 银河麒麟服务器版 V10 SP3 + * 华为欧拉 24.03 LTS + +- 上传操作系统镜像 iso 到 dnsmasq 服务器 +- 挂载 iso 到 /mnt/iso 目录 + ```bash + mkdir /mnt/iso + mount -o loop xxxx.iso /mnt/iso + ``` + +- 在系统镜像的挂载目录(/mnt)启动 http 服务 + ```bash + cd /mnt + python2 -m SimpleHTTPServer 10086 + # 或者使用 python3 + python3 -m http.server 10086 + ``` + +## 创建 kicksart 自动安装脚本 +- 创建 /mnt/ks.cfg 文件,内容如下 + ``` + # Use graphical install + graphical + + # Keyboard layouts + keyboard --vckeymap=cn --xlayouts='cn' + # System language + lang zh_CN.UTF-8 + + # 注释其中可能存在的 U盘或光盘安装设备配置项 “harddrive” + # Use hard drive installation media + #harddrive --dir= --partition=LABEL=openEuler-24.03-LTS-x86_64 + + %packages + @^minimal-environment + + %end + + # Run the Setup Agent on first boot + firstboot --enable + + # 确认系统硬盘设备名,sata 或 sas 第一块盘是 sda,nvme 第一块盘是 nvme0n1 + # Generated using Blivet version 3.8.2 + ignoredisk --only-use=sda + # Partition clearing information + clearpart --none --initlabel + # Disk partitioning information + # 创建 efi 分区,传统 BIOS 引导不需要 efi 分区 + part /boot/efi --fstype="efi" --ondisk=sda --size=256 --fsoptions="umask=0077,shortname=winnt" + # 这里指定 size 是 99GB,可按实际容量调整 + part / --fstype="xfs" --ondisk=sda --size=101376 + + # System timezone + timezone Asia/Shanghai --utc + + # Root password + rootpw --iscrypted $y$j9T$VB3hYFCRRHaCTsOM/DwE2KUX$Ci6f4pASC887sewVuvjFqTXHN.g5nsVsPoca9RntMdD + + # 安装完成后的操作,这里禁用了 selinux 和自带的防火墙 + %post + /usr/bin/systemctl disable firewalld + sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config + %end + ``` + +## 复制网络引导文件 +### EFI 引导 +- **不支持 secure boot** +- 复制镜像里的启动文件到 dnsmasq 服务器的 /var/ftp/ 下 + ```bash + cp -a /mnt/EFI/BOOT/* /var/ftp/ + cp -a /mnt/images/pxeboot/{initrd.img,vmlinuz} /var/ftp/ + ``` + +- 编辑 /var/ftp/grub.cfg,修改第一个启动项 + ``` + menuentry ... --class gnu-linux --class gnu --class os { + linuxefi vmlinuz inst.repo=http://10.0.86.1:10086/iso inst.ks=http://10.0.86.1:10086/ks.cfg ... + initrdefi initrd.img + } + # 增加 inst.repo 和 inst.ks 这俩参数,其他不变 + ``` + +### 传统 BIOS 引导(未测试) +- 复制镜像里的启动文件到 dnsmasq 服务器的 /var/ftp/ 下 + ```bash + cd /var/ftp + cp /mnt/isolinux/* . + mkidr pxelinux.cfg + mv isolinux.cfg pxelinux.cfg/default + ``` + +- 打开 /var/ftp/pxelinux.cfg/default,修改第一个启动项 + ``` + label linux + menu label ... + kernel vmlinuz + append initrd=initrd.img inst.repo=http://10.0.86.1:10086 ... + # ks 参数: inst.ks= + ``` + +- 在 centos7/8 上安装 syslinux + ```bash + yum install syslinux # centos7 + dnf install syslinux # centos 8 + ``` + +- 把 /user/share/syslinux/pxelinux.0 复制到 dnsmasq 服务器的 /var/ftp/ 下 + +## 装机 +- 把待安装机器和 pxe 服务器接入同一个交换机(无其他 dhcp 广播) +- 启动待安装机器,选择 pxe 引导 +