通过 NFS 服务器共享 Ubuntu 18.10 ISO/DVD

登录到pxe服务器。使用 yum 命令安装 NFS 包。

[root@pxe-server ~]# yum install -y nfs-utils

启动并启用 NFS 服务。

[root@pxe-server ~]# systemctl start nfs-server
[root@pxe-server ~]# systemctl enable nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

创建用于共享 Ubuntu 18.10 ISO 的目录。

[root@pxe-server ~]# mkdir /nfsshare
[root@pxe-server ~]# chown nfsnobody:nfsnobody /nfsshare

在 CentOS 7.5 防火墙中允许 NFS 和相关端口。

[root@pxe-server ~]# firewall-cmd --permanent --add-service={nfs,mountd,rpc-bind}
success
[root@pxe-server /]# firewall-cmd --reload
success

调整 SELinux 权限。

[root@pxe-server /]# semanage fcontext --add -t nfs_t '/nfsshare(/.*)?'
[root@pxe-server /]# restorecon -Rv /nfsshare/
restorecon reset /nfsshare context unconfined_u:object_r:var_t:s0->unconfined_u:object_r:nfs_t:s0

为所有客户端导出 /nfsshare 目录。

[root@pxe-server /]# echo "/nfsshare *(ro)" >> /etc/exports
[root@pxe-server /]# exportfs -r

添加 Ubuntu 18.10 Server ISO/DVD 并将其挂载到 /mnt/iso(我们可以根据自己的选择使用任何挂载点)。

[root@pxe-server ~]# mount -t iso9660 /dev/cdrom /mnt/iso
mount: /dev/sr0 is write-protected, mounting read-only

将 /mnt/iso 目录的内容复制到 NFS 服务器。

[root@pxe-server ~]# cp -rf /mnt/iso /nfsshare/ubuntu18

创建一个用于自动安装 Ubuntu 的 Kickstart 文件

我们必须在 /nfsshare/ubuntu18/preseed/ 目录中为 Ubuntu 18.10 编写一个 Kickstart 文件,以便 PXE 客户端可以通过 NFS 服务访问它。

[root@pxe-server ~]# vi /nfsshare/ubuntu18/preseed/ubuntu.seed

kickstart文件内容参考,根据需求进行修改

# Enable extras.ubuntu.com.
d-i     apt-setup/extras        boolean true
# Install the Ubuntu desktop.
tasksel tasksel/first   multiselect ubuntu-desktop
# On live DVDs, don't spend huge amounts of time removing substantial
# application packages pulled in by language packs. Given that we clearly
# have the space to include them on the DVD, they're useful and we might as
# well keep them installed.
ubiquity        ubiquity/keep-installed string icedtea6-plugin openoffice.org
#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone Asia/Karachi
#Root password
rootpw --disabled
#Initial user (user with sudo capabilities)
user ubuntu --fullname "jackli" --password jackli1234
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Installation media
nfs --server=192.168.1.1011 --dir=/nfsshare/ubuntu18/
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel
#Basic disk partition
part / --fstype ext4 --size 1 --grow --asprimary
part swap --size 1024
part /boot --fstype ext4 --size 256 --asprimary
#System authorization infomation
auth  --useshadow  --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
#Firewall configuration
firewall --disabled --trust=eth0 --ssh

为 Ubuntu 18.10 安装创建菜单项

为基于 BIOS 的客户端编辑 PXE 启动菜单。

[root@pxe-server ~]# vi /var/lib/tftpboot/pxelinux.cfg/default

其中添加 Ubuntu 18.10 安装的菜单项。

default vesamenu.c32
prompt 0
timeout 30
menu title JackLi's PXE Menu
label Install RHEL 7.5
kernel /networkboot/rhel7/vmlinuz
append initrd=/networkboot/rhel7/initrd.img inst.repo=ftp://192.168.1.1011/pub/rhel7 ks=ftp://192.168.1.1011/pub/rhel7/rhel7.cfg
label Install RHEL 6.0 (64-bit)
kernel /networkboot/rhel6/vmlinuz
append initrd=/networkboot/rhel6/initrd.img inst.repo=ftp://192.168.1.1011/pub/rhel6 ks=ftp://192.168.1.1011/pub/rhel6/rhel6.cfg
label Install Ubuntu 18.10 Server
menu label Install Ubuntu 18.10 Server
kernel networkboot/ubuntu18/linux
append vga=788 initrd=networkboot/ubuntu18/initrd.gz ks=nfs:192.168.1.1011:/nfsshare/ubuntu18/preseed/ubuntu.seed --- quiet

为基于 UEFI 的客户端编辑 PXE 启动菜单。
有关 UEFI 的更多信息,请参阅在 CentOS 7 中向 PXE 服务器添加 UEFI 支持。

[root@pxe-server ~]# vi /var/lib/tftpboot/grub.cfg

在此文件中添加 Ubuntu 18.10 安装的菜单项。

set timeout=60
menuentry 'Install RHEL 7.5' {
        linuxefi /networkboot/rhel7/vmlinuz inst.repo=ftp://192.168.1.1011/pub/rhel7/ inst.ks=ftp://192.168.1.1011/pub/rhel7/rhel7.cfg
        initrdefi /networkboot/rhel7/initrd.img
}
menuentry 'Install RHEL 6.0' {
        linuxefi /networkboot/rhel6/vmlinuz inst.repo=ftp://192.168.1.1011/pub/rhel6/ inst.ks=ftp://192.168.1.1011/pub/rhel6/rhel6.cfg
        initrdefi /networkboot/rhel6/initrd.img
}
menuentry "Install Ubuntu 18.10 Server" {
        set gfxpayload=keep
        linuxefi        /networkboot/ubuntu18/linux inst.repo=nfs:192.168.1.1011:/nfsshare/ubuntu18 inst.ks=nfs:192.168.1.1011:/nfsshare/ubuntu18/preseed/ubuntu.seed
        initrdefi       /networkboot/ubuntu18/initrd.gz
}

启动PXE 客户端即可开始安装ubuntu系统。

配置 CentOS 7 PXE 服务器以安装 Ubuntu 18.10

本文假设我们已经有一台PXE服务器。我们将配置它来安装ubuntu系统。

如果还没有,参考之前的教程 在 RHEL/CentOS 7 中搭建 PXE 引导服务器

欢迎来到之路教程(on itroad-com)

将启动镜像复制到 tftpboot 目录

Ubuntu ISO 中的启动镜像不适用于网络启动 因此,我们从 Ubuntu 网站下载了网络启动镜像。

[root@pxe-server ~]# wget http://archive.ubuntu.com/ubuntu/dists/cosmic/main/installer-amd64/current/images/netboot/netboot.tar.gz

解压下载 tar包。

[root@pxe-server ~]# mkdir netboot
[root@pxe-server ~]# tar xvf netboot.tar.gz -C netboot

我们需要将 initrd.gz 和 linux 文件从 netboot 目录 ~/netboot/ubuntu-installer/amd64/ 复制到 /var/lib/tftpboot/networkboot/ubuntu18 目录。
这些文件将在 PXE 启动菜单的菜单项中引用。

[root@pxe-server ~]# mkdir /var/lib/tftpboot/networkboot/ubuntu18
[root@pxe-server ~]# cp ~/netboot/ubuntu-installer/amd64/{linux,initrd.gz} /var/lib/tftpboot/networkboot/ubuntu18/
日期:2020-09-17 00:11:53 来源:oir作者:oir