首页 > 代码库 > PXE装机
PXE装机
环境:宿主机:centos 7
KVM 虚拟机 rhel7.2
1.搭建yum 仓库
真机:
[root@room4pc09 桌面]# mkdir /var/www/html/dvd
[root@room4pc09 桌面]# mount /ISO/rhel-server-7.2-x86_64-dvd.iso /var/www/html/dvd/
mount: /dev/loop1 写保护,将以只读方式挂载
PXE服务器:
[root@PXE Server ~]# rm -rf/etc/yum.repos.d/*
[root@PXE Server ~]# yum-config-manager--add http://192.168.4.254/dvd
[root@PXE Server ~]# echo gpgcheck=0>> /etc/yum.repos.d/192.168.4.254_dvd.repo
[root@PXE Server ~]# yum clean all
[root@PXE Server ~]# yum repolist
2.配置dhcp服务,建立dhcp地址池
[root@PXE Server ~]# yum -y install dhcp
验证dhcp能够自动获取ip
新开一台虚拟机client
设置ip地址为 192.168.4.207/24,确保能和PXE服务器能够ping通
虚拟机client里面设置ip地址并开启
[root@client ~]# nmcli connection modify eth0 ipv4.methodmanual ipv4.addresses 192.168.4.207/24
[root@client ~]# nmcli connection up eth0
真机远程登录虚拟机client
[root@room4pc09 桌面]# ssh -X root@192.168.4.207
[root@localhost ~]# dhclient -d eth0
Internet Systems Consortium DHCP Client4.2.5
Copyright 2004-2013 Internet SystemsConsortium.
All rights reserved.
For info, please visithttps://www.isc.org/software/dhcp/
Listening on LPF/eth0/54:52:04:09:07:01
Sending on LPF/eth0/54:52:04:09:07:01
Sending on Socket/fallback
DHCPREQUEST on eth0 to 255.255.255.255 port67 (xid=0x4b10147)
DHCPACK from 192.168.4.7(xid=0x4b10147) ---------------------------------DHCP服务器ip地址是192.168.4.7
bound to 192.168.4.20 -- renewal in 20937seconds.------------------dhcp自动获取ip地址从192.168.4.20开始,表示dhcp配置成功
3. tftp设置引导文件
[root@PXE Server ~]# yum -y installtftp-server
[root@PXE Server ~]# systemctl restart tftp
[root@PXE Server ~]# yum provides*/pxelinux.0
已加载插件:langpacks,product-id, search-disabled-repos, subscription-manager
This system is not registered to Red HatSubscription Management. You can use subscription-manager to register.
192.168.4.254_dvd/filelists_db | 3.2 MB 00:00
syslinux-4.05-12.el7.x86_64 : Simple kernelloader which boots from a FAT
: filesystem
源 :192.168.4.254_dvd
匹配来源:
文件名 :/usr/share/syslinux/pxelinux.0
[root@PXE Server ~]# yum -y installsyslinux
[root@PXE Server ~]# rpm -ql syslinux |greppxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@PXE Server ~]# cp/usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@PXE Server ~]# ls /var/lib/tftpboot/
pxelinux.0
提供启动内核和启动的驱动(从光盘文件中复制过来)-------------需要读取光盘-----------将光盘挂载-----------本地读写操作
1.打开KVM 虚拟系统管理器,双击 PXEServer
2.点击灯泡
3. 设置IDE CDROM 1 的镜像为 rhel7 镜像
4.挂载
[root@PXE Server ~]# rm -rf /mnt/*
[root@PXE Server ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@PXE Server ~]# ls /mnt/
addons images Packages RPM-GPG-KEY-redhat-release
EFI isolinux release-notes TRANS.TBL
EULA LiveOS repodata
GPL media.repo RPM-GPG-KEY-redhat-beta
[root@PXE Server ~]# cp/mnt/isolinux/vmlinuz /var/lib/tftpboot/
[root@PXE Server ~]# cp/mnt/isolinux/initrd.img /var/lib/tftpboot/
[root@PXE Server ~]# ls /var/lib/tftpboot/
initrd.img pxelinux.0 vmlinuz
5. 配置引导菜单
真机上传图片到PXE 服务器
[root@room4pc09 ftp]# scp -r /root/桌面/tupian/ root@192.168.4.7:/var/lib/tftpboot
QQ图片20170412113810.jpg 100% 80KB 80.3KB/s 00:00
QQ图片20170412113822.jpg 100% 24KB 23.5KB/s 00:00
QQ图片20170412113831.jpg 100% 33KB 33.0KB/s 00:00
PXE 服务器查看是否上传成功
[root@PXE Server ~]# ls /var/lib/tftpboot/
initrd.img pxelinux.0 pxelinux.cfg tupian vesamenu.c32 vmlinuz
PXE服务器上操作
将cdrom设置为rhel6 镜像
6.挂载
[root@PXE Server ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@PXE Server ~]# mkdir/var/lib/tftpboot/pxelinux.cfg
[root@PXE Server ~]# cp /mnt/isolinux/isolinux.cfg/var/lib/tftpboot/pxelinux.cfg/default
[root@PXE Server ~]# ls -l/var/lib/tftpboot/pxelinux.cfg/default
-r--r--r--. 1 root root 941 4月 17 04:57/var/lib/tftpboot/pxelinux.cfg/default
[root@PXE Server ~]# chmod 644/var/lib/tftpboot/pxelinux.cfg/default
[root@PXE Server ~]# ll /var/lib/tftpboot/pxelinux.cfg/default
-rw-r--r--. 1 root root 941 4月 17 04:57/var/lib/tftpboot/pxelinux.cfg/default
[root@PXE Server ~]# vim/var/lib/tftpboot/pxelinux.cfg/default
menu background tupian/QQ图片20170412113810.jpg
menu title Welcome to PXE Server!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menulabel ^Install RHEL7
kernelvmlinuz
appendinitrd=initrd.img
label local
menulabel Boot from ^local drive
menu default
localboot0xffff
真机上
[root@room4pc09 桌面]# system-config-kickstart ------------- 运行无人值守安装程序
这里无法显示软件包,问题的根源在yum包的名字未更改成development,只有development才会被kickstart认识
[root@room4pc09 桌面]# vim /etc/yum.repos.d/mnt_.repo
[development]
name=added from: file:///mnt/
baseurl=file:///mnt/
enabled=1
gpgcheck=0
再次运行 system-config-kickstart,显示软件包
yum仓库名称改为development,软件包显示,开始选择软件包
系统-基本
桌面-GNOME,X 窗口系统,字体,输入法
保存到 /root/ks.cfg
PXE服务器上
[root@PXE Server ~]# yum -y install vsftpd
[root@PXE Server ftp]# mkdir /var/ftp/rhel7
[root@PXE Server ftp]# mount /dev/cdrom/mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@PXE Server ~]# cd /var/ftp/
[root@PXE Server ftp]# cp -pr /mnt/*/var/ftp/rhel7/
真机上上传ks.cfg 到/var/ftp
[root@room4pc09 桌面]# scp /root/ks.cfg root@192.168.4.7:/var/ftp/
ks.cfg 100% 688 0.7KB/s 00:00
PXE服务器上查看是否上传成功
[root@PXE Server ~]# ls /var/ftp/
ks.cfg pub rhel7
[root@PXE Server ~]# cd /var/ftp/
[root@PXE Server ftp]# systemctl restartdhcpd
[root@PXE Server ftp]# systemctl restarttftp
[root@PXE Server ftp]# systemctl restartvsftpd
验证:打开 KVM重新建立一台虚拟机,选择PXE安装,查看是否能够执行成功
本文出自 “12903162” 博客,请务必保留此出处http://12913162.blog.51cto.com/12903162/1941108
PXE装机