搭建PXE服務及實現安裝銀河麒麟桌面操作系統
一、安裝PXE服務器前的准備
服務器操作系統:銀河麒麟高級服務器操作系統V10 SP1
服務器IP地址:em1 172.17.31.163 用於連接外網,可以進行yum安裝相關服務
em2 192.168.1.1 用於DHCP服務網段的配置
x86安裝引導文件:grubx64.efi(如果是其他架構平台,則需要更改該文件)
x86鏡像文件:Kylin-Desktop-V10.1-Release-Build1-20201128-x86_64.iso
二、安裝PXE服務
1、配置dhcp服務
(1)檢查系統是否有dhcp服務,如果沒有就通過yum install安裝;
[root@localhost ~]# rpm -qa | grep dhcp
dhcp-4.3.6-37.ky10.x86_64
(2)修改dhcp配置文件dhcpd.conf;
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
#dhcpd.conf
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#ddns-update-style interim;
ddns-update-style none;
ignore client-updates;
option space PXE;
allow booting;
allow bootp;
class "pxeclients"{
match if substring(option vendor-class-identifier,0,9) = "PXEClient";
next-server 192.168.1.1; #此處為TFTP Server端的IP地址
filename "uefi/grubx64.efi"; #告訴TFTP目錄下的bootstarp文件
}
subnet 192.168.1.0 netmask 255.255.255.0{ ## 定義子網
range 192.168.1.2 192.168.1.200;#配置DHCP分配地址區間(地址池)
option broadcast-address 192.168.1.255;#此處為DHCP服務的廣播地址
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
}
2、配置tftp服務
(1)檢查系統是否有tftp服務,如果沒有通過yum install安裝
[root@localhost ~]# rpm -qa | grep tftp
tftp-server-5.2-27.ky10.x86_64
syslinux-tftpboot-6.04-5.ky10.noarch
(2)修改tftp配置文件,將其狀態改為啟用狀態
[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 -c #tftp服務根目錄
disable = no #no表明tftp處於啟用狀態
per_source = 11
cps = 100 2
flags = IPv4
}#默認disable狀態為yes,需要改為no
(3)將x86鏡像文件中casper/的initrd.lz和vmliuz拷貝到tftpboot/casper
[root@localhost tftpboot]# cd casper/
[root@localhost casper]# ls
initrd.lz vmlinuz
[root@localhost casper]#
(4)在tftpboot目錄下創建uefi文件夾,並創建grub.cfg文件;
[root@localhost tftpboot]# mkdir uefi
[root@localhost tftpboot]# cd uefi/
[root@localhost pxelinux.cfg]# vim grub.cfg # 修改linux內核引導文件
set default="0"
function load_video {
if [ x\$feature_all_video_module=xy];then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
#insmod all_video
fi
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set timeout=60
### END /etc/grub.d/00_header ###
#search --no-floppy --set=root -l 'Kylin-Server-10(x86_64)'
### BEGIN /etc/grub.d/10_linux ###
menuentry '1)Install Kylin Desktop V10.1 1106 X86' --class red --class gnu-linux --class gnu --class os {
linux casper/vmlinuz boot=casper automatic-ubiquity only-ubiquity locale=zh_CN quiet splash audit=0 netboot=nfs nfsroot=192.168.1.1:/opt/nfs/x86_64-kylin/v10.1 file=/cdrom/preseed/preseed.cfg ip=dhcp security=
initrd casper/initrd.lz
}
#file中的cdrom指的是放置需要安裝系統的鏡像文件,例如/opt/nfs/x86_64-kylin/v10.1
(5)將x86的引導文件efi拷貝到uefi文件夾下
[root@localhost uefi]# ls
grub.cfg grubx64.efi
(6)使用 syslinux 提供的bootstart(系統文件為pxelinux.0);
[root@localhost ~]# yum install syslinux #會在系統中生成pxelinux.0,該文件是legacy方式的引導文件
[root@localhost ~]# cd /usr/share/syslinux/ #pxelinux.0文件存儲目錄
[root@localhost syslinux]# cp pxelinux.0 /var/lib/tftpboot/ #復制到tftp根目錄下
[root@localhost syslinux]# cp ldlinux.c32 /var/lib/tftpboot/ #測試提示必須要有
(7)將tftpboot目錄下的所有文件、目錄添加777權限
3、配置nfs服務
(1)檢查系統是否有nfs服務,如果沒有通過yum install安裝
[root@localhost ~]# rpm -qa | grep nfs
texlive-psnfss-svn33946.9.2a-22.ky10.noarch
nfs-utils-help-2.4.2-2.ky10.x86_64
nfs-utils-2.4.2-2.ky10.x86_64
nfs4-acl-tools-help-0.3.4-5.ky10.x86_64
nfs4-acl-tools-0.3.4-5.ky10.x86_64
[root@localhost ~]#
(2)修改nfs配置文件
[root@localhost /]# vim /etc/exports
#/var/www/html/kylin-V10SP1 192.168.1.1/255.255.255.0(rw,sync)
/opt/nfs *(insecure,rw,async,no_root_squash,no_subtree_check)
(3)在/opt/nfs/創建相關iso文件目錄
[root@localhost ~]# cd /opt/nfs
[root@localhost nfs]# ll
總用量 0
drwxrwxrwx 6 root root 163 12月 11 09:50 aarch64-kylin
drwxrwxrwx 2 root root 6 12月 11 09:46 mips64-kylin
drwxrwxrwx 9 root root 279 11月 28 18:45 x86_64-kylin
[root@localhost nfs]#
注:所有的目錄及文件都要添加777權限
(4)將整個iso掛載后的內容對應拷貝到上述目錄中。
注:隱藏文件和隱藏目錄也需要拷貝。可以使用如下命令
[root@localhost /] cp -ar .* /opt/nfs/x86_64-kylin/
注:nfs下面所有文件及文件夾的權限都為777
三、編寫自動安裝系統腳本
1、將自動化安裝系統腳本preseed.cfg添加到nfs相關系統鏡像文件下(需要創建一個文件夾,名為preseed)preseed.cfg負責引導自動化安裝
[root@localhost preseed]# pwd
/opt/nfs/x86_64-kylin/v10.1/preseed
[root@localhost preseed]# vim preseed.cfg
d-i debian-installer/locale string zh_CN.UTF-8
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string cn
d-i keyboard-configuration/layoutcode string cn
d-i time/zone string Asia/Shanghai
d-i preseed/early_command string sed "s/\/tmp\/kylin-data.ini/\/etc\/kylin-data.ini/g" -i /root/lib/partman/lib/recipes.sh; echo -e "[lixiang]\ndata = 1\nbackup = 1" > /root/etc/kylin-data.ini;
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i passwd/user-fullname string kylin
d-i passwd/username string kylin
d-i passwd/user-password password k123123
d-i passwd/user-password-again password k123123
ubiquity ubiquity/summary note
ubiquity ubiquity/reboot boolean true
ubiquity ubiquity/success_command string \
mount --bind /cdrom /target/mnt; \
cp -r /cdrom/desktop_tool_v10.1 /target/home/kylin/desktop_tool_v10.1; \
cp /cdrom/post-install.sh /target/home/kylin/post-install.sh; \
chroot echo 'L' | /target /bin/bash /home/kylin/desktop_tool_v10.1/TestSuite.sh -e; \
chroot /target /bin/bash /home/kylin/post-install.sh
2、自動化腳本測試
將自動化腳本放置在/opt/nfs/x86_64-kylin/v10.1/目錄下,並在preseed.cfg中聲明相關內容,如上述腳本所示,即可完整開機自動化腳本運行測試功能。
四、啟動相關服務
systemctl start tftp
systemctl start dhcpd.service
systemctl start nfs.service
systemctl start nfs-server.service
systemctl start nfs-utils.service
systemctl stop firewalld.service