第一阶段 实现无人值守安装
思路:
作为提供安装的服务器(注意它的iptables和selinux)
1、生成ks.cfg(无人值守配置文件),并通过NFS/HTTP/FTP/Harddisk共享

2、配置DHCP服务器(客户端只有有与共享ks.cfg配置文件的服务器在同一网段的IP才可行)


作为需要安装系统的客户端
1、光盘启动
2、在boot: linux ks=/path/ks.cfg


具体实现:
作为提供安装的服务器
1、生成ks.cfg(无人值守配置文件),并通过NFS/HTTP/FTP/Harddisk共享
无人值守配置文件的生成方法有两种:
a.system-config-kickstart命令生成( 注意key --skip
[root@localhost ~]# yum -y install system-config-kickstart
[root@localhost ~]# system-config-kickstart
注意ks.cfg文件的权限
[root@localhost ftp]# ls -l /var/ftp/ks.cfg
-rw-r--r-- 1 root root 1292 03-31 11:15 /var/ftp/ks.cfg
b.拷系统自身的一个ks文件,稍做修改
系统自身的一个ks文件:/root/anaconda-ks.cfg

通过NFS共享ks.cfg文件
[root@localhost ftp]# ls /var/ftp/ks.cfg
/var/ftp/ks.cfg
[root@localhost ftp]# vim /etc/exports
[root@localhost ftp]# cat /etc/exports
/var/ftp *(rw)


2、配置DHCP服务器(客户端只有有与共享ks.cfg配置文件的服务器在同一网段的IP才可行)
[root@localhost ftp]# yum -y install dhcp
[root@localhost ftp]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖“/etc/dhcpd.conf”? y
修改/etc/dhcpd.conf的配置文件,定义租用IP的地址段和地址池范围
[root@localhost ftp]# service dhcpd start
启动 dhcpd: [确定]

3、配置NFS服务器,共享安装树文件 /rhel5u5
[root@localhost ftp]# cat /etc/exports
/var/ftp *(rw)
/rhel5u5 *(rw)
[root@localhost ftp]# service portmap restart
停止 portmap: [确定]
启动 portmap: [确定]
[root@localhost ftp]#
service nfs restart


作为需要安装系统的客户端
1、光盘启动
2、在boot: linux ks=/path/ks.cfg
boot: linux ks=nfs:192.168.1.254:/var/ftp/ks.cfg


ks.cfg文件
[root@localhost ftp]# cat ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
# System authorization information
key --skip
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# 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.1.254 --dir=/rhel5u5
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$23JmK7TQ$mPN5A.BrLCoDGHIktT0r80

# SELinux configuration
selinux --enforcing
# System timezone
timezone Asia/Shanghai
# Install OS instead of upgrade
install
# X Window System configuration information
xconfig --defaultdesktop=GNOME --depth=32 --resolution=1024x768
# Disk partitioning information
part / --bytes-per-inode=4096 --fstype="ext3" --size=6000
part /boot --bytes-per-inode=4096 --fstype="ext3" --size=100
part swap --bytes-per-inode=4096 --fstype="swap" --size=1500

%packages
@base-x
@gnome-desktop
@chinese-support
@admin-tools
@system-tools
dhcpd.conf
[root@localhost ftp]# cat /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;

subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
option routers 192.168.1.254;
option subnet-mask 255.255.255.0;

option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.254;

option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- 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.1.128 192.168.1.254;
default-lease-time 21600;
max-lease-time 43200;

# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
第二阶段 实现网络引导
思路:
1、需要安装系统的客户端主机必须要支持网络启动
网卡支持intel PXE规范
2、当网络启动后
需要有IP 地址----DHCP服务器分配
需要去找网络上一个共享了bootstrap程序(pxelinux.0)的主机,一般是通过一个TFTP服务来共享 ----DHCP服务器可以在配置文件中定义下一个服务器是谁,DHCP服务器中也定义了找到下一个服务器以后,加载它共享的哪一个文件 (bootstrap).

3、将加载bootstrap(相当于grub的stage2功能)运行,继续再加载自己的配置文件(相当于grub.conf),此配置文件中将定义加载从光盘中拷出的vmlinuz和initrd.img文件。
同时,为了让后续的安装过程实现无人值守,我们需要在配置文件中定义如何找到ks.cfg文件(此文件在上一阶段已经OK)


需要在第一了段基本上额外配置dhcp的相关字段,TFTP服务器,TFTP服务器要共享 bootstrap程序文件,bootstrap配置文件和vmlinuz/initrd.img

具体细节实现:
1、修改dhcp配置文件:
vim /etc/dhcpd.conf
在subnet声明中加如下语句:
subnet 192.168.1.0 netmask 255.255.255.0 {

# --- default gateway
next-server 192.168.1.254; 此IP是TFTP服务器的IP
filename "/pxelinux.0"; 此文件是TFTP服务器共享的文件

2、配置TFTP,共享相关文件
[root@localhost isolinux]# yum -y install tftp-server

[root@localhost isolinux]# cd /tftpboot/
此目录 就是tftp服务器的共享根目录


a.拷bootstrap文件(系统自带)到tftp的共享根目录下
]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/
b.创建放bootstrap配置文件的目录
[root@localhost syslinux]# mkdir /tftpboot/pxelinux.cfg
c.拷bootstrap配置文件的模板(光盘中的isolinux目录下自带)
[root@localhost syslinux]# cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
d.拷vmlinuz,initrd.img到tftp共享根目录下
]# cp /mnt/isolinux/vmlinuz /mnt/isolinux/initrd.img /tftpboot/

]# cp /mnt/isolinux/*.msg /tftpboot/pxelinux.cfg/

e.pxelinux.0的配置文件
[root@localhost syslinux]# cat /tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 30
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=nfs:192.168.1.254:/var/ftp/ks.cfg

3、注意,服务启动
[root@localhost syslinux]# chkconfig tftp on [root@localhost syslinux]# service xinetd restart[root@localhost syslinux]# netstat -tunlp | grep :69
udp 0 0 0.0.0.0:69 0.0.0.0:* 4896/xinetd

pxelinux.0的配置文件
pxelinux.0的配置文件
[root@localhost syslinux]# cat /tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 30
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=nfs:192.168.1.254:/var/ftp/ks.cfg