ubuntu16 kickstart pxe 安裝系統
阿新 • • 發佈:2018-06-11
ubuntu 安裝PXE服務器環境
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
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
- 安裝tftp服務
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
4.拷貝及修改所需文件
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
接下來就可以安裝系統了
ks.cfg 文件內容:
#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。 以網絡模式啟動一臺服務器進行裝機
過程略。。。
ubuntu16 kickstart pxe 安裝系統