PXE配置

安装

安装dhcp、tftp、nfs,前面的博客有说明。

安装syslinux

1
sudo apt install syslinux syslinux-common pxelinux 

配置

复制文件到/var/tci/tftp(tftp的目录)

1
2
3
4
5
6
7
8
9
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /var/tci/tftp/
cp /usr/lib/syslinux/modules/bios/libutil.c32 /var/tci/tftp/
cp /usr/lib/syslinux/modules/bios/menu.c32 /var/tci/tftp/
cp /usr/lib/PXELINUX/lpxelinux.0 /var/tci/tftp/
cp /usr/lib/PXELINUX/pxelinux.0 /var/tci/tftp/
cp /boot/initrd.img-5.15.0-72-generic /var/tci/tftp/
cp /boot/initrd.img-5.15.0-73-generic /var/tci/tftp/
cp /boot/vmlinuz-5.15.0-72-generic /var/tci/tftp/
cp /boot/vmlinuz-5.15.0-73-generic /var/tci/tftp/

/var/tci/tftp/下建立pxelinux.cfg目录,然后在pxelinux.cfg目录下建立default文件
·

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 菜单,还有一些可选如vesamenu.c32 
DEFAULT menu.c32

# 直接复制的内核
LABEL ubuntu20.4-73
KERNEL vmlinuz-5.15.0-73-generic
APPEND initrd=initrd.img-5.15.0-73-generic root=/dev/nfs nfsroot=192.168.8.88:/var/tci/netboot/root ip=bootp rw selinux=0 nomodeset vga=0x314
prompt 1

# 直接复制的内核
LABEL ubuntu20.4-72
KERNEL vmlinuz-5.15.0-72-generic
APPEND initrd=initrd.img-5.15.0-72-generic root=/dev/nfs nfsroot=192.168.8.88:/var/tci/netboot/root ip=bootp rw selinux=0 nomodeset vga=0x314
prompt 1

# mkinitramfs -o 打包的
LABEL nfs-mk-o
kernel vmlinuz-5.15.0-73-generic
append initrd=initrd.nfs root=/dev/nfs nfsroot=192.168.8.88:/var/tci/netboot/root ip=bootp rw selinux=0 nomodeset vga=0x314
prompt 1


LABEL img #
KERNEL vmlinuz-5.15.0-73-generic
APPEND initrd=initrd.img root=/dev/nfs nfsroot=192.168.8.88:/var/tci/netboot/root ip=bootp rw selinux=0 nomodeset vga=0x314
prompt 1

# cpio打包的
LABEL cpio
# 可以设置不同的内核
kernel vmlinuz-5.15.0-73-generic
append initrd=initrd.cpio root=/dev/nfs nfsroot=192.168.8.88:/var/tci/netboot/root ip=dhcp rw selinux=0 nomodeset vga=0x314
prompt 1
# 等待时间6秒
timeout 60

查看/var/tci/tftp/

1
ls /var/tci/tftp/
1
2
initrd.1     initrd.img                    initrd.img-5.15.0-73-generic  ldlinux.c32  linux        menu.c32  pxelinux.0    vesamenu.c32               vmlinuz-5.15.0-73-generic
initrd.cpio initrd.img-5.15.0-72-generic initrd.nfs libutil.c32 lpxelinux.0 modules pxelinux.cfg vmlinuz-5.15.0-72-generic

无盘系统配置

构建无盘系统

安装debootstrap

1
sudo apt install debootstrap

利用debootstrap/var/tci/netboot/root

1
mkdir -p /var/tci/netboot/root/ 

构建系统

x64

1
debootstrap --arch=amd64 --include=linux-image-amd64,systemd,systemd-coredump,grub-efi-amd64,grub-legacy,grub-pc,wget,locales,vim,openssh-server,sudo,bash-completion bullseye /var/tci/netboot/root https://mirrors.tuna.tsinghua.edu.cn/debian/

arm

1
debootstrap --arch=arm64 --include=linux-image-amd64,systemd,systemd-coredump,grub-efi,grub-legacy,grub-pc,wget,locales,vim,openssh-server,sudo,bash-completion bullseye /var/tci/netboot/root https://mirrors.tuna.tsinghua.edu.cn/debian/

--arch=amd64 架构
--include=linux-image-amd64,systemd,systemd-coredump,grub-efi-amd64,locales,vim,openssh-server,sudo,bash-completion 模块

配置无盘系统

修改/var/tci/netboot/root/etc/initramfs-tools/initramfs.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# initramfs.conf
# Configuration file for mkinitramfs(8). See initramfs.conf(5).
#
# Note that configuration options from this file can be overridden
# by config files in the /etc/initramfs-tools/conf.d directory.

#
# MODULES: [ most | netboot | dep | list ]
#
# most - Add most filesystem and all harddrive drivers.
#
# dep - Try and guess which modules to load.
#
# netboot - Add the base modules, network modules, but skip block devices.
#
# list - Only include modules from the 'additional modules' list
#

MODULES=netboot # 修改,网络启动
BOOT=nfs # 修改,nfs
#
# BUSYBOX: [ y | n | auto ]
#
# Use busybox shell and utilities. If set to n, klibc utilities will be used.
# If set to auto (or unset), busybox will be used if installed and klibc will
# be used otherwise.
#

BUSYBOX=auto

#
# KEYMAP: [ y | n ]
#
# Load a keymap during the initramfs stage.
#

KEYMAP=n

#
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
#

COMPRESS=gzip

#
# DEVICE: ...
#
# Specify a specific network interface, like eth0
# Overridden by optional ip= or BOOTIF= bootarg
#

DEVICE=

#
# NFSROOT: [ auto | HOST:MOUNT ]
#

NFSROOT=auto

#
# RUNSIZE: ...
#
# The size of the /run tmpfs mount point, like 256M or 10%
# Overridden by optional initramfs.runsize= bootarg
#

RUNSIZE=10%

#
# FSTYPE: ...
#
# The filesystem type(s) to support, or "auto" to use the current root
# filesystem type
#

FSTYPE=auto

配置无盘自动挂载nfs

1
vim /var/tci/netboot/root/etc/fstab
1
2
3
# UNCONFIGURED FSTAB FOR BASE SYSTEM
proc /proc proc defaults 0 0 # 增加
192.168.8.88:/var/tci/netboot/root / nfs defaults,rw 0 0 # 增加

配置无盘hosts

1
vim /var/tci/netboot/root/etc/hosts
1
2
3
4
5
127.0.0.1       localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 vm # 增加这一行,机器名

配置无盘网络

1
vim /var/tci/netboot/root/etc/network/interfaces
1
2
3
4
5
6
7
8
9
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source /etc/network/interfaces.d/*
# The primary network interface
auto ens33
allow-hotplug ens33
iface ens33 inet idhcp # 使用DHCP
dns-nameservers 192.168.8.88 # DNS地址
iface default inet dhcp # 默认使用dhcp

auto

在系统启动的时候启动网络接口,无论网络接口有无连接 (插入网线)。如果该接口配置了 DHCP,则无论有无网线,系统都会去获取 DHCP。并且如果没有插入网线,则等该接口超时后才会继续 DHCP。

allow-hotplug

只有当内核从网络接口检测到热插拔事件后才会启动该接口。如果系统开机时该接口没有插入网线,则系统不会启动该接口。系统启动后,如果插入网线,系统会自动启动该接口。

修改无盘root密码

1
2
cd /var/tci/netboot/root/
chroot .
1
2
3
4
root@vm:/# passwd root
New password:
Retype new password:
passwd: password updated successfully

PXE测试

启动

pxe

菜单

pxe

无盘系统

pxe