#!/bin/bash
## TsengYia 2012.07.09
## OS Version: Red Hat Enterprise Linux 5.4
PXE_SVR="192.168.157.128"
NETWORK="192.168.157"
######################################################
##
## 一、准备软件仓库
##
#### 1.从光盘中复制软件包
##
mkdir -p /var/ftp/rhel5
# cp -rf /misc/cd/* /var/ftp/rhel5/
# 或者
service autofs restart
ls /misc/cd &> /dev/null
mount --bind /misc/cd /var/ftp/rhel5
##
#### 2.启动FTP服务
##
service vsftpd restart
chkconfig vsftpd on
##
#### 3.确认软件仓库可用(在本机或客户机中测试)
##
echo "[Server]
name=RHEL 5.4 Server
baseurl=ftp://$PXE_SVR/rhel5/Server
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[VT]
name=RHEL 5.4 VT
baseurl=ftp://$PXE_SVR/rhel5/VT
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[Cluster]
name=RHEL 5.4 Cluster
baseurl=ftp://$PXE_SVR/rhel5/Cluster
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[ClusterStorage]
name=RHEL 5.4 ClusterStorage
baseurl=ftp://$PXE_SVR/rhel5/ClusterStorage
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" > /etc/yum.repos.d/rhel5.repo
##
##
## 二、配置TFTP服务,准备引导文件
##
#### 1.安装及配置tftp-server
##
yum -y install tftp-server
echo 'service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot/linux-install
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}' > /etc/xinetd.d/tftp
service xinetd restart
chkconfig xinetd on
##
#### 2.安装syslinux,准备引导文件
##
yum -y install syslinux
cd /var/ftp/rhel5/images/pxeboot/
/bin/cp -f vmlinuz initrd.img /tftpboot/linux-install/
##
##
## 三、配置DHCP服务
##
#### 1.安装dhcp软件包
##
yum -y install dhcp
##
#### 2.配置并启动dhcpd服务
##
#/bin/cp -f /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
echo 'ddns-update-style none;
ignore client-updates;
subnet '$NETWORK'.0 netmask 255.255.255.0 {
option routers '$NETWORK'.1;
option subnet-mask 255.255.255.0;
option domain-name "benet.com";
option domain-name-servers '$NETWORK'.1,202.106.0.20;
option time-offset -18000; # Eastern Standard Time
range '$NETWORK'.50 '$NETWORK'.100;
default-lease-time 21600;
max-lease-time 43200;
next-server '$PXE_SVR'; #//指定TFTP服务器地址
filename "pxelinux.0"; #//指定所使用的引导程序名称
}' > /etc/dhcpd.conf
service dhcpd restart
chkconfig dhcpd on
##
##
## 四、准备PXE安装菜单
##
echo 'default auto
prompt 1
label auto
kernel vmlinuz
append initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux text
kernel vmlinuz
append text initrd=initrd.img devfs=nomount ramdisk_size=8192
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img devfs=nomount ramdisk_size=8192' > /tftpboot/linux-install/pxelinux.cfg/default
##
## 五、为客户机安装系统(PXE方式)
#1.修改BIOS设置,优先从网卡(LAN或Network)启动
#2.重新启动客户机
#3.PXE安装过程
# 1)自动配置IP地址 -->
# 2)下载并运行引导程序pxelinux.0 -->
# 3)下载并运行vmlinuz、initrd.img -->
# 4)获取并显示安装菜单
# 5)选择安装方式,并进入系统安装向导
# 6)…… 完成系统安装
##
####
######################################################
####
阅读(1712) | 评论(0) | 转发(0) |