CentOS8.4搭建PXE启动Ubuntu-server20.04(UEFI)

本次实验使用安装镜像的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
>}

附上下载链接

​​​​​​用于PXE引导UEFI的文件grubx64.efi-Linux文档类资源-CSDN下载

用于PXE引导UEFI的文件shim.efi-Linux文档类资源-CSDN下载

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cloud@Linux99.cn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值