How to install CentOS7 with kickstart

准备工作

关闭防火墙

1
2
$ systemctl stop firewalld
$ systemctl disable firewalld

关闭SELinux

1
2
$ setenforce 0
$ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

配置Web服务

安装Nginx

1
2
3
$ wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ yum -y install nginx

配置CentOS镜像

1
2
3
$ wget http://mirrors.163.com/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso
$ mkdir -p /usr/share/nginx/html/centos
$ mount -t iso9660 CentOS-7-x86_64-Minimal-1611.iso /usr/share/nginx/html/centos

启动Nginx

1
2
$ systemctl start nginx
$ systemctl enable nginx

配置DHCP服务

安装DHCP服务

1
$ yum -y install dhcp

创建DHCP配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cat <<EOF > /etc/dhcp/dhcpd.conf
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 172.16.16.0 netmask 255.255.255.0 {
option routers 172.16.16.254
option subnet-mask 255.255.255.0;
option domain-name-servers 172.16.16.253;
option time-offset -18000;
range dynamic-bootp 172.16.16.101 172.16.16.200;
default-lease-time 21600;
max-lease-time 43200;
next-server 172.16.16.1;
filename "pxelinux.0";
}
EOF

启动DHCP服务

1
2
$ systemctl start dhcpd
$ systemctl enable dhcpd

配置TFTP服务

安装TFTP服务

1
$ yum -y install xinetd tftp-server tftp syslinux-tftpboot

创建TFTP配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cat <<EOF > /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
disable= no
per_source= 11
cps= 100 2
flags= IPv4
}
EOF

启动TFTP服务

1
2
$ systemctl start tftp
$ systemctl enable tftp

拷贝安装PXE启动文件

1
2
$ cp /usr/share/nginx/html/centos/images/pxeboot/vmlinuz /var/lib/tftpboot/vmlinuz
$ cp /usr/share/nginx/html/centos/images/pxeboot/initrd.img /var/lib/tftpboot/initrd.img

创建PXE引导记录

1
2
3
4
5
6
7
8
9
10
$ mkdir -p /var/lib/tftpboot/pxelinux.cfg
$ cat <<EOF > /var/lib/tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 180
display boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=http://172.16.16.1/ks.cfg
EOF

定制Kickstart

创建Kickstart文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
$ cat <<EOF > /usr/share/nginx/html/CentOS7-Minimal-KS.cfg
#platform=86, AMD64, or Intel EM64T
#version=DEVEL
# System authorization information
auth --useshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url="http://172.16.16.1/centos"
# Use text mode install
text
# Firewall configuration
firewall --disabled
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=''
# System language
lang en_US.UTF-8
# Installation logging level
logging --level=info
# Network information
network --bootproto=dhcp --device=eth0 --onboot=yes
network --hostname=localhost.localdomain
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$YK0iQhiP$PLjn4mFoOzFb7Asr4BdQj/
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --asprimary --fstype="swap" --size=32768
part /boot --asprimary --fstype="ext4" --size=200
part / --asprimary --fstype="ext4" --size=51200
part /opt --asprimary --fstype="ext4" --grow --size=1
%packages
@^minimal
@core
chrony
wget
net-tools
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
EOF

创建Kickstart文件软链接

1
$ ln -s /usr/share/nginx/html/CentOS7-Minimal-KS.cfg /usr/share/nginx/html/ks.cfg