基于PXE+Pressed方式的Ubuntu14.04网络安装
1.PXE简介
PXE是由Intel公司开发的最新技术,工作于Client/Server的网络模式,支持工作站通过网络从远端服务器下载映像,并由此支持来自网络的操作系统的启动过程,其启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transferprotocol)或MTFTP(multicast trivialfile transfer protocol)协议下载一个启动软件包到本机内存中并执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。PXE可以引导多种操作系统,如:Windows 95/98/2000/xp/2003/vista/2008,linux等。
2.环境
PXE Server:ubuntukylin-14.04.4-desktop 64位操作系统,IP:192.168.198.128
PXE Client:ubuntu-14.04-server-amd64, BIOS设置从网络启动(若为第一次安装可不用设置)
注:PXE Server和PXE Client在一个局域网内。
首先,笔记本能正常上网,虚拟机的网卡采用NAT方式,虚拟机也能正常上网
打开左边的终端窗口,安装网络安装所需的软件,此处强调一点,必须保证你所操作的分发服务器(此处是虚拟机)能正常联外网,否则由于软件本身的依赖关系会导致安装不了,鉴
于此生产环境中建议将自己的笔记本安装Ubuntu 桌面版然后作为分发服务器进行网络分发。
3.PXE Server 安装相关服务
1) apt-get install system-config-kickstartubuntu网络配置
2) apt-get installdhcp3-server
3) apt-get installapache2
4) apt-get installtftpd-hpa tftp-hpa
4.配置dhcp服务
修改配置文件/etc/f,配置如下图:
subnet 192.168.198.0 netmask 255.255.255.0 { range 192.168.198.129 192.168.198.254; option domain-name "192.168.198.128"; option domain-name-servers 192.168.198.128; option routers 192.168.198.1; default-lease-time 600; max-lease-time 7200; next-server 192.168.198.128; filename "pxelinux.0"; } |
说明:
subnet为dhcp服务器分配ip的子网192.168.74网段,必须和PXE server的一个网卡同一个网段;
range为dhcp服务器为客户端分配IP的范围;
domain-name为客户端指明DNS名字;
domain-name-servers为客户端指明DNS服务器的IP地址;
routers为客户端指定网关;
default-lease-time为默认租约时间(单位:秒);
max-lease-time为最大租约时间(单位:秒);
next-server为客户端指定tftp服务器地址
filename为开始启动文件的名称;
host ns1中是位特定的MAC地址指定IP地址;
配置好后运行DHCP服务:
#service isc-dhcp-server restart 来重启服务
运行netstat -anp | grep :67
udp 0 0 0.0.0.0:67 0.0.0.0:*1777/dhcpd
这个表示服务已经在运行中。
5.配置Apache服务
首先创建ubuntu14.04的镜像目录:
#mkdir /var/www/html/ubuntu14.04
挂载Ubuntu14.04的光盘镜像:
#mount /dev/cdrom /mnt
#cp –r /mnt/* /var/www/html/ubuntu14.04
启动apache:
#/etc/init.d/apache2 start
并保证通过浏览器访问192.168.198.128/ubuntu14.04/ 可以看到目录的内容。
6.配置TFTP
配置文件/etc/default/tftpd-hpa默认不用修改。
7.创建pxe加载文件:
#cd /var/lib/tftpboot/
#cp -r /var/www/html/ubuntu14.04/install/netboot/* .
修改/var/lib/tftpboot/ubuntu-installer/amd64/boot-screens目录下的syslinux.cfg文件:
timeout改为1
8.修改文件
首先解包initrd,然后在initrd根目录下面放置一个文件preseed.cfg,然后在将initrd打包
解包initrd
#cd /home
#cp /var/lib/tftpboot/ubuntu-installer/ .
#
#mv initrd initrd.img
#mkdir initrd
#cd initrd
#cpio -id <../initrd.img
添加全自动安装的内容
#vi preseed.cfg (该文件应在initrd目录下,后面我们要把initrd目录里的内容重新再打包)
#locate d-i debian-installer/locale string en_US #keyboard d-i console-setup/ask_detect boolean false d-i console-configuration/layoutcode string us d-i keyboard-configuration/modelcode string SKIP #clock d-i clock-setup/utc boolean false d-i time/zone string Asia/Shanghai #network d-i netcfg/choose_interface select eth0 d-i netcfg/dhcp_failed note d-i netcfg/dhcp_options select Do not configure the network at this time d-i netcfg/get_hostname string ubuntu d-i netcfg/get_domain string ubuntu-domain #mirror d-i mirror/country string manual d-i mirror/http/hostname string 192.168.74.128 d-i mirror/http/directory string /ubuntu14.04 d-i mirror/http/proxy string #clock d-i clock-setup/ntp boolean true #Partitioning #d-i partman-auto/disk string /dev/sda d-i partman-auto/method string regular d-i partman-lvm/device_remove_lvm boolean true d-i partman-md/device_remove_md boolean true d-i partman-auto/choose_recipe select atomic d-i partman/default_filesystem string ext4 d-i partman/confirm_write_new_label boolean true d-i partman/choose_partition select Finish d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true # Base system installation d-i base-installer/kernel/image string linux-generic #user d-i passwd/root-login boolean root d-i passwd/root-password password 111111 d-i passwd/root-password-again password 111111 d-i user-setup/allow-password-weak boolean true d-i passwd/make-user boolean false d-i user-setup/encrypt-home boolean false #file system d-i live-installer/net-image string 192.168.198.128/ubuntu14.04/install/filesystem.squashfs #apt setup d-i apt-setup/use_mirror boolean false d-i apt-setup/services-select multiselect security d-i apt-setup/security_host string 192.168.198.128 d-i apt-setup/security_path string /ubuntu14.04 d-i debian-installer/allow_unauthenticated string true #package tasksel tasksel/first multiselect standard d-i pkgsel/include string openssh-server vim d-i pkgsel/install-language-support boolean false d-i pkgsel/language-packs multiselect en, zh d-i pkgsel/update-policy select none #grub d-i grub-installer/skip boolean false d-i lilo-installer/skip boolean true d-i grub-installer/grub2_instead_of_grup_legacy boolean true d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true d-i preseed/late_command string sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /target/etc/ssh/sshd_config d-i finish-install/reboot_in_progress note |
注:
d-i live-installer/net-image string 192.168.198.128/ubuntu/install/filesystem.squashfs
这项为必须的配置项(ubuntu12.10版本以后,安装一些包会依赖于预配置的文件系统,这就是导致使用kickstart方式无法成功安装的原因),否则在安装过程中会失败。
然后再打包:
#find . | cpio -o -H newc |gzip -9 >../
替换网络启动的initrd
#cd ..
# /var/lib/tftpboot/ubuntu-installer/amd64/
9.测试网络安装
之后新建一个虚拟机,启动虚拟机,全程自动安装,安装完成后自动重启。
安装成功后:
10.参考文件
Debian官方附录:附录 B. 使用预置自动进行安装
/releases/stable/amd64/apbs04.html.zh-cn
示例脚本
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论