linux远程安装DHCP+TFTP+NFS
http://blog.sina.com.cn/s/blog_6151984a0100ek1z.html
PXE(Pre-boot Execution Environment)是由Intel设计的协议,它可以使计算机通过网络启动
PXE client在网卡的ROM中,当计算机(网卡)引导时, BIOS把PXE client调入内存执行
-
PXE client通过DHCP获得自己的地址,和对应的引导文件 -
PXEclient通过TFTP将放置在远端的DHCP/TFTP SERVE上的操作系统通下载到本地运行。
[root@mail /]# cat /etc/dhcpd.conf
ddns-update-style interim; 如果系统对此句报错,就要先起named
ignore client-updates;
subnet 10.4.0.0 netmask 255.255.0.0 {
range 10.4.2.120 10.4.2.130;
option routers 10.4.1.198;
option subnet-mask 255.255.0.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;
default-lease-time 21600;
max-lease-time 43200;
option time-offset -18000;
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# option netbios-node-type 2;
host vm {
hardware ethernet 00:0c:29:9f:7b:32;
# 要事先获知安装主机网卡的MAC地址(把主机设成LAN启动后,开机就会看到)
fixed-address 10.4.2.116;
filename "pxelinux.0";
# This is the name of the file the boot ROMs should download.
option host-name "nm.lab.com";
# 加此句,否则安装时,会很慢的,找hostname时间
}
}
[root@mail tftpboot]# /etc/init.d/dhcpd start
Starting dhcpd:
[root@mail tftpboot]# /etc/init.d/dhcpd stop
Shutting down dhcpd: [ OK ]
[root@mail tftpboot]# /etc/init.d/dhcpd start
Starting dhcpd: [ OK ]
[root@mail tftpboot]#
-
步骤二。配置TFTP SERVER
/tftpboot/pxelinux.0 bootstrap文件 ,这是pxe协议的引导文件
这个文件是由一个软件syslinux提供,一般linux都有这个软件,通常位于/usr/lib/syslinux/
[root@mail]# ls /usr/lib/syslinux/
copybs.com isolinux-debug.bin memdisk pxelinux.0 syslinux.com
syslinux-nomtools isolinux.bin keytab-lilo.pl mkdiskimage sys2ansi.pl syslinux.exe
[root@mail]# cp /usr/lib/syslinux/pxelinux.0 /tftpboot
/tftpboot/initrd.img 根文件系统文件
[root@mail]# cd /mnt/cdrom/isolinux 从linux光盘的isolinux目录中拷贝
[root@mail isolinux]# ls
boot.cat general.msg isolinux.bin memtest
param.msg snake.msg TRANS.TBL boot.msg initrd.img
isolinux.cfg options.msg rescue.msg splash.lss vmlinuz
[root@mail isolinux]# cp initrd.img /tftpboot/
/tftpboot/vmlinuz 内核镜像文件
[root@mail isolinux]# cp vmlinuz /tftpboot/ 从linux光盘的isolinux目录中拷贝
/tftpboot/splash.lss 和*.msg boot:提示符上面显示的Redhat广告画
splash.lss
boot.msg
general.msg
options.msg
param.msg
rescue.msg
snake.msg
[root@mail isolinux]# cp splash.lss /tftpboot/ 从linux光盘的isolinux目录中拷贝
[root@mail isolinux]# cp *.msg /tftpboot/
cfg文件
[root@mail isolinux]# cp isolinux.cfg /tftpboot/pxelinux.cfg/default 此文件不放在tftpboot目录中,而在/tftpboot/pxelinux.cfg/目录中
可用光盘的/isolinux/isolinux.cfg。将这个文件直接改名为default拷贝过来,无需修改
都 cp 完后,/tftpboot下文件如下:
[root@mail /]# ls -F /tftpboot
boot.cat expert.msg initrd.img isolinux.cfg* memtest options.msg pxelinux.0
snake.msg TRANS.TBL boot.msg general.msg isolinux.bin param.msg pxelinux.cfg/ rescue.msg splash.lss vmlinuz
注:以上文件一般在RedHat安装版第一张光盘的/images/pxeboot下,或者/isolinux下(不同版本,目录也不太一样)(本文是在isolinux目录下)
步骤三。nfs server 配置
[root@mail /]#mount -o loop xxxx.iso /mnt/cdrom 把光盘iso mount上
[root@mail /]# vi /etc/exports
/mnt/cdrom *(ro,no_root_squash) 把mount 后的安装目录export出去
[root@mail /]# /etc/init.d/nfs start nfs server 启动
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
#ps -ef
root 11808 1 0 15:33 ? 00:00:00 [nfsd]
root 11809 1 0 15:33 ? 00:00:00 [nfsd]
root 11810 1 0 15:33 ? 00:00:00 [nfsd]
root 11811 1 0 15:33 ? 00:00:00 [nfsd]
root 11812 1 0 15:33 ? 00:00:00 [nfsd]
root 11813 1 0 15:33 ? 00:00:00 [nfsd]
root 11814 1 0 15:33 ? 00:00:00 [nfsd]
root 11815 1 0 15:33 ? 00:00:00 [nfsd]
root 11819 1 0 15:33 ? 00:00:00 rpc.mountd
root 11913 11361 0 17:11 pts/3 00:00:00 ps -ef
有可能的话,远端找台机器检测一下nfs
[root@vm macg]# mount -t nfs 10.4.1.105:/mnt/cdrom /mnt/cdrom/
[root@vm macg]# ls /mnt/cdrom
autorun RELEASE-NOTES-bn.html RELEASE-NOTES-U1-it.html
EULA RELEASE-NOTES-de.html RELEASE-NOTES-U1-ja.html
GPL RELEASE-NOTES-en RELEASE-NOTES-U1-ko.html
images RELEASE-NOTES-en.html RELEASE-NOTES-U1-pa.html
isolinux RELEASE-NOTES-es.html RELEASE-NOTES-U1-pt_BR.html
在dhcpd.conf文件中,filename 不是绝对路径,而是/tftpboot下的相对路径,即filename filename"pxelinux.0"; 是表示/tftpboot/pxelinux.0
千万别写成 filename "/tftpboot/pxelinux.0";
更要注意:linux的 man dhcpd写得不对
[root@mail tftpboot]# man dhcpd
dhcpd(8)
dhcpd(8)
NAME
dhcpd - Dynamic Host Configuration Protocol Server
SYNOPSIS
BOOTP Support
host haagen {
hardware ethernet 08:00:2b:4c:59:23;
fixed-address 239.252.197.9;
filename "/tftpboot/haagen.boot";
}
比如一个PXEClient由DHCPServer分配的IP地址为192.168.0.22,那么相对应的配置文件名为/tftpboot/pxelinux.cfg/C0A80016
(注:C0A80016为IP地址192.168.0.22的十六进制表示)。
用光盘进行远程NFS安装的缺陷:export mount point后很难umount
root@mail /]# umount /mnt/cdrom
umount: /mnt/cdrom: device is busy
umount: /mnt/cdrom: device is busy
[root@mail /]# /etc/init.d/nfsstop
Shutting down NFS mountd: [
Shutting down NFS daemon: [
Shutting down NFS quotas: [
Shutting down NFS services:
[root@mail /]# umount /mnt/cdrom