kickstart

PXE(Pre-Execution Environment) + kickstart + NFS + TFTP + DHCP 安装 CentOS。

安装 tftp,dhcp:

# yum install tftp-server xinetd dhcp

开启 tftp 服务:

# sed '/disable/s/no/yes/g' /etc/xinetd.d/tftp

修改 exports 文件:

# cat >> /etc/exports << EOF
/opt/centos *(rw,sync)

修改 dhcpd.conf 文件,这里是以指定的方式来给特定 mac 机器分配 ip:

# cat /etc/dhcpd.conf

# 支持的 dns 的动态更新方式
ddns-update-style interim;
# 忽略客户端 dns 动态更新
ignore client-updates;
# 支持  pxe
allow booting;
# 对 bootp 请求进行应答
allow bootp;

subnet 10.18.101.0 netmask 255.255.255.0 {

  option routers 10.18.101.254;
  option subnet-mask 255.255.255.0;
  option domain-name-servers 8.8.4.4;
  option time-offset -18000;
  range 10.18.101.234 10.18.101.240;
  default-lease-time 21600;
  max-lease-time 43200;
  # tftp 服务器的 ip
  next-server 10.18.101.23;
  #filename "pxelinux.0";   

}

host h1 {
  hardware ethernet 33:33:33:33:33:33;
  fixed-address 10.18.101.235;
  option host-name "xen-pex1";
  filename "pxelinux.0";
}

host h2 {
  hardware ethernet 44:44:44:44:44:44;
  fixed-address 10.18.101.236;
  option host-name "xen-pxe2";
  filename "pxelinux.0";
}

挂载镜像:

# mount -o loop CentOS-5.5-x86_64.iso /mnt

将 bootstrap 从 /usr/lib/syslinux/pxelinux.0 复制到 /tftpboot/ 中;内核文件 vmlinuz 以及根文件系统 initrd.img 从 /mnt/images/pxeboot/{vmlinuz,initrd.img} 复制到 /tftpboot/ 中:

# cp /mnt/images/pxeboot/initrd.img /tftp
# cp /mnt/images/pxeboot/vmlinuz /tftp
# cp /usr/lib/syslinux/pxelinux.0 /tftp

在 /tftp/ 中建立 pxelinux.cfg 目录,将镜像中的 isolinux.cfg 复制进去,并修改:

# mkdir /tftp/pxelinux.cfg && cp /mnt/isolinux/isolinux.cfg /tftp/default
# vi /tftp/pxelinux.cfg/default

default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F7 rescue.msg
label linux
kernel vmlinuz
append ks=nfs:10.18.101.23:/opt/centos/ks.cfg ksdevice=eth0 initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append –

# tree /tftpboot/
/tftpboot/
|– initrd.img
|– pxelinux.0
|– pxelinux.cfg
|   `– default
`– vmlinuz

将解压的文件复制到 /opt/centos 目录中:

# rsync –av /mnt/ /opt/centos && cd /opt/centos
# createrepo  .

编写 ks.cfg 文件。可以使用 system-config-kickstart 这个图形界面来配置 kickstart 文件,如下,能基本满足要求,但是如果需要细化各种包的配置就需要
参见下c面这个链接,下面是我的一个配置:

# cat /opt/centos/ks.cfg

#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth  –useshadow  –enablemd5
# System bootloader configuration
bootloader –location=mbr
# Partition clearing information
clearpart –all –initlabel
# Use text mode install
text
# Firewall configuration
firewall –enabled –ssh  –trust=eth0
# 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=10.18.101.23 –dir=/opt/centos
# Network information
network –bootproto=dhcp –device=eth0 –onboot=on
# Reboot after installation
reboot
# Root password
rootpw –iscrypted $1$rLEB44dX$BDYNeOvaEd09i4HkQ8A1R1
# SELinux configuration
selinux –disabled
# Do not configure the X Window System
skipx
# System timezone
timezone –isUtc Asia/Shanghai
# Install OS instead of upgrade
install
# Disk partitioning information
part /boot –bytes-per-inode=4096 –fstype="ext3" –size=100
part swap –bytes-per-inode=4096 –fstype="swap" –size=1000
part / –bytes-per-inode=4096 –fstype="ext3" –size=5000

%packages –resolvedeps
@base
@editors
@chinese-support

%post
#!/bin/sh

# 关闭 ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
sed -i 's/NETWORKING_IPV6.*$/NETWORKING_IPV6=no/' /etc/sysconfig/network

# 简单的操作配置
echo "alias vi='vim'" >> /etc/bashrc
echo "alias ll='ls -lF –color=auto'" >> /etc/bashrc
echo "alias l='ls -F –color=auto'" >> /etc/bashrc
echo "alias r='reset'" >> /etc/bashrc

# 换源
wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS5-Base-163.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bk
mv /etc/yum.repos.d/CentOS5-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
yum makecache

这里是 kickstart 选项的详解。

重启各项服务,dhcp fail 的最大原因可能是少写了“;”号:

# /etc/init.d/dhcpd restart
# /etc/init.d/portmap restart
# /etc/init.d/nfs restart
# /etc/init.d/xinetd restart

客户机从网络启动。