标题: PXE NFS kickstart实现无人值守安装Red Hat Enterprise Linux 目的: PXE NFS kickstart实现无人值守安装Red Hat Enterprise Linux 作者信息: Alin Fang MSN: cst05001@hotmail.com G Talk: cst05001@gmail.com 19 Aug, 2008 原理: 首先我们必须搞清楚linux的安装大概是什么东西在干什么事情: 安装linux的系统启动过程: BIOS=>引导介质=>用于安装环境的linux内核(vmlinuz)和驱动模块(initrd.img)=>安装程序(anaonda)=>寻找安装介质=>由安装程序从安装介质获取所需安装文件=>完成安装配置(普通配置, IPTABLES, SELinux)[=>重启(如果你disabled了SELinux,默认是开启的)]=>进入系统 由于上面只是简要描述了下安装的表层原理,现在我来讲下几个阶段的实现。 引导介质: Red Hat Enterprise Linux 5至少支持这几种引导介质: CDROM Hard Disk(具体做法请参考方云麟的《用硬盘安装Red Hat Enterprise Linux》) U盘(具体做法请参考方云麟的《用U盘安装Red Hat Enterprise Linux》) NIC(俗称网卡-__-||) 这里重点是讲以网卡作为引导介质安装linux的方法。 网卡要能作为安引导介质,必须有一个叫做Preboot Execution Environment(预启动执行环境) 的模块,简称PXE。(参考: http://en.wikipedia.org/wiki/Preboot_Execution_Environment ) PXE的功能有: 通过IP, TCP, UDP, TFTP等协议连接到远程服务器上。 执行PXE固件上预定义好的API。 现在我们的关键是,如何让PXE模块连接到我们的安装服务器上? 要连接网络,首先必须有一个IP。但是网卡的PXE模块并没有让用户自定义静态IP的功能,它只能够通过DHCP协议获取IP。于是要求我们的安装环境里面有一台能够提供DHCP服务的服务器。 PXE模块安装到服务器上后,我们需要把安装用的程序(vmlinuz, initrd.img, 等等)传输到待安装机器上来,我选择用TFTP协议。 具备以上条件后,我们已经可以在待安装机器启动安装程序了。 我把到此为止定义成安装的第一阶段。 第一阶段和下面开始安装(我姑且把下面阶段定义成安装的第二阶段),是相对独立的。 记住,是相对独立的! 然后开始讲安装程序 anaonda安装linux的几个步骤。 安装程序首先必须确定你通过什么安装介质来安装linux。 如果是CDROM,则搜索CDROM上的安装包以及其他安装所需的文件。 如果是Hard Disk,则会询问你你的安装镜像或者安装树在哪个硬盘分区的哪个文件目录下。 如果是通过网络安装(NFS, FTP, HTTP),则会在这个时候初始化网络,并定位安装源位置。 这里有个很重要的事情要搞清楚。有人会问“之前网卡PXE模块已经获取了一次IP地址,为什么现在还要设置一次?” 这里我再说明以下, 1)PXE获取的是安装用的内核以及安装程序等,安装程序要获取的是安装系统所需的二进制包以及配置文件! 2)PXE模块和安装程序是相对独立的,PXE的网络配置并不能传递给安装程序! 这个就是为什么要再次配置一下网络的原因。 回到原先话题。 我们说了,这文章重点是讲述如何PXE kickstart NFS安装linux。 至此,当给安装程序指定了安装源的位置之后,安装程序就可以像常规的CDROM安装linux一样进行安装了。 (PXE的存在其实是一次意外,详情请参考: http://en.wikipedia.org/wiki/Preboot_Execution_Environment ) 什么是kickstart? Kickstart是一个主要用在Red Hat系列以及基于Red Hat的发行版本的自动安装工具集( http://en.wikipedia.org/wiki/Kickstart_(Linux ) ) 我们这次要用kickstart进行无人值守全自动安装,主要要用到的kickstart工具有 1)/root/anaconda-ks.cfg 这个文件是安装完linux,安装程序留下来的基于本机配置的kickstart安装脚本 2)system-config-kickstart 这个是kickstart的配置工具(如果没有,请自行安装-__-|||) 如何使用kickstart配置文件? 在我们这里,kickstart配置文件将给安装用内核vmlinuz调用。 什么是NFS? NFS全称Network File System( http://en.wikipedia.org/wiki/Network_File_System_(protocol ) ),NFS协议很方便的实现了UNIX/LINUX等OS的文件共享。 什么是DHCP? DHCP的全程是Dynamic Host Configuration Protocol,即动态主机信息分配协议。能分配给网卡很多信息,比如,IP,等等…… OK,知道了这些之后,我就开始进行实际操作了。 流程图: screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://docs.google.com/File?id=dhkp88bm_15fm5h95ft_b');}" onmousewheel="return imgzoom(this);" alt="" /> 拓扑图: screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://docs.google.com/File?id=dhkp88bm_16c3365fgd_b');}" onmousewheel="return imgzoom(this);" alt="" /> 实验环境: 网段:192.168.0.0/24 服务器IP:192.168.0.1 客户机IP:192.168.0.2 – 192.168.0.254 操作系统:Red Hat Enterprise Linux 5.2 Server i386 步骤: 配置NFS服务: [root@server1 tftpboot]# mkdir -p /var/sysinstall [root@server1 tftpboot]# vim /etc/exports /var/sysinstall 192.168.0.0/24(ro,async) [root@server1 tftpboot]# service nfs restart Shutting down NFS mountd: [FAILED] Shutting down NFS daemon: [FAILED] Shutting down NFS services: [ OK ] Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ] [root@server1 tftpboot]# cp -rf /misc/cd/* /var/sysinstall/ 这里我尝试使用ln,但是之后在客户机安装的时候找不到安装树 [root@server1 tftpboot]# cd /var/sysinstall/ [root@server1 sysinstall]# 安装TFTP服务: 略 [root@server1 Server]# rpm -q tftp-server tftp-server-0.42-3.1 [root@server1 Server]# [root@server1 Server]# vim /etc/xinetd.d/tftp service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4 } [root@server1 Server]# service xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@server1 Server]# netstat -nupal |grep 69 udp 0 0 0.0.0.0:69 0.0.0.0:* 5433/xinetd udp 0 0 :::32769 :::* 5159/avahi-daemon: [root@server1 Server]# OK,TFTP服务已经开启。 配置pxe服务模块: [root@server1 Server]# updatedb [root@server1 Server]# locate pxelinux.0 /tftpboot/linux-install/pxelinux.0 /usr/lib/syslinux/pxelinux.0 [root@server1 Server]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot/ [root@server1 Server]# [root@server1 cd]# pwd /misc/cd [root@server1 cd]# /bin/cp isolinux/* /tftpboot/ -rf [root@server1 cd]# cd /tftpboot/ [root@server1 tftpboot]# ls boot.cat initrd.img linux-install param.msg splash.lss boot.msg isolinux.bin memtest pxelinux.0 TRANS.TBL general.msg isolinux.cfg options.msg rescue.msg vmlinuz [root@server1 tftpboot]# mkdir pxelinux.cfg [root@server1 tftpboot]# cp isolinux.cfg pxelinux.cfg/default [root@server1 tftpboot]# vim pxelinux.cfg/default default linux prompt 1 timeout 10 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 ks=nfs:192.168.0.1:/var/sysinstall/ks.cfg 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 - 安装kickstart配置工具: [root@server1 ~]# cd /misc/cd [root@server1 cd]# cd Server/ [root@server1 Server]# rpm -ivh system-config-kickstart-2.6.19.6-1.el5.noarch.rpm warning: system-config-kickstart-2.6.19.6-1.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 error: Failed dependencies: pykickstart is needed by system-config-kickstart-2.6.19.6-1.el5.noarch [root@server1 Server]# rpm -ivh pykickstart-0.43.1-1.el5.noarch.rpm warning: pykickstart-0.43.1-1.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:pykickstart ########################################### [100%] [root@server1 Server]# rpm -ivh system-config-kickstart-2.6.19.6-1.el5.noarch.rpm warning: system-config-kickstart-2.6.19.6-1.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:system-config-kickstart########################################### [100%] [root@server1 Server]# system-config-kickstart 这个命令是在X下运行的。 用 system-config-kickstart打开/root/anaconda-ks.cfg,根据需求修改配置。并且另存为/var/sysinstall/ks.cfg #platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 # System bootloader configuration bootloader --append="rhgb quiet" --location=mbr --driveorder=sda # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel 这行一定不能注释,否则会让你确认是否格式化硬盘 # Use text mode install text # Firewall configuration firewall --disabled # Run the Setup Agent on first boot firstboot --disable key xxxx-xxxx-xxxx-xxxx # System keyboard keyboard us # System language lang en_US # Installation logging level logging --level=info # Use NFS installation media nfs --server=192.168.0.1 --dir=/var/ftp/public # Network information network --bootproto=dhcp --device=eth0 --onboot=on # Reboot after installation reboot #Root password rootpw --iscrypted $1$K3L4H4zb$5DPvt/Va6WHXTYHnUKrzh. # SELinux configuration selinux --disabled # System timezone timezone --isUtc Asia/Shanghai # Install OS instead of upgrade install # X Window System configuration information xconfig --defaultdesktop=GNOME --depth=24 --resolution=1024x768 --startxonboot # Disk partitioning information part /boot --bytes-per-inode=4096 --fstype="ext3" --size=256 part swap --bytes-per-inode=4096 --fstype="swap" --size=512 part / --bytes-per-inode=4096 --fstype="ext3" --grow s--size=1 %packages @office @editors @text-internet @gnome-desktop @dialup @core @base @games @java @legacy-software-support @base-x @graphics @printing @sound-and-video @admin-tools @graphical-internet emacs kexec-tools device-mapper-multipath xorg-x11-utils xorg-x11-server-Xnest libsane-hpaio -sysreport 这个是我的ks.cfg 安装并配置DHCP服务: [root@server1 Server]# rpm -ivh dhcp-3.0.5-13.el5.i386.rpm warning: dhcp-3.0.5-13.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:dhcp ########################################### [100%] [root@server1 Server]# cat /etc/dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample #[root@server1 Server]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcp.conf cp: overwrite `/etc/dhcpd.conf'? Y [root@server1 Server]# vim /etc/dhcpd.conf ddns-update-style interim; ignore client-updates; subnet 192.168.0.0 netmask 255.255.255.0 { # --- default gateway option routers 192.168.0.1; option subnet-mask 255.255.255.0; filename "/pxelinux.0"; next-server 192.168.0.1; option time-offset -18000; # Eastern Standard Time range dynamic-bootp 192.168.0.128 192.168.0.254; default-lease-time 21600; max-lease-time 43200; } [root@server1 Server]# service dhcpd start Starting dhcpd: [ OK ] [root@server1 Server]# netstat -nupal | grep dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 5525/dhcpd [root@server1 Server]# 结果: 这样一个基于PXE NFS kickstart的无人值守安装Red Hat Enterprise Linux就配置完成了。 |
|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )
GMT+8, 2024-9-30 07:20 , Processed in 0.278430 second(s), 12 queries , Gzip On, MemCache On.
Powered by Discuz! X3.5
© 2001-2023 Discuz! Team.