搭建PXE服务及实现安装银河麒麟桌面操作系统

搭建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

你可能感兴趣的:(linux,ubuntu,pxe)