目录

Pxe Kicstart for Centos

https://cdn.jsdelivr.net/gh/jiuchan/pic1.blog.mulinux.com/img/image-20201116151115835.png

环境准备

Linux-pxe服务器:192.168.216.20,Centos6.6_X64;网关和dns地址都为192.168.216.2。

tftp、dhcp、nfs服务器:192.168.216.20

虚拟机模拟环境:需提前将CentOS光盘加到光驱。

搭建tftp服务器

1
2
3
yum install -y  tftp tftp-server  xinetd
vi /etc/xinetd.d/tftp   // 其他默认,将disable = yes替换为disable = no
service xinetd start  

配置dhcpd服务

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
yum  install -y  dhcp
cp  /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.216.0 netmask 255.255.255.0 {
    allow booting;
    allow bootp;
    allow unknown-clients;
    option routers  192.168.216.2;
    option subnet-mask  255.255.255.0;
    option domain-name-servers  192.168.216.2;
    option time-offset  -18000; # Eastern Standard Time
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- you understand Netbios very well
#    option netbios-node-type 2;
    range dynamic-bootp 192.168.216.100 192.168.216.254;
    default-lease-time 21600;
    max-lease-time 43200;
    next-server  192.168.216.20;
    filename "pxelinux.0";
}

service dhcpd start

配置支持pxe

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
yum install -y syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot
mkdir  /install
mount /dev/cdrom1 /install #挂载时只读提示mount: block device /dev/sr0 is write-protected, mounting read-only,不影响。  
cp  /install/isolinux/{initrd.img,vmlinuz.img} /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
chmod 644 /var/lib/tftpboot/pxelinux.cfg/default

vim  /var/lib/tftpboot/pxelinux.cfg/default  // 内容为:
default linux
prompt 1
timeout 30
label linux
kernel vmlinuz
append initrd=initrd.img ks=nfs:192.168.216.20:/ks/ks.cfg

配置ks.cfg

 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
mkdir /ks 
vi /ks/ks.cfg
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  --useshadow  --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Use graphical install
graphical
# Firewall configuration
firewall --enabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Use NFS installation media
nfs --server=192.168.216.20 --dir=/install
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
#Root password
rootpw --iscrypted $1$BYSimLw0$I515yLiKzudlwkIskBqQE1
 
# SELinux configuration
selinux --disabled
# System timezone
timezone  Asia/Shanghai
# Install OS instead of upgrade
install
# X Window System configuration information
#xconfig  --defaultdesktop=GNOME --depth=32 --resolution=800x600
reboot
text
# Disk partitioning information
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
part swap --bytes-per-inode=4096 --fstype="swap" --size=256
part / --bytes-per-inode=4096 --fstype="ext3" --grow --size=1

%packages --ignoremissing

@editors
@graphics
@x-software-development
@development-libs
@development-tools
kernel-devel
e2fsprogs
kernel

配置NFS

1
2
3
4
5
6
7
yum install -y nfs-utils rpcbind
vim /etc/exports
/install  * (ro,no_root_squash,sync)
/ks *(ro,no_root_squash,sync)

启动NFS服务:
service nfs restart 

创建一个新的虚拟机

设置网络为nat模式,默认就是使用dhcp方式安装系统的。

https://cdn.jsdelivr.net/gh/jiuchan/pic1.blog.mulinux.com/img/image-20201116151216972.png

https://cdn.jsdelivr.net/gh/jiuchan/pic1.blog.mulinux.com/img/image-20201116151255541.png

安装成功:root密码是:123456