本次实验使用安装镜像的Yum源
1.删除自带的网络源,关闭防火墙,Selinux
rm -rfv /etc/yum.repos.d/*
systemctl disable --now firewalld
setenforce 0
2.添加本地仓库源
mount -o loop /dev/sr0 /mnt/ #挂载镜像到mnt目录
vi /etc/yum.repos.d/centos.repo #创建repo文件
>[BaseOS]
>name=BaseOS
>baseurl=file:///mnt/BaseOS
>gpgcheck=0
>enabled=1
>
>[AppStream]
>name=AppStream
>baseurl=file:///mnt/AppStream
>gpgcheck=0
>enabled=1
dnf clean all #清除缓存
dnf makecache #重建缓存
3.安装http tftp dhcp服务
dnf install httpd tftp-server dhcp-server -y
systemctl enable httpd tftp dhcpd #配置开机启动
4.创建tftp配置文件(此文件不存在 需手动创建)
vi /etc/xinetd.d/tftp
>service tftp
>{
> socket_type = dgram
> protocol = udp
> wait = yes
> user = root
> server = /usr/sbin/in.tftpd
> server_args = -s /var/lib/tftpboot #引导文件路径
> disable = no
> per_source = 11
> cps = 100 2
> flags = IPv4
>}service tftp=
>{
> socket_type = dgram
> protocol = udp
> wait = yes
> user = root
> server = /usr/sbin/in.tftpd
> server_args = -s /var/lib/tftpboot
> disable = no
> per_source = 11
> cps = 100 2
> flags = IPv4
>}
5.配置dhcp服务
配置的网段可根据自己的网络环境修改
vi /etc/dhcp/dhcpd.conf
>filename "shim.efi"; #引导文件
>next-server 192.168.1.1; #tftp服务器地址
>allow booting;
>allow bootp;
>default-lease-time 600;
>max-lease-time 7200;
>
>subnet 192.168.1.0 netmask 255.255.255.0 {
> range 192.168.1.2 192.168.1.254;
> option domain-name-servers ns1.pxe.org;
> option domain-name "pxe.org";
> option routers 192.168.1.1;
> option broadcast-address 192.168.1.255;
> default-lease-time 600;
> max-lease-time 7200;
>}
6.配置http服务
这里我们需要用到ubuntu-server的安装镜像
vi /etc/httpd/conf.d/welcome.conf
注释以下内容
#<LocationMatch "^/+$">
# Options -Indexes
# ErrorDocument 403 /.noindex.html
#</LocationMatch>
systemctl start httpd #启动httpd服务
ubuntu-20.04.3-live-server-amd64.iso /var/www/html/ubuntu.iso #拷贝ubuntu安装镜像
7.拷贝所需要的启动文件到/var/lib/tftpboot/
rpm2cpio /mnt/BaseOS/Packages/shim-x64-15-15.el8_2.x86_64.rpm | cpio -idmv
mv boot/efi/EFI/centos/shimx64.efi /var/lib/tftpboot/shim.efi
mount -o loop /var/www/html/ubuntu.iso /opt/ #挂载ubuntu镜像到opt目录
cp /opt/casper/initrd /var/lib/tftpboot/
cp /opt/casper/vmlinuz /var/lib/tftpboot/
cp /opt/EFI/BOOT/grubx64.efi /var/lib/tftpboot/
8.编辑引导配置文件
vi /var/lib/tftpboot/grub.cfg
>set default="0"
>
>function load_video {
> insmod efi_gop
> insmod efi_uga
> insmod video_bochs
> insmod video_cirrus
> insmod all_video
>}
>
>load_video
>set gfxpayload=keep
>insmod gzio
>insmod part_gpt
>insmod ext2
>
>set timeout=60
>menuentry 'Install Ubuntu 20.04.3' --class fedora --class gnu-linux --class gnu --class os {
> set gfxpayload=keep
> linuxefi vmlinuz ip=dhcp url=http://192.168.1.1/ubuntu.iso quiet
> initrdefi initrd
>}
附上下载链接