PXE协议详解:
PXE,预启动执行环境(Preboot eXecution Environment,PXE,也被称为预执行环境)提供了一种使用网络接口(Network Interface)启动计算机的机制。这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统。
PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使计算机通过网络启动。协议分为client和server两端,支持工作站通过网络从远端服务器下载映像,并由此支持来自网络的操作系统的启动过程,其启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中并执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统
PXE工作原理:
1.PXE client从自己的PXE网卡启动,向本网络中的DHCP服务器请求ip地址
2.DHCP服务器收到dhcp请求后,分配dhcp地址池中ip给PXE client
3.PXE client向本网络中的TFTP服务器索取bootstarp文件(core.efi)
4.PXE client取得bootstarp文件后之执行pxelinux.0(grub.cfg)文件引导,使用pxelinux环境来引导os安装程序。
5.PXE client然后读取pxelinux.cfg(mips64el)文件夹中的default(grub.cfg)引导文件,通过TFTP服务器加载内核vmlinuz和根文件系统(boot.msg,vesamenu.c32,initrd.img,splash.jpg),根据grub启动菜单选择共享服务器nfs上面下载系统安装包开始安装系统。
服务安装及配置流程(虚拟机IP:192.168.1.228)
一、DHCP安装及配置
[root@localhost ~]# yum install -y dhcp*
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
##############dhcp.conf
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option arch code 93 = unsigned integer 16;
subnet 192.168.1.0 netmask 255.255.255.0 {
#option routers 192.168.1.254;
option time-offset -18000;
range dynamic-bootp 192.168.1.2 192.168.1.253;
default-lease-time 21600;
max-lease-time 43200;
#range 192.168.1.2 192.168.1.253
class "pxeclinets" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.1.228; #服务器IP,也就是本地IP
if option arch = 00:07 or arch = 00:09 {
filename "uefi/core.efi";
} else {
#filename "pxelinux/pxelinux.0";
filename "core.efi"; #引导文件
}
}
}
#############dhcp.conf
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl enable dhcpd
二、TFTP安装及配置
[root@localhost ~]# yum install -y tftp*
##安装xinetd守护进程,因为tftp依赖于xinetd
[root@localhost ~]# yum install -y xinetd
[root@localhost ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot #这里是默认路径(即为根目录)
disable = no #这里改为no
per_source = 11
cps = 100 2
flags = IPv4
}
~
~
关闭并配置开机自动关闭系统防火墙(重要!否则会导致PXE Client无法访问TFPT服务)
# systemctl stop firewalld
# systemctl disable firewalld
启动并配置开机自动启动xinetd进程
# systemctl start xinetd; systemctl restart xinetd(tftp服务搜xinetd服务管理)
# systemctl enable xinetd
# systemctl start tftp
三、NFS安装及配置(nfs-utils)
[root@localhost ~]# yum install -y nfs*
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl status nfs
[root@localhost ~]# vim /etc/exports
######配置iso文件路径及IP(虚拟机光驱路径)
/run/media/root/UOS 192.168.1.228/24(rw,sync,all_squash)
######配置iso文件路径及IP
######挂载文件目录
[root@localhost ~]# exportfs -a
[root@localhost ~]# showmount -e 192.168.1.228
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
Loongarch平台安装文件准备及配置
1、根据dhcp.conf放置core.efi文件
2、提取ISO中grub.cfg文件到/var/lib/tftpboot/目录
set default=1
set timeout=6
set menu_color_normal=white/black
set menu_color_highlight=yellow/black
search --no-floppy --set=root -l 'Fedora-MATE'
menuentry 'Install UnionTech OS Desktop 20 Professional' {
echo 'Loading kernel ...'
linux /boot/vmlinuz-4.19.0-loongson-3-desktop root=live:CDLABEL=UOS console=ttyS0,115200 rdinit=/init loongson loglevel=7 ro rd.live.image rd.live.dir=live rd.live.squashimg=filesystem.squashfs livecd-installer locales=zh_CN.UTF-8 boot=live rd.luks=0 rd.md=0
echo 'Loading ramdisk ...'
initrd /boot/initrd.img-4.19.0-loongson-3-desktop
echo 'boot ...'
boot
echo 'after boot ...'
}
menuentry 'PXE Install UOS' {
echo 'Loading kernel ...'
linux /mips64el/vmlinuz-4.19.0-loongson-3-desktop root=/dev/nfs nfsroot=192.168.1.228:/run/media/root/UOS rw loglevel=7 console=ttyS0,115200 console=tty rd.live.image rd.live.dir=live rd.live.squashimg=filesystem.squashfs livecd-installer locales=zh_CN.UTF-8 boot=live rd.luks=0 rd.md=0 rd.debug ip=dhcp
#linux /mips64el/vmlinuz-4.19.0-loongson-3-desktop root=/dev/nfs nfsroot=192.168.1.228:/var/nfs/mips64el rw console=tty livecd-installer locales=zh_CN.UTF-8 boot=live
echo 'Loading initrd ...'
initrd /mips64el/initrd.img-4.19.0-loongson-3-desktop
}
menuentry 'Test Install OS' {
echo 'Loading kernel ...'
linux /mips64el/vmlinuz-4.19.0-loongson-3-desktop root=/dev/nfs nfsroot=192.168.1.228:/mnt/hgfs/vmshare/loongarch64 rw loglevel=7 console=ttyS0,115200 console=tty rd.live.image rd.live.dir=live rd.live.squashimg=filesystem.squashfs livecd-installer locales=zh_CN.UTF-8 boot=live rd.luks=0 rd.md=0 rd.debug ip=dhcp
echo 'Loading ramdisk ...'
initrd /mips64el/initrd.img-4.19.0-loongson-3-desktop
boot
}
3、根据exports中设置的共享路径设置grub.cfg文件
4、根据grub.cfg文件放置系统内核文件(vmlinuz,initrd.img)
/var/lib/tftpboot为根目录
************注意事项************
1、权限不足,exports中要添加(rw,sync,all_squash)
2、IP不正确,要与exports中地址一致
3、nfs未正常开启
4、未正确配置exports并启用
5、内核文件有问题(vmlinuz)