99 lines
2.7 KiB
Markdown
99 lines
2.7 KiB
Markdown
---
|
||
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=<ks.cfg url>
|
||
```
|
||
- 在 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=<ks.cfg url>
|
||
```
|
||
- 修改文件权限,确保 dnsmasq 用户可读
|
||
```bash
|
||
chown -R dnsmasq.dnsmasq /var/ftpd/
|
||
```
|
||
|
||
# 装机
|
||
- 把待安装机器和 dnsmasq 服务器接入同一个交换机(无其他 dhcp 广播)
|
||
- 启动待安装机器,选择 pxe 引导,从第一个启动项启动
|
||
|