Home > Article > Operation and Maintenance > Linux system network installation method based on pxe+dhcp+nfs+tftp+kickstart
Original text published on: 2010-09-05
Reprinted to cu on: 2012-07-21
PXE (preboot execute environment) works in the network mode of Client/Server, supporting the workstation through The network downloads the image from the remote server and thus supports the booting of the operating system from the network. During the startup process, the terminal is assigned an IP address by the DHCP server, and then uses TFTP(trivial file transfer protocol) and other protocols download exist on the server (NFS, FTP, HTTP, etc. )LiunxThe kernel and root file system wait until they are in the local memory and executed, thus completing the basic software settings of the terminal and booting the pre-installed software in the server Terminal operating system.
Kickstart is an unattended installation method. It records various parameters that are filled in by manual intervention during a typical installation process, and generates a ks.cfg file; in subsequent installation processes, the requirement to fill in the parameters appears. , the installation program will search for the kickstart file, and no manual intervention is required if the appropriate parameters can be found.
os:
## CentOS 5.4 i386
soft:
## dhcp, nfs, tftp, kickstart (gnomeor x-window)
can be installed usingyum:
yum –y install dhcp* yum –y install nfs* yum –y install tftp* yum –y install system-config-kickstart*
ip:## eth0 : 192.168.1.254
3. Introduction to the installation and configuration process
1. ConfigurationDHCP ##more /etc/dhcpd.conf
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
# Location: Zhangjiang IDC
# Date: 2010-08-01
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.254;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.1.254;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.1.10 192.168.1.250;
default-lease-time 21600;
max-lease-time 43200;
# Group the PXE bootable hosts
# PXE-server configuration direction
next-server 192.168.1.254; #指向nfs服务器
filename "/pxelinux.0"; #/tftp根目录下的启动引导文件
# we want the nameserver to appear at a fixed address
host ns {
hardware ethernet 00:1C:25:80:F4:58; #张江机房的笔记本网卡mac
fixed-address 192.168.1.2;
}
}
Service:
/etc/init.d/dhcpd restart2.
ConfigurationTFTP more /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /tftpboot #-s指定tftp根目录
disable = no #默认yes,关闭
per_source = 11
cps = 100 2
flags = IPv4
}
Service:
/etc/init.d/xinetd.restartCheck if tftp
the service is started:
chkconfig –list | grep tftp
3.
ConfigurationNFS ##NFSNeed to ask
RPCRegistration can only be called by the client. Generally, portmap is installed by default for port mapping. If not, you can use yum Installation:yum –y install portmap*
可以直接使用挂载的镜像,这里是拷到服务器上为了建立一个专门存放常用的镜像文件建的目录。
mount /dev/cdrom /mnt mkdir /ios/CentOS_5.4 cp –a /mnt/* /ios/CentOS_5.4
#共享tftp的根目录,192.168.1.0/24网段的用户有只读权限 echo "/tftpboot 192.168.1.0/24(ro,sync)" > /etc/exports #共享存放镜像文件的目录,所有用户有只读权限 echo "/ios/CentOS_5.4 *(ro,sync)" >> /etc/exports
#不重启nfs服务器情况下配置生效 exportfs –arv #重启服务 /etc/init.d/portmap restart /etc/init.d/nfs resart
查看共享目录是否生效:
showmount –e localhost
4. 配置PXE启动需要的文件
cp /usr/lib/syslinux/pxelinux.0 /tftpboot
# pxelinux.0依赖于syslinux,没有安装使用yum:yum –y install syslinux*
# pxelinux.0是PXE启动引导文件
cp /ios/CentOS_5.4/ioslinux/vmlinuz /tftpboot cp /ios/CentOS_5.4/ioslinux/initrd.img /tftpboot
# vmlinuz和initrd.img是不同版本的系统内核和系统引导文件,安装不同版本系统时请使用各版本的vmlinuz和initrd.img
mkdir /tftpboot/pxelinux.cfg cp /ios/CentOS_5.4/ioslinux.cfg /tftpboot/pxelinux.cfg/default
到目前已经可以从网络安装系统了。测试如下:
启动服务器,一般F12进入PXE网络启动,向DHCP请求IP,DHCP响应包含IP地址和pxelinux启动程序位置;PXE客户端收到响应后,向服务器请求传送文件(pxelinux.0、pxelinux.cfg/default、vmlinuz、initrd.img);客户端通过pxelinux.cfg/default文件成功的引导Linux安装内核后,安装程序首先必须确定你通过什么安装介质来安装linux,如果是通过网络安装(NFS, FTP, HTTP),则会在这个时候初始化网络,并定位安装源位置。(由于PXE获取的是安装用的内核以及安装程序等,而安装程序要获取的是安装系统所需的二进制包以及配置文件,它们需要的内容不同造成PXE模块和安装程序是相对独立的,PXE的网络配置并不能传递给安装程序,从而进行两次获取IP地址过程)。
5. 配置ks.cfg文件
ks.cfg文件可以由以下方法生成:
1. 每次装好一台CentOS(RedHat),安装程序都会自动创建一个kickstart文件,文件记录了真实的安装配置,位置在/root/anaconda-ks.cfg,可以根据此配置来生成自己需要的ks.cfg文件;
2. 使用图形化的kickstart配置工具,命令:system-config-kickstart;
3. 使用文本编辑器编辑。
以下是已经写好的ks.cfg文件,仅供参考:
more /ios/ks.cfg # Kickstart file automatically generated by anaconda. install nfs --server=192.168.1.254 --dir=/ios/CentOS_5.4 #指出NFS的路径和安装文件的位置 lang en_US.UTF-8 keyboard us network --device eth0 --onboot yes --bootproto dhcp --hostname test #network --device eth0 --onboot yes –bootproto static --ip 192.168.1.10 --netmask 255.255.255.0 --gateway 192.168.1.1 --nameserver 8.8.8.8 --hostname test #一个网卡获得地址的方式 network --device eth1 --onboot no --bootproto dhcp --hostname test rootpw --iscrypted $1$V26J9f5V$A7k9alSJs1GzG.qNBef6f/ #加密root密码 firewall --disabled #--port=22:tcp authconfig --enableshadow --enablemd5 #使用md5认证 selinux --disabled timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work clearpart --linux part /boot --fstype ext3 --size=100 --ondisk=sda part swap --size=2048 --ondisk=sda part / --fstype ext3 --size=100 –grow --ondisk=sda #分区和选包是机房最头疼的事,在这里可以修改 #clearpart --linux --drives=sda #part /boot --fstype ext3 --size=200 #part pv.2 --size=0 --grow --ondisk=sda #volgroup VolGroup00 --pesize=32768 pv.2 #logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow #logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=1000 --grow --maxsize=6144 #以上是一个LVM分区的示范 reboot #安装完毕后重启 %packages @development-libs @development-tools @admin-tools @editors #选包
将配置好的ks.cfg文件放在共享目录内,这里放到/ios下
echo "/ios 192.168.1.0/24(ro,sync)" >> /etc/exports exportfs –arv
修改/tftpboot/pxelinux.cfg/default配置:
more /tftpboot/pxelinux.cfg/default default ks #默认从标签ks启动 prompt 1 #显示"boot:"提示符 timeout 30 #等待超时时间 display boot.msg #/tftpboot/boot.msg默认显示boot.msg,可以根据实际情况编辑, F1 boot.msg F2 options.msg F3 general.msg F4 param.msg F5 rescue.msg label linux #在boot:提示符后输入linux(只是一个标签),从下面指出的内核启动 kernel vmlinuz append initrd=initrd.img label text #在boot:提示符后输入text,这里是文字界面安装 kernel vmlinuz append initrd=initrd.img text label ks #default默认,从ks.cfg读取安装信息,无需人工干预 kernel vmlinuz append ks=nfs:192.168.1.254:/ios/ks.cfg initrd=initrd.img ksdevice=link #ksdevice=link,从连接的网卡读取安装文件 label local localboot 1 label mem kernel memtest append -
6. 进阶
由于机房目前常安装的系统是RHEL4.7, RHEL4.7 x86_64, CentOS5.4, CentOS5.4 x86_64。可以将四种镜像放在专门的目录内。例如:
RHEL4.7:/ios/rhel4.7
RHEL4.7 x86_64: /ios/rhel4.7-x86_64
CentOS5.4: /ios/centos5.4
CentOS5.4 x86_64: /ios/centos5.4- x86_64
/tftp根目录(这里是/tftpboot下,各版本的内核和引导文件也需要改变位置:
RHEL4.7:/ios/rhel4.7/vmlinuz
/ios/rhel4.7/initrd.img
RHEL4.7 x86_64: /ios/ rhel4.7-x86_64/vmlinuz
/ios/ rhel4.7-x86_64/initrd.img
CentOS5.4: /ios/centos5.4/vmlinuz
/ios/centos5.4/initrd.img
CentOS5.4 x86_64: /ios/centos5.4- x86_64/vmlinuz
/ios/centos5.4- x86_64/ initrd.img
PXE引导文件(这里是/tftpboot/pxelinux.cfg/default)修改:
default 3 prompt 1 timeout 300 display boot.msg F1 boot.msg F2 options.msg F3 general.msg F4 param.msg F5 rescue.msg label 1 kernel rhel4.7/vmlinuz append initrd=rhel4.7/initrd.img label 2 kernel rhel4.7-x86_64/vmlinuz append initrd=rhel4.7-x86_64/initrd.img label 3 kernel centos5.4/vmlinuz append initrd=centos5.4/initrd.img label 4 kernel centos5.4-x86_64/vmlinuz append initrd=centos5.4-x86_64/initrd.img label 1-ks_** kernel rhel4.7/vmlinuz append ks=nfs:192.168.1.254:/ios/rhel4.7ks_**.cfg initrd=rhel4.7/initrd.img ksdevice=link label 2-ks_** kernel rhel4.7-x86_64/vmlinuz append ks=nfs:192.168.1.254:/ios/rhel4.7-x86_64ks_**.cfg initrd=rhel4.7-x86_64/initrd.img ksdevice=link label 3-ks_** kernel centos5.4/vmlinuz append ks=nfs:192.168.1.254:/ios/centos5.4ks_**.cfg initrd=centos5.4/initrd.img ksdevice=link label 4-ks_** kernel centos5.4-x86_64/vmlinuz append ks=nfs:192.168.1.254:/ios/centos5.4-x86_64ks_**.cfg initrd=centos5.4-x86_64/initrd.img ksdevice=link label local localboot 0 label mem kernel memtest append –
这里由于选项太多,可以在tftp根目录下启用boot.msg与options.msg文件来说明安装什么样的操作系统和怎样安装操作系统。如:
boot.msgInstall RHEL4.7: 1 Install RHEL4.7 x86_64: 2 Install CentOS5.4: 3 Install CentOS5.4 x86_64: 4 Default: Graph mode. If you want to use text mode, type: [number] text F1: boot.msg F2: options.msg
options.msgInstall RHEL4.7: 1 Install RHEL4.7 x86_64: 2 Install CentOS5.4: 3 Install CentOS5.4 x86_64: 4 Default: Graph mode. If you want to use text mode, type: [number] text If you want to use kickstart, the flowing list the different OS ks.cfg: 1-ks_**: RHEL4.7 2-ks_**: RHEL4.7 x86_64 3-ks_**: CentOS5.4 4-ks_**: CentOS5.4 x86_64 F1: boot.msg F2: options.msg
7. 小结
只要注意各操作系统的内核和引导文件的对应关系,就能扩展到多套系统。
kickstart文件能在原来的基础上修改的就在原来的基础上修改,稍加时日,就可以形成针对各业务不同的kickstart文件,这样就方便IDC人员实现Linux操作系统的自动化安装。
The above is the detailed content of Linux system network installation method based on pxe+dhcp+nfs+tftp+kickstart. For more information, please follow other related articles on the PHP Chinese website!