[Linux] Kickstart (unattended installation)

The traditional way to install the operating system: installation CD, U disk installation, network installation.

kickstart an unattended installation, it works in advance a good definition of the configuration file linux installation process, the configuration file is usually ks.cfg.

With this file, you can let Linux be installed in accordance with the requirements of our automated pre-defined during the installation process, while for the deployment of a large number of hosts are also very convenient.

PXE (preboot execute environment, pre-boot execution environment) is the latest technology developed by Intel Corporation, working in network mode on Client / Server,

Mirror support downloading from a remote server via a network, and thus support via a network operating system boot, the boot process, the terminal requires the server to assign an IP address, then

TFTP (trivial file transfer protocol, Trivial File Transfer Protocol) protocol to download a package to start the machine's memory performed by this software package start end

(Client) basic software provided to guide the installation of the operating system.


PXE can boot multiple operating systems. Strictly speaking, PXE is not an installation, but a guide mode. PXE installation of the necessary conditions must contain a PXE support of the machine to be installed in the network card (NIC), that is, the card must have a PXE Client, PXE Client in NIC ROM. When the computer boots, the BIOS into memory the PXE Client performed by the PXE Client then placed at the distal end of the file is downloaded over the network to the local operation. PXE boot using DHCP server and needs to set the TFTP server. The DHCP server will PXE Client (host system will be installed) assigned an IP address, since the IP address is assigned to the PXE Client, so that when configuring the DHCP server need to add the appropriate PXE settings. In addition, in the ROM PXE Client, has been in existence TFTP Client, then you can go to the TFTP Server download the desired file by TFTP protocol.

PXE boot process:

1、PXE client端通过PXE BootROM(自启动芯片)(BIOS里面的PXE固件)广播一个DHCP discover包;

2、支持PXE的DHCP服务器返回分配给客户机的IP以及启动文件的放置位置;

3、PXE client会向本网络中的TFTP服务器索取pxelinux.0(引导文件)、pxelinux.cfg/default(启动菜单配置文件)、vmlinuz (可执行的linux内核)和initrd.img(驱动程序模块)文件;

5、PXE client由TFTP从服务端下载启动安装程序所必需的文件(pxelinux.0、pxelinux.cfg/default)后,会根据default文件中定义的引导顺序,加载内核和文件系统;

6、这些启动资源其实就是最小的操作系统,这个最小操作系统在装载了网络驱动和TCP/IP协议栈之后,就可以通过HTTP、FTP、NFS方式进行安装;

[root@server ~]# yum install dhcp xinetd tftp-server vsftpd syslinux system-config-kickstart -y

dhcp:动态主机配置协议,为客户端分配IP地址。

xinetd:可监视一些网络请求的守护进程,其根据网络请求来调用相应的服务进程来处理连接请求。例如FTP、Telnet、SSH等就适合使用xinetd模式。

tftp-server:简单文件传输协议,用于向客户端提供安装引导相关的文件。udp的69号端口

vsftpd:为客户端提供系统安装时所需的文件。

syslinux:产生pxelinux.0文件。

system-config-kickstart:用于生成kickstart配置文件。

1、配置DHCP服务

#修改dhcp服务配置文件

[root@server ~]# vim /etc/dhcp/dhcpd.conf

ddns-update-style interim;

ignore client-updates;

filename "pxelinux.0";              指定引导文件

next-server 172.24.8.131;        指定引导文件服务器

subnet 172.24.8.0 netmask 255.255.255.0 {

        option routers 172.24.8.1;

        option subnet-mask 255.255.255.0;

        option domain-name-servers 114.114.114.114;

        range dynamic-bootp 172.24.8.100 172.24.8.254;

        default-lease-time 60;

        max-lease-time 60;

}

[root@server ~]# systemctl restart dhcpd

2、配置TFTP服务

[root@server ~]# vim /etc/xinetd.d/tftp

修改下面两条内容       

server_args             = -s /tftpboot                    //指定目录,该目录可自定义

disable                 = no                                    //开启服务开关

[root@server ~]# systemctl restart tftp

#在7.0系统中如果服务无法启动,使用以下命令进行启动

[root@server ~]#systemctl start tftp.socket

启动xinetd服务:

[root@server ~]# systemctl restart xinetd

3、准备引导相关的文件

#创建网络引导配置文件目录

[root@server ~]#mkdir -p /tftpboot/pxelinux.cfg

#复制引导文件

[root@server ~]#cp /usr/share/syslinux/pxelinux.0 /tftpboot/

#复制系统映像

[root@server ~]#cp /mnt/images/pxeboot/initrd.img /tftpboot/

#复制系统内核

[root@server ~]# cp /mnt/images/pxeboot/vmlinuz /tftpboot/

#复制引导配置文件

[root@server ~]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default

复制加载图形模块的文件

[root@localhost pxelinux.cfg]# cp /mnt/isolinux/vesamenu.c32  /tftpboot

 可以自定义一张图片背景,将其放在/tftpboot目录下

#变更配置文件权限

[root@server ~]# chmod 644 /tftpboot/pxelinux.cfg/default

#修改配置文件

[root@server ~]# vim /tftpboot/pxelinux.cfg/default

1         default linux                修改默认启动模式

64  append initrd=initrd.img ks=ftp://192.168.9.131/ks.cfg      修改加载的KS应答文件

 4、准备安装镜像

#启动FTP服务

[root@server ~]# systemctl start vsftpd

#查看FTP服务状态

[root@server ~]#systemctl status vsftpd

#挂载系统镜像到共享目录

[root@server ~]#mount /dev/sr0 /var/ftp/pub/

#可通过windows系统的浏览器才确认服务访问情况

5、创建ks应答文件

[root@localhost Desktop]# system-config-kickstart

可进入图形界面选择安装设置:镜像文件通过ftp服务共享,则安装方法按照下图填写:

最后将生成的ks.cfg文件保存至/var/ftp/

注意:这里需要停掉 VMware网络适配器的DHCP服务,让虚拟机使用我们配置的DHCP服务器。

最后创建一台虚拟机,就会自动引导安装程序。


拓展:

使用其他服务提供镜像文件:

(1)http

[root@server ~]# yum install httpd -y

#复制系统安装文件到/var/www/html目录下

[root@server ~]# cp -r /mnt/* /var/www/html/rhel

#将KS文件放到/var/www/html目录下

[root@server ~]# ll /var/www/html/ks.cfg

#启动HTTPD服务

[root@server ~]# systemctl start httpd

#修改配置文件

[root@server ~]# vim /tftpboot/pxelinux.cfg/default

1         default linux                修改默认启动模式

64  append initrd=initrd.img ks=http://172.24.8.131/ks.cfg      修改加载的KS应答文件

可以重新创建ks应答文件,也可以直接修改之前的ks应答文件中的系统安装资源目录

[root@server ~]# vim  /var/www/html/ks.cfg

# Use network installation

url --url="http://172.24.8.131/rhel"

(2)NFS

[root@server ~]#vim /etc/exports

/var/www/html        *(ro)

#启动NFS服务

[root@server ~]# systemctl restart nfs

#可通过其他linux主机进行远程挂载共享目录来测试服务启动情况

#注意:需要修改default文件的ks文件路径

[root@mail ~] vi /tftpboot/pxelinux.cfg/default

64   append initrd=initrd.img ks=nfs:172.24.8.131:/var/www/html/ks.cfg

#注意:需要修改KS应答文件中的系统安装资源目录

[root@mail ~]# vi /var/www/html/ks.cfg

# Use network installation

nfs --server=172.24.8.131 --dir=/var/www/html/rhel

发布了43 篇原创文章 · 获赞 50 · 访问量 7947

Guess you like

Origin blog.csdn.net/weixin_43997530/article/details/103786786