pxe无人值守自动安装
CentOS6.5下PXE+Kickstart无人值守安装操作系统 1、 PXE 简介
PXE(Pre-boot Execution Environment,预启动执行环境) 是由Intel 公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP 地址,再用TFTP (trivial file transfer protocol )或MTFTP(multicast trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。
严格来说,PXE 并不是一种安装方式,而是一种引导方式。进行 PXE 安装的必要条件是在要安装的计算机中必须包含一个 PXE 支持的网卡(NIC ),即网卡中必须要有 PXE Client。PXE 协议可以使计算机通过网络启动。此协议分为 Client 端和 Server 端,而PXE Client 则在网卡的 ROM 中。当计算机引导时,BIOS 把 PXE Client 调入内存中执行,然后由 PXE Client 将放置在远端的文件通过网络下载到本地运行。运行 PXE 协议需要设置 DHCP 服务器和 TFTP 服务器。DHCP 服务器会给 PXE Client(将要安装系统的主机)分配一个 IP 地址,由于是给 PXE Client 分配 IP 地址,所以在配置 DHCP 服务器时需要增加相应的 PXE 设置。此外,在 PXE Client 的 ROM 中,已经存在了 TFTP Client ,那么它就可以通过 TFTP 协议到 TFTP Server 上下载所需的文件了。
工作过程:
1. PXE Client 从自己的PXE 网卡启动,向本网络中的DHCP 服务器索取IP ;
2. DHCP 服务器返回分配给客户机的IP 以及PXE 文件的放置位置(该文件一般是放在一台TFTP 服务器上) ;
3. PXE Client 向本网络中的TFTP 服务器索取pxelinux.0 文件; 4. PXE Client 取得pxelinux.0 文件后之执行该文件;
5. 根据pxelinux.0 的执行结果,通过TFTP 服务器加载内核和文件系统; 6.
进入安装画面, 此时可以通过选择HTTP 、FTP 、NFS 方式之一进行安装;
2、 Kickstart 简介
Kickstart 是一种无人值守的安装方式。它的工作原理是在安装过程中记录典型的需要人工干预填写的各种参数,并生成一个名为ks.cfg 的文件。如果在安装过程中(不只局限于生成Kickstart 安装文件的机器)出现要填写参数的情况,安装程序首先会去查找Kickstart 生成的文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便需要安装者手工干预了。所以,如果Kickstart 文件涵盖了安装过程中可能出现的所有需要填写的参数,
那么安装者完全可以只告诉安装程序从何处取ks.cfg 文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg 中的设置重启系统,并结束安装。
环境:
DHCP / TFTP IP:192.168.1.10 HTTP / FTP / NFS IP:192.168.1.10
具体实现步骤:
生成ks.cfg 文件需要system-config-kickstart 工具,而此工具依赖于X Windows,所以我们需要安装X Windows 和Desktop 并重启系统,操作如下:
[root@muban ~]# yum groupinstall "X Window System" [root@muban ~]# yum groupinstall Desktop
[root@muban ~]#startx或者 init 5 (从命令行换为桌面模式)
注:我在实验的时候,给一个最初没有装桌面的系统采用这种方式,结果转换以后,使物理磁盘满载,导致死机,最后还是使用了一台最初装好桌面的虚拟机做的实验
实验前关闭防火墙以及selinux 安全增强工具 [root@muban ~]# service iptables stop [root@muban ~]# setenforce 0 [root@muban ~]# getenforce Permissive
安装Http 工具,可选择方式有HTTP 、VSTFPD 、NFS 等方式,这里选择Http 方式
[root@muban ~]# yum install -y httpd [root@muban ~]# rpm -qa|grep httpd httpd-2.2.15-53.el6.centos.x86_64
[root@muban ~]# /etc/init.d/httpd start
[root@muban ~]# chkconfig httpd on设置开机启动
[root@muban html]# mount /dev/cdrom /var/www/html/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only
新建cdrom 文件夹,并将镜像挂载到这个文件夹下,无需复制,浪费时间
安装tftp-server
[root@muban /]# yum install tftp-server –
y [root@muban /]# vi /etc/xinetd.d/tftp
因为tftp 服务是挂载在超级进程xinetd 下的,所以通过启动xinetd 来启动tftp 服务。 [root@muban /]# /etc/init.d/xinetd restart Stopping xinetd: [ OK ]
Starting xinetd: [ OK ] [root@muban /]# chkconfig xinetd on设置为开机启动项
安装syslinux ,我的虚拟机中没有,需要安装
syslinux 是一个功能强大的引导加载程序,而且兼容各种介质。更加确切地说:SYSLINUX 是一个小型的Linux 操作系统,它的目的是简化首次安装Linux 的时间,并建立修护或其它特殊用途的启动盘。
[root@muban tftpboot]# yum install syslinux –y
[root@muban ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/首先加载的文件pxelinux.0
复制iso 镜像中的/images/pxeboot/initrd.img和vmlinuz 至/var/lib/tftpboot/文件夹中
[root@mubanhtml]# cp /var/www/html/cdrom/images/pxeboot/{initrd.img,vmlinuz}
/var/lib/tftpboot/第三加载镜像启动项
复制iso 镜像中的/isolinux/*.msg 至/var/lib/tftpboot/ 文件夹中
[root@muban html]# cp /var/www/html/cdrom/isolinux/*.msg /var/lib/tftpboot
将iso 镜像中的/isolinux 目录中的isolinux.cfg 复制到pxelinux.cfg 目录中,同时更改文件名称为default
[root@muban html]# mkdir /var/lib/tftpboot/pxelinux.cfg [root@muban html]# cp /var/www/html/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default第二加载的配置文件,很重要
[root@localhost ~]# vi /var/lib/tftpboot/pxelinux.cfg/default
default ks默认最开始加载模块的名称,可以修改 prompt 1 timeout 6
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.5! menu color border 0 #ffffffff #00000000 menu color sel 7 #ffffffff #ff000000 menu color title 0 #ffffffff #00000000 menu color tabmsg 0 #ffffffff #00000000 menu color unsel 0 #ffffffff #00000000 menu color hotsel 0 #ff000000 #ffffffff menu color hotkey 7 #ffffffff #ff000000 menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system menu default kernel vmlinuz
append initrd=initrd.img label vesa
menu label Install system with ^basic video driver kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset label ks
kernel vmlinuz
append ks=http://192.168.1.10/ks.cfg initrd=initrd.img自己新增加人的模块,最开始启动它,加载initrd.img 及读取所在的目录ks.cfg label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue label local
menu label Boot from ^local drive localboot 0xfff label memtest86
menu label ^Memory test kernel memtest append –
wq !保存退出,这里是强制的,因为这个文件是只读的
安装DHCP 服务:
[root@localhost ~]# yum -y install dhcp
[root@localhost ~]# cp -f /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@localhost ~]# vi /etc/dhcp/dhcpd.conf # dhcpd.conf
# Sample configuration file for ISC dhcpd
# option definitions common to all supported networks... option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600; max-lease-time 7200;
ddns-update-style interim; ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1; option subnet-mask 255.255.255.0; option domain-name-servers 192.168.1.1;
range dynamic-bootp 192.168.1.21 192.168.1.11; default-lease-time 600; max-lease-time 7200;
filename "pxelinux.0";下载tftp 上的这个启动文件 next-server 192.168.1.10; }
[root@localhost ~]# /etc/init.d/dhcpd start启动dhcp 服务
Starting dhcpd: [ OK ]
安装kickstart 软件
[root@localhost ~]# yum install system-config-kickstart 配置Kickstart
# system-config-kickstart
修改ks.cfg 文件
[root@localhost ~]# vi /var/www/html/ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL
unsupported_hardware(optional) centos6.4以后有的参数,我安装时最开始就显示”不支持硬件检验”导致无法自动下去,只能手动点击,加入此参数后完美解决 # Firewall configuration firewall --disabled
# Install OS instead of upgrade install
# Use network installation
url --url="http://192.168.1.10/cdrom/"这是系统镜像的位置 # Root password
rootpw --iscrypted $1$YJXvUWRR$yhmHMlLwzjt.O7oyiK8hI/ # System authorization information
auth --useshadow --passalgo=sha512 # Use graphical install graphical
firstboot --disable # System keyboard keyboard us
# System language lang en_US
# SELinux configuration selinux --disabled
# Installation logging level logging --level=info
# Reboot after installation Reboot 必须要重启 # System timezone
timezone Asia/Shanghai # Network information
network --bootproto=dhcp --device=eth0 --onboot=on # System bootloader configuration
key –skip redhat 有序列号要求,需要此参数,对于centos 无用,可忽略 bootloader --location=mbr # Clear the Master Boot Record zerombr
# Partition clearing information
clearpart --all --initlabel 此条命令必须添加,不然系统会让用户手动选择是否清除所有数据,这就需要人为干预了,从而导致自动化过程失败 # Disk partitioning information
part /boot --fstype="ext4" --size=150 part swap --fstype="swap" --size=1024
part /home --fstype="ext4" --size=2048 part / --fstype="ext4" --size=15360
%packages @base
@basic-desktop @compat-libraries @console-internet @internet-browser @system-management
%end
[root@localhost html]# service xinetd status xinetd (pid 3897) is running...
[root@localhost html]# service dhcpd status dhcpd (pid 6648) is running...
[root@localhost html]# service httpd status
httpd (pid 3822) is running...再次确认所有所需要的服务都运行了
[root@localhost html]# chmod 777 ks.cfg记得给这个文件执行权限,默认是没有执行权限的
客户端配置和平时基本一致,只有一处有些出入,如下
保证磁盘大小和你在kickstart 中分配的大小相符,通俗就是不能小于你分配的容量,另外一定要选立即分配所有磁盘空间这项,我网络连接用的是桥接方式,也可以用nat 方式,只要能连通即可,最后安装成功了,从最开始杂乱无章,到最后梳理安装好,花了挺长时间,多
谢前辈们的文章,对我的帮助极大!!!