为网络启动设置PXE服务器
如果你的系统完全崩溃掉了,不想刻盘,不想USB安装。又或是你需要给一个机房所有的机器安装系统。那么如果硬件支持,你应该试试网络安装。下面仅以debian为例介绍一下如何网络安装系统。
首先你的主板要支持网络启动,具体可以看bios。同时你需要设置一台 TFTP 服务器,并且对于很多机器来说,还需要一台 DHCP 服务器 ,或 BOOTP 服务器。BOOTP 是一种 IP 协议,用来告诉一台计算机它自己 IP 地址以及从网络何处获得启动映像。 DHCP (Dynamic Host Configuration Protocol) 是一个更灵活,向后兼容的 BOOTP 扩展。有些系统只能通过 DHCP 来配置。这里只介绍如何通过dhcp和tftp完成网络安装。
1、安装、配置tftp
1.1 安装
# aptitude install tftpd-hpa
1.2 配置
$ vim /etc/inetd.conf
写入一下内容(lenny中默认已经设置好了):
tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
在较新版本的系统中(lenny中需要),还需要将/etc/default/tftpd-hpa中的RUN_DAEMON置为yes。
1.3 启动tftp服务(始配置生效)
#/etc/init.d/tftp-hda start
2、安装、配置dhcp服务器
2.1 安装:
$ apt-get install dhcp3-server
2.2 配置
$ vim /etc/dhcp3/dhcpd.conf
加入如下内容:
# the configuration file for dhcpd when "Network boot linux via PXE"
# configure the ipaddress range, here is needded ***
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.2 192.168.1.254;
}
# configure the ipaddress of the tftp server and the default file name
# please setup tftpd and put pxelinux.0 in the root directory of it
next-server 192.168.1.1;
filename "pxelinux.0";
# configure the ipaddress of the tftp server as 192.168.1.1 to avoid it getting
# a dynamical one, you'd modify the ethernet to your own before you using this
# configuration file
host server { # ensure the ip address of tftp
hardware ethernet 00:e0:b0:f5:82:61; #
fixed-address 192.168.1.1;
}
range指定了客户机可以得到的ip的范围;next-server指定tftp服务器的ip地址;filename指定所启动的文件,这里注意,路径为相对于/etc/inetd.conf -s 后所指定的路径,一定不能写成绝对路径!!hardware ethernet 指定服务器的网卡地址,将服务器ip绑定为192.168.1.1避免服务器ip发生变化,使客户机不能tftp到指定的文件。至此,dhcp服务器配置完毕,现在一定不能在一个局域网里面启动,否则整个网络会出现问题。
下面通过交叉线(当然也可以通过交换机)将欲装系统的客户机和配置好的服务器相连。
2.3 配置ip 与指定的fixed-address相同
#ifconfig eth0 192.168.1.1
2.4 重启使配置生效
#/etc/init.d/dhcp3-server start
2.5 若无法启动dhcp服务。
若无法启动,看看自己ip与fixed-address是否一样,不一样则无法启动。
3、配置PXE
只需要vmlinuz(or linux) 和initrd这两个文件就可以了。
3.1 充分利用debian的netboot.tar.gz来配置PXE
到http://http.us.debian.org/debian/dists/lenny/main/installer-i386/current/images/netboot/netboot.tar.gz (或者其它镜像站下载)下载netboot.tar.gz并解压到/var/lib/tftpboot.当然如果inetd.conf中你指定是别的路径,就解压到相应的地方,解压后得到debian-installer目录。
3.2 在/var/lib/tftpboot目录下,利用debian-installer目录下的boot-screens创建menu目录,用于在进入安装之前,设置选择安装哪个发行版
#cd /var/lib/tftpboot
#mv debian-installer/i386/boot-screens menu
其实只要保留 menu.cfg syslinux.cfg txt.cfg vesamenu.c32 这四个文件就可以了,但是全部保留也没关系,可以只删掉*.txt文件(rm *.txt)
3.3
# cp -a /var/lib/tftpboot/debian-installer/i386/pxelinux.* /var/lib/tftpboot
修改default文件为:
# D-I config version 1.0
include menu/menu.cfg
default menu/vesamenu.c32
prompt 0
timeout 0
3.4 添加一个需要安装的发行版
3.4.1 添加debian的网络安装
3.4.1.1 以安装debian lenny i386为例:
准备linux和initrd.gz
#mkdir /var/lib/tftpboot/debian_lenny_i386
#cp /var/lib/tftpboot/debian-installer/i386/linux /var/lib/tftpboot/debian_lenny_i386
#cp /var/lib/tftpboot/debian-installer/i386/initrd.gz /var/lib/tftpboot/debian_lenny_i386
3.4.1.2 配置新加入的网络安装的发行版,使之可以显示
#cd /var/lib/tftpboot/menu/
#cp txt.cfg lenny_i386.cfg
修改lenny_i386.cfg 为
label install
menu label ^Install lenny i386
menu default
kernel debian_lenny_i386/linux
append vga=normal initrd=debian_lenny_i386/initrd.gz -- quiet
(命名根据自己的习惯命就可以了)
最后,
unanao:/var/lib/tftpboot/menu#cat menu.cfg
menu hshift 13
menu width 49
menu title Installer boot menu
include debian-install/i386/boot-screens/stdmenu.cfg
include menu/lenny_i386.cfg --这里加入include lenny_i386.cfg (写的时候不要加--后面的内容)
include menu/centos.cfg
include debian-install/i386/boot-screens/amdtxt.cfg
include debian-installer/i386/boot-screens/gtk.cfg
include debian-installer/i386/boot-screens/amdgtk.cfg
menu begin advanced
menu title Advanced options
include debian-installer/i386/boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include debian-installer/i386/boot-screens/adtxt.cfg
include debian-installer/i386/boot-screens/amdadtxt.cfg
include debian-installer/i386/boot-screens/adgtk.cfg
include debian-installer/i386/boot-screens/amdadgtk.cfg
menu end
label help
menu label ^Help
text help
Display help screens; type 'menu' at boot prompt to return to this menu
endtext
config debian-installer/i386/boot-screens/prompt.cfg
(其实这个配置文件里面好多都没有用了,不过懒着删了呵呵)
一个debian lenny i386 的网络启动就做好了,其它的发行版也大同小异。
3.4.2 添加centos的网络安装
准备:vmlinuz 和initrd.img两个文件
#cd /var/lib/tftpboot/
#mkdir /var/lib/tftpboot/centos_i386
#wget http://centos.ustc.edu.cn/centos/5.4/isos/i386/CentOS-5.4-i386-netinstall.iso
将vmlinuz 和initrd.img 拖出放入 centos_i386目录中
3.4.1.2 配置新加入的网络安装的发行版,使之可以显示
#cd /var/lib/tftpboot/menu/
#cp txt.cfg centos_i386.cfg
修改centos_i386.cfg 为
label install
menu label ^Install centos i386
menu default
kernel centos_i386/linux
append vga=normal initrd=centos_i386/initrd.gz -- quiet
(命名根据自己的习惯命就可以了)
最后,
unanao:/var/lib/tftpboot/menu#cat menu.cfg
menu hshift 13
menu width 49
menu title Installer boot menu
include debian-install/i386/boot-screens/stdmenu.cfg
include menu/lenny_i386.cfg --这里加入include lenny_i386.cfg (写的时候不要加--后面的内容)
include menu/centos.cfg --这里加入include centos_i386.cfg (写的时候不要加--后面的内容)
include debian-install/i386/boot-screens/amdtxt.cfg
include debian-installer/i386/boot-screens/gtk.cfg
include debian-installer/i386/boot-screens/amdgtk.cfg
menu begin advanced
menu title Advanced options
include debian-installer/i386/boot-screens/stdmenu.cfg
label mainmenu
menu label ^Back..
menu exit
include debian-installer/i386/boot-screens/adtxt.cfg
include debian-installer/i386/boot-screens/amdadtxt.cfg
include debian-installer/i386/boot-screens/adgtk.cfg
include debian-installer/i386/boot-screens/amdadgtk.cfg
menu end
label help
menu label ^Help
text help
Display help screens; type 'menu' at boot prompt to return to this menu
endtext
config debian-installer/i386/boot-screens/prompt.cfg
(其实这个配置文件里面好多都没有用了,不过懒着删了呵呵)
一个cenos i386 的网络启动就做好了,其它的发行版也大同小异。
在centos安装的时候有一个地方 Installation Method
选择 HTTP
Web site name:centos.ustc.edu.cn
CentOS directory: centos/5.4/os/i386
3.4.3 网络安装arch
下载的vmlinuz和initrd.img的地址:
ftp://mirror.lzu.edu.cn/archlinux/iso/archboot/2009.08/archlinux-2009.08-1-archboot.iso
在isolinux目录里面的vmlinuz和initrd.img的两个文件。
其它的方法同上面两个发行版的安装。
4、安装系统
启动客户机,进bios设为从网络启动。等待一会儿,熟悉的安装界面出来了,可以开始安装了。
(注意在获取ip之前,请将server的dhcp服务停掉)
然后本本从PXE启动就可以了,进入安装后到了选择DEBIAN安装镜像那一步时候由于台式机和本本组成的小局域网和外界隔离所以无法找到镜像,这个时候可以拔下本本的网线然后直接插到可以可以连到外面的交换机上(就是大局域网上),运行一把dhcpclient 就可以(让本本在不重新启动的情况下在新网络里通过DHCP重新分配IP,如果你的台式机没有和外界隔离并且提供DNS和网关服务就不需要这样插拔网线啦)。这样就完成了安装。
5、参考资料:
http://oss.lzu.edu.cn/modules/newbb/viewtopic.php?topic_id=1437&forum=6
http://www.thusa.co.za/blog/warwick-chapman/howto-pxe-boot-menu-both-debian-50-lenny-and-40-etch-network-installs
http://www.chrisgountanis.com/technical/45-centos-netinstall.html
