PXE安装操作系统

Posted 不懂123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PXE安装操作系统相关的知识,希望对你有一定的参考价值。

TFTP服务

     用PXE安装操作系统依赖于DHCP服务和TFTP服务

     网卡一般都内置的TFTP客户端的程序

     systemctl enable tftp     systemctl enable  dhcpd

 1 [root@centos7 dhcp]# yum install tftp-server
 2 [root@centos7 dhcp]# rpm -ql tftp-server
 3 /etc/xinetd.d/tftp
 4 /usr/lib/systemd/system/tftp.service
 5 /usr/lib/systemd/system/tftp.socket
 6 /usr/sbin/in.tftpd
 7 /usr/share/doc/tftp-server-5.2
 8 /usr/share/doc/tftp-server-5.2/CHANGES
 9 /usr/share/doc/tftp-server-5.2/README
10 /usr/share/doc/tftp-server-5.2/README.security
11 /usr/share/man/man8/in.tftpd.8.gz
12 /usr/share/man/man8/tftpd.8.gz
13 /var/lib/tftpboot
14 #安装客户端
15 [root@yxh6 ~]# yum install tftp
16 [root@yxh6 ~]# tftp 192.168.231.7
17 tftp> get file   
18 #file存在服务端的/var/lib/tftpboot目录下
TFTP配置

 

搭建PXE服务器

[root@centos7 html]#yum install httpd
[root@centos7 html]# systemctl start httpd
[root@centos7 html]# vi /etc/fstab
/dev/sr0             /var/www/html/centos7          iso9660       defautls 0   0
[root@centos7 html]# mount -a
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 html]# mkdir ksdir{6,7}
[root@centos7 html]# ls
centos6  centos7  ksdir6  ksdir7
[root@centos7 html]# cp /root/anaconda-ks.cfg ksdir7/ks7_desktop.cfg
[root@centos7 html]# cd ksdir7
[root@centos7 ksdir7]# ls
ks7_desktop.cfg
[root@centos7 ksdir7]# ll
total 4
-rw------- 1 root root 1737 May 27 00:06 ks7_desktop.cfg
[root@centos7 ksdir7]# chmod 644 ks7_desktop.cfg 
[root@centos7 ksdir7]# ll
total 4
-rw-r--r-- 1 root root 1737 May 27 00:06 ks7_desktop.cfg
准备yum源和ks文件
[root@centos7 dhcp]# vi dhcpd.conf 
#配置和自动安装系统相关的配置

subnet 192.168.231.0 netmask 255.255.255.224 {
  range 192.168.231.10 192.168.231.20;
  option routers 192.168.231.254;
  next-server 192.168.231.7;
  filename "pxelinux.0";
}

[root@centos7 dhcp]# systemctl restart dhcpd.service
[root@centos7 dhcp]# systemctl enable dhcpd httpd
配置DHCP
 1 [root@centos7 dhcp]# yum install  tftp-server syslinux
 2 [root@centos7 dhcp]# cd /var/lib/tftpboot
 3 [root@centos7 tftpboot]# mkdir pxelinux.cfg/
 4 #pxelinux.0 文件来自于 syslinux软件包,必须先安装syslinux
 5 [root@centos7 tftpboot]# cp /usr/share/syslinux/pxelinux.0  .
 6 [root@centos7 tftpboot]# cp /var/www/html/centos7/isolinux/{vmlinuz,initrd.img,vesamenu.c32} /var/lib/tftpboot/
 7 [root@centos7 tftpboot]#cp /var/www/html/centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
 8 [root@centos7 pxelinux.cfg]# vi default 
 9 label linux
10   menu label ^Install Desktop7
11   kernel vmlinuz
12   append initrd=initrd.img ks=http://192.168.231.7/ksdir7/ks7_desktop.cfg
13 [root@centos7 pxelinux.cfg]#systemctl enable tftp.socket
14 [root@centos7 pxelinux.cfg]#systemctl start  tftp
配置TFTP
 1 #version=DEVEL
 2 # System authorization information
 3 auth --enableshadow --passalgo=sha512
 4 # Use CDROM installation media
 5 url --url=http://192.168.231.7/centos7
 6 # Use graphical install
 7 #graphical
 8 text
 9 # Run the Setup Agent on first boot
10 firstboot --enable
11 ignoredisk --only-use=sda
12 # Keyboard layouts
13 keyboard --vckeymap=us --xlayouts=\'us\'
14 # System language
15 lang en_US.UTF-8
16 reboot
17 # Network information
18 network  --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --no-activate
19 network  --hostname=centosmy7.localdomain
20 
21 # Root password
22 rootpw --iscrypted $6$RzUIKaLkncGUm9SL$FtuXzR8IpSz2OEQp.LlDrDH1O62SMrZ/Gj06iTSNqlxWma/aHf21lpikhNln6UgNyuL/HqGUrM45feTBkMC1T0
23 # System services
24 services --disabled="chronyd"
25 # System timezone
26 timezone Asia/Shanghai --isUtc --nontp
27 # X Window System configuration information
28 xconfig  --startxonboot
29 # System bootloader configuration
30 bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
31 zerombr
32 # Partition clearing information
33 clearpart --none --initlabel
34 # Disk partitioning information
35 part swap --fstype="swap" --ondisk=sda --size=2048
36 part / --fstype="xfs" --ondisk=sda --size=51200
37 part /data --fstype="xfs" --ondisk=sda --size=30720
38 part /boot --fstype="xfs" --ondisk=sda --size=1024
39 
40 %packages
41 @base
42 @core
43 @dial-up
44 @fonts
45 @guest-agents
46 @print-client
47 @x11
48 kexec-tools
49 
50 %end
51 
52 %addon com_redhat_kdump --enable --reserve-mb=\'auto\'
53 
54 %end
55 
56 %anaconda
57 pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
58 pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
59 pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
60 %end
61 
62 %post
63  systemctl disable initial-setup.service
64  systemctl  disable  initial-setup-graphical.service
65  systemctl set-default multi-user.target
66  mkdir -p /root/oscreate
67  useradd laozijiadeuser
68 %end
ks文件示例

 

 新创建一个虚拟机,把网卡的网段设置成和服务器为同一个网段,启动机器出现下图

 

PXE安装多个版本的系统

    安装不同版本的操作系统,需要分别拷贝对应的内核文件和ks文件,不能混合使用

mkdir /var/lib/tftpboot/pxelinux.cfg/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/centos{6,7}

cp  /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/
cp  /var/www/html/centos/6/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/


cp /var/www/html/centos/7/isolinux/isolinux.cfg  /var/lib/tftpboot/pxelinux.cfg/default
vim /var/lib/tftpboot/pxelinux.cfg/default

cat /var/lib/tftpboot/pxelinux.cfg/default 

cat /var/lib/tftpboot/pxelinux.cfg/default 
default menu.c32
timeout 600

menu title www.yxh.com

label centos7
  menu label ^Install  Desktop CentOS  7
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img ks=http://192.168.30.17/ksdir/ks7_desktop.cfg

label centos6
  menu label install ^Mini CentOS 6
  menu default
  kernel centos6/vmlinuz
  append initrd=centos6/initrd.img ks=http://192.168.30.17/ksdir/ks6_mini.cfg
label local
  menu label Boot from ^local drive
  localboot 0xffff
menu end
代码示例
 1 tree /var/lib/tftpboot/
 2 /var/lib/tftpboot/
 3 ├── centos6
 4 │├── initrd.img
 5 │└── vmlinuz
 6 ├── centos7
 7 │├── initrd.img
 8 │ └── vmlinuz
 9 ├── menu.c32
10 ├── pxelinux.0
11 └── pxelinux.cfg
12     └── default
文件结构目录

 

Linux配置服务的一般步骤

1.检查防火墙和selinux
2.安装包
3.启动服务
4.检查服务是否成功启动
5.在客户端执行命令测试
6.每个服务都有自己的工作主目录

  

以上是关于PXE安装操作系统的主要内容,如果未能解决你的问题,请参考以下文章

PXE自动安装Linux 系统

PXE远程安装服务

ubuntu16 kickstart pxe 安装系统

CentOS使用PXE网络启动自动安装操作系统

PXE自动安装Linux系统

pxe安装介绍