pxe remote installation linux system

        Today and colleagues to room to install a hard disk, open the machine, find SCSI line is not long enough, can only take one hard disk. It seems only replace the old with the new hard disk drive, but did not take time to go any disc, you can not install a new hard drive operating system, colleagues say you can go back with PXE, PXE remote installation of the system before also have some understanding, but not practiced in the online search of the following information.:
 
Fundamental
  1) What is PXE
  PXE (Pre-boot Execution Environment) is a protocol designed by Intel, which allows the computer via a network boot. Server and client protocol is divided into two ends, PXE client in the ROM of the card, when the computer is booted, the BIOS performs the PXE client into memory, and displays the command menu, the selection by the user, the PXE client placed at the distal end operating system downloaded to run locally through the network.
  Successful operation of PXE protocol need to address the following two questions:
  1. Since it is transmitted over the network, the computer starts, its IP address configuration by whom;
  2. Through what protocol to download the Linux kernel and root file system
  For the first problem can be solved by DHCP Server, a DHCP server to assign an IP address to the PXE client, DHCP Server protocol is used to dynamically assign IP addresses DHCP Client, but because this is an IP address assigned to the PXE Client, so when configuring DHCP Server, you need to add the appropriate PXE-specific configuration.
  As for the second question, the ROM PXE client is located, has been in existence TFTP Client. PXE Client use TFTP Client, TFTP Server to download the required files via TFTP protocol.
  In this way, the conditions would have to run the PXE protocol, let's take a look at the work process PXE protocol.
2) the work process
在上图中,PXE client是需要安装Linux的计算机,TFTP Server和DHCP Server运行在另外一台Linux Server上。Bootstrap文件、配置文件、Linux内核以及Linux根文件系统都放置在Linux Server上TFTP服务器的根目录下。
  PXE client在工作过程中,需要三个二进制文件:bootstrap、Linux 内核和Linux根文件系统。Bootstrap文件是可执行程序,它向用户提供简单的控制界面,并根据用户的选择,下载合适的Linux内核以及Linux根文件系统。
 
具体配置过程如下:
首先是安装必要的服务,DHCPD,TFTP-SERVER,NFS(一般默认就有了)
dhcpd和tftp-server都有对应的rpm,直接安装就可以了.
# vi /etc/xinetd.d/tftp
=============+==========+===========+============+============
service tftp
{
        disable = no (默认是yes,这里改成no,启用它)
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -u nobody -s /tftpboot //-s 表示用/tftpboot作为tftp目录的根目录. 
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}
tftp是由xinted来启动的,修改完后要记得service xinetd restart
# vi /etc/dhcpd.conf
=============+==========+===========+============+============
ddns-update-style interim;
ignore client-updates;
default-lease-time 21600;
max-lease-time 43200;
authourtative;
next-server 192.168.1.103;
subnet 192.168.1.0 netmask 255.255.255.0 {
    option routers          192.168.1.1;
    option subnet-mask      255.255.255.0;
    range 192.168.1.1 192.168.1.100;
    default-lease-time 21600;
    max-lease-time 43200;
    filename "/pxelinux.0";
    option domain-name-servers 202.106.0.20;
}
这里的 pxelinux.0就是上面提到的bootstrap,上面已经指定了tftp的根目录,所以这里用相对路径.
next-server 192.168.1.103;这句一开始我并没有加上,当要安装系统的机器启动以后,在查找pxelinux.cfg目录下的配置文件的时候,就死活找不 到了.经过很长时间的等待,出现一个boot:的提示符,告诉我:can't load kernel image:linux,一开始以为是/tftpboot/pxelinux.cfg/default的配置文件有误,检查后没问题.
google了半天,总算查到了一个帖子,说可能是dhcp3.0的一个bug,需要加上这个参数来指定DHCP SERVER的IP.修改配置文件加入此句后,重启dhcp,然后再重新启动客户机,这次速度大大加快,顺利通过.
3 配置支持PXE 
# mkdir /tftpboot
# cp /usr/lib/syslinux/pxelinux.0 /tftpboot
把LINUX第一张安装光盘上/image/pxeboot/initrd.img和vmlinuz 以及isolinux/*.msg考到/tftpboot目录下 (*.msg也可以不拷,重点是initrd.img和vmlinuz,没有内核是无法引导的)
# cd /tftpboot
# mkdir pxelinux.cfg
# vi defaultdefault centos5
prompt 1
timeout 30
label centos5
 kernel vmlinuz
append ks=nfs:192.168.1.103:/root/inst/ks initrd=initrd.img devfs=nomount ramdisk_size=9216
#append initrd=initrd.img devfs=nomount ramdisk_size=9216

 这里的 ks=nfs:192.168.1.103:/root/inst/ks 文件是指定kickstart配置文件,可以在安装中不用人工干预,自动按预设的参数安装.实现安装过程的全自动.
4 配置NFS服务
# vi /etc/exports
/root/inst      192.168.1.0/24(ro,sync) //这里是/root/inst 而不是/root/inst/
# mkdir /home/iso
拷贝安装LINUX的ISO文件到这个目录
5 需要开启的系统服务
/dhcpd/network/nfs/portmap/syslog/tftp/xinetd/
service dhcpd start
service portmap start
service nfs start
最后附上ks文件的内容.
install
nfs --server=192.168.1.103 --dir=/root/inst
lang en_US.UTF-8
keyboard us
network --device eth0 --bootproto static --ip 192.168.1.220 --netmask 255.255.255.0 --gateway 192.168.1.1  --nameserver 192.168.1.1
#network --device eth0 --bootproto DHCP
rootpw --iscrypted $1$WvFbqnpm$m94fa4AopXI/kfYOYbWMW.
firewall --enabled --port=22:tcp
#firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
clearpart --all
zerombr yes
clearpart --linux --initlabel
part /boot --fstype ext2 --size=256
part / --fstype ext3 --size=8192
part /opt --fstype ext3 --size=8192
part /usr --fstype ext3 --size=16384
part swap --size=4096
part /home --fstype ext3 --size=1 --grow
reboot //加入这行后装完系统后可以自动重启,需要注意的是机器的启动顺序不能是网卡优先,否则会循环装系统........
%packages --resolvedeps
@ everything
grub
kernel
kernel-devel
e2fsprogs
 

转载于:https://www.cnblogs.com/ericsun/archive/2013/05/24/3096858.html

Guess you like

Origin blog.csdn.net/weixin_33721427/article/details/93154958
Recommended