环境
PXE网段:172.25.151.0/24
PXE网关:172.25.151.1
PXE服务器地址:172.25.151.254
PXE服务器系统 : ubuntu 16.04
DHCP地址池:172.25.151.240~172.25.151.253
PXE安装镜像IOS:ubuntu-16.04.4-server-amd64
挂载目录:/mnt
首先:设置网卡1 以pxe方式启动 最后:安装完成后恢复默认启动方式。
配置:
1.安装dhcp服务器
apt-get install isc-dhcp-server
修改网卡
root@ubuntu-pxe:~# cat /etc/default/isc-dhcp-server | grep -v "^#" | grep -v "^$" INTERFACES="enp2s0"
配置dhcp地址池
root@ubuntu-pxe:~# cat /etc/dhcp/dhcpd.conf | grep -v "^#" | grep -v "^$" ddns-update-style none; log-facility local7; subnet 192.168.151.0 netmask 255.255.255.0 { range 192.168.151.240 192.168.151.253; option domain-name-servers 192.168.111.2; option subnet-mask 255.255.255.0; option routers 192.168.151.1; option broadcast-address 192.168.151.255; default-lease-time 600; max-lease-time 7200; } allow booting; allow bootp; option option-128 code 128 = string; option option-129 code 129 = text; next-server 192.168.151.254; filename "pxelinux.0";
重启dhcp服务
systemctl restart isc-dhcp-server@H_301_28@
apt-get install tftpd-hpa
修改配置
root@ubuntu-pxe:~# cat /etc/default/tftpd-hpa | grep -v "^#" | grep -v "^$" TFTP_USERNAME="tftp" TFTP_DIRECTORY="/var/lib/tftpboot" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="--secure" RUN_DAEMON="yes" OPTIONS="-l -s /var/lib/tftpboot"
3.安装Apache2
apt-get install apache2
mkdir /var/www/html/ubuntu rm -fr /var/www/html/index.html mount /dev/cdrom /mnt cp -r /mnt/* /var/www/html/ubuntu/ cp -r /var/www/html/ubuntu/install/netboot/* /var/lib/tftpboot/
5.生成ks.cfg 文件(文件内容见最后)
6.修改部分配置
在命令行root家目录
cp ks.cfg /var/www/html/
vim /var/www/html/ks.cfg #添加安装的软件包
skipx #下面添加需要安装的软件包
%packages
openssh-server
编辑txt.cfg
root@ubuntu-pxe:~# cat /var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg | grep -v "^#" | grep -v "^$" default install label install menu label ^Install menu default kernel ubuntu-installer/amd64/linux append net.ifnames=0 AND biosdevname=0 ks=http://192.168.151.254/ks.cfg vga=788 initrd=ubuntu-installer/amd64/initrd.gz live-installer/net-image=http://192.168.151.254/ubuntu/install/filesystem.squashfs label cli menu label ^Command-line install kernel ubuntu-installer/amd64/linux append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
编辑文件default
root@ubuntu-pxe:~# cat /var/lib/tftpboot/pxelinux.cfg/default | grep -v "^#" | grep -v "^$" path ubuntu-installer/amd64/boot-screens/ include ubuntu-installer/amd64/boot-screens/menu.cfg default ubuntu-installer/amd64/boot-screens/vesamenu.c32 prompt 0 timeout 100
#Generated by Kickstart Configurator #platform=x86 #System language lang en_US #Language modules to install langsupport zh_CN --default=en_US #System keyboard keyboard us #System mouse mouse #System timezone timezone --utc Asia/Shanghai #Root password rootpw --iscrypted $1$Ay.KmnwT$EuOQBV95hYKjITybaKFqW/ #Initial user user web --fullname "web" --iscrypted --password $1$sQNvuINl$UytM7d0Myy1qnE8UtesTl. #Reboot after installation reboot #Use text mode install text #Install OS instead of upgrade install #Use Web installation url --url http://192.168.151.254/ubuntu #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr yes #Partition clearing information clearpart --all --initlabel #Disk partitioning information part /boot --fstype ext4 --size 500 --asprimary part / --fstype ext4 --size 10240 --asprimary part swap --size 4096 --asprimary #System authorization infomation auth --useshadow --enablemd5 #Network information network --bootproto=dhcp --device=eth0 #Firewall configuration firewall --disabled #Do not configure the X Window System skipx %packages openssh-server vim ntp %post IP=$(/sbin/ifconfig |grep 192.168|grep -oP "(?<=inet addr:).*(?= Bcast)") NAME=$(echo $IP|awk -F"." '{print $3$4}') sed -i "/$IP/d" /etc/hosts echo $IP SH$NAME >> /etc/hosts hostname SH$NAME echo SH$NAME >/etc/hostname NET=$(/sbin/ifconfig |grep -o "inet addr:192.168[^ ]*" |awk -F. '{print $3}')
7。 以网络模式启动一台服务器进行装机
过程略。。。