码迷,mamicode.com
首页 > 其他好文 > 详细

CenOS 7 PXE服务器配置

时间:2018-05-31 02:36:48      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:PXE   UEFI   MBR   

配置流程

1.   安装所需软件包

yum install -y tftp-server httpd syslinux xinetd dhcp*

2.   停止安全策略

systemctl stop firewalld

setenforce 0

 

3.   配置DHCP如下:

ddns-update-style interim;

allow bootp;

allow booting;

 

 

subnet 10.53.0.0 netmask 255.255.0.0 {

option routers 10.53.100.254;

next-server 10.53.100.11;   #该IP为PXE引导程序bootx64.efi或者pxelinux.0所在服务器

option time-offset -18000;

range dynamic-bootp 10.53.100.100 10.53.100.110;#dhcp服务器地址池范围

default-lease-time 21600;

max-lease-time 43200;

filename "mbr/bootx64.efi"; #该文件路径为tftp根目录,引导之后,则已引导文件所在目录为根目录

# filename "mbr/pxelinux.0"; #该文件路径为tftp根目录,引导之后,则已引导文件所在目录为根目录

}

 

其中红色字体为而选一模式,bootx64.efi为UEFI引导方式所需要的引导文件,pxelinux.0为传统BIOS引导方式所需要的引导文件。

 

4.   配置tftp服务器

4.1.  使用如下命令,修改配置tftp配置文件,启用tftp

 

sed -i '/disable/s/yes/no/' /etc/xinetd.d/tftp

 

创建tftpboot目录,来方便配置。

 

mkdir /tftpboot/

 

并配置tftp根目录为新创建的/tftpboot 目录

 

server_args = -s /tftpboot

 

最终tftp配置如下:(标红为修改的位置)

 

[root@7-4-1 tftpboot]# cat /etc/xinetd.d/tftp

# default: off

# description: The tftp server serves files using the trivial file transfer \

# protocol. The tftp protocol is often used to boot diskless \

# workstations, download configuration files to network-aware printers, \

# and to start the installation process for some operating systems.

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot

disable = no

per_source = 11

cps = 100 2

flags = IPv4

}

 

5.   拷贝引导和内核文件,/tftpboot目录最终如下:

 

 

[root@7-4-1 tftpboot]# tree /tftpboot/

/tftpboot/

├── kernel

│   ├── 7.2

│   │   ├── initrd.img

│   │   └── vmlinuz

│   ├── 7.3

│   │   ├── initrd.img

│   │   └── vmlinuz

│   └── 7.4

│   ├── initrd.img

│   └── vmlinuz

├── mbr

│   ├── pxelinux.0

│   ├── pxelinux.cfg

│   │   └── default

│   └── vesamenu.c32

└── uefi

├── bootx64.efi

└── grub.cfg

 

7 directories, 11 files

 

 

其中,kernel mbr uefi目录为使文件结构调理清晰创建的目录,并非必须,三个目录对应文件获取方法如下:

 

u  kernel目录

该目录下对应7.2 7.3 7.4目录下文件 为该centos对应版本镜像中的内核文件,每个版本两个文件路径如下:

注意:/Cent-iso为原版镜像的挂载点,如下皆为如此。

/Cent-iso/isolinux/initrd.img

/Cent-iso/isolinux/vmlinuz

 

 

u  mbr目录:

 

pxelinux.0文件为安装syslinux软件包后生成的文件路径如下:

 

cp /usr/share/syslinux/pxelinux.0 /tftpboot/mbr/

 

pxelinux.cfg目录需要手动创建:

mkdir -p /tftpboot/mbr/pxelinux.cfg

 

vesamenu.c32、default需要从原版镜像获取,镜像中路径如下:

 

default文件对应路径如下:

cp /Cent-iso/isolinux/isolinux.cfg /tftpboot/mbr/pxelinux.cfg/default

 

vesamenu.c32文件为传统BIOS引导菜单所需,路径如下:

 

cp /Cent-iso/isolinux/vesamenu.c32 /tftpboot/mbr/

 

 

u  uefi目录:

 

grub.cfg为复制光盘中的文件即可

 

cp /Cent-isoEFI/BOOT/grub.cfg /tftpboot/uefi/

 

 

bootx64.efi需要grub2-mkstandalone命令来生成,该命令需要软件包名称:

 

yum install -y grub2-efi-modules

 

制作efi引导文件命令如下:

 

 

grub2-mkstandalone -d /usr/lib/grub/x86_64-efi/ -O x86_64-efi --modules="tftp net efinet linux part_gpt efifwsetup" -o bootx64.efi

 

其中-o 后的 bootx64.efi即为我们需要的文件,制作完成后,拷贝至对应路径即可。

 

最后附上grub.cfg和default文件:

 

 

 

default

[root@7-4-1 tftpboot]# cat /tftpboot/mbr/pxelinux.cfg/default

default vesamenu.c32

timeout 600

 

display boot.msg

 

# Clear the screen when exiting the menu, instead of leaving the menu displayed.

# For vesamenu, this means the graphical background is still displayed without

# the menu itself for as long as the screen remains in graphics mode.

menu clear

menu background splash.png

menu title Mr Song's PXE

menu vshift 8

menu rows 18

menu margin 8

#menu hidden

menu helpmsgrow 15

menu tabmsgrow 13

 

# Border Area

menu color border * #00000000 #00000000 none

 

# Selected item

menu color sel 0 #ffffffff #00000000 none

 

# Title bar

menu color title 0 #ff7ba3d0 #00000000 none

 

# Press [Tab] message

menu color tabmsg 0 #ff3a6496 #00000000 none

 

# Unselected menu item

menu color unsel 0 #84b8ffff #00000000 none

 

# Selected hotkey

menu color hotsel 0 #84b8ffff #00000000 none

 

# Unselected hotkey

menu color hotkey 0 #ffffffff #00000000 none

 

# Help text

menu color help 0 #ffffffff #00000000 none

 

# A scrollbar of some type? Not sure.

menu color scrollbar 0 #ffffffff #ff355594 none

 

# Timeout msg

menu color timeout 0 #ffffffff #00000000 none

menu color timeout_msg 0 #ffffffff #00000000 none

 

# Command prompt text

menu color cmdmark 0 #84b8ffff #00000000 none

menu color cmdline 0 #ffffffff #00000000 none

 

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

 

menu tabmsg Press Tab for full configuration options on menu items.

 

menu separator # insert an empty line

menu separator # insert an empty line

 

label linux

menu label ^7.2

kernel ../kernel/7.2/vmlinuz

append initrd=../kernel/7.2/initrd.img inst.stage2=http://10.53.2.200/yum/7.2-yum/ quiet

 

 

label linux

menu label ^7.3

menu default

kernel ../kernel/7.3/vmlinuz

append initrd=../kernel/7.3/initrd.img inst.stage2=http://10.53.2.200/yum/7.3-yum/ quiet

 

 

label linux

menu label ^7.4

kernel ../kernel/7.4/vmlinuz

append initrd=../kernel/7.4/initrd.img inst.stage2=http://10.53.2.200/yum/7.4-yum/ quiet

 

 

 

 

menu separator # insert an empty line

 

# utilities submenu

menu begin ^Troubleshooting

menu title Troubleshooting

 

label vesa

menu indent count 5

menu label Install CentOS 7 in ^basic graphics mode

text help

Try this option out if you're having trouble installing

CentOS 7.

endtext

kernel ../kernel/7.4/vmlinuz

append initrd=../kernel/7.4/initrd.img inst.stage2=http://10.53.2.200/yum/7.4-yum/ xdriver=vesa nomodeset quiet

 

label rescue

menu indent count 5

menu label ^Rescue a CentOS system

text help

If the system will not boot, this lets you access files

and edit config files to try to get it booting again.

endtext

kernel ../kernel/7.4/vmlinuz

append initrd=../kernel/7.4/initrd.img inst.stage2=http://10.53.2.200/yum/7.4-yum/ rescue quiet

 

label memtest

menu label Run a ^memory test

text help

If your system is having issues, a problem with your

system's memory may be the cause. Use this utility to

see if the memory is working correctly.

endtext

kernel memtest

 

menu separator # insert an empty line

 

label local

menu label Boot from ^local drive

localboot 0xffff

 

menu separator # insert an empty line

menu separator # insert an empty line

 

label returntomain

menu label Return to ^main menu

menu exit

 

menu end

 

 

 

 

 

grub.cfg

[root@7-4-1 tftpboot]# cat /tftpboot/uefi/grub.cfg

set default="1"

 

function load_video {

insmod efi_gop

insmod efi_uga

insmod video_bochs

insmod video_cirrus

insmod all_video

}

 

load_video

set gfxpayload=keep

insmod gzio

insmod part_gpt

insmod ext2

 

 

#menu title Mr.Song's PXE

set timeout=60

### END /etc/grub.d/00_header ###

 

search --no-floppy --set=root -l 'CentOS 7 x86_64'

 

 

 

 

### BEGIN /etc/grub.d/10_linux ###

 

 

 

menuentry '7.2' --class fedora --class gnu-linux --class gnu --class os {

linuxefi (tftp)/kernel/7.2/vmlinuz inst.repo=http://10.53.2.200/yum/7.2-yum/ quiet

initrdefi (tftp)/kernel/7.2/initrd.img

}

 

 

menuentry '7.3' --class fedora --class gnu-linux --class gnu --class os {

linuxefi (tftp)/kernel/7.3/vmlinuz inst.repo=http://10.53.2.200/yum/7.3-yum/ quiet

initrdefi (tftp)/kernel/7.3/initrd.img

}

 

menuentry '7.4' --class fedora --class gnu-linux --class gnu --class os {

linuxefi (tftp)/kernel/7.4/vmlinuz inst.repo=http://10.53.2.200/yum/7.4-yum/ quiet

initrdefi (tftp)/kernel/7.4/initrd.img

}

submenu 'Troubleshooting -->' {

menuentry 'Install CentOS 7 in basic graphics mode' --class fedora --class gnu-linux --class gnu --class os {

linuxefi (tftp)/kernel/7.4/vmlinuz inst.stage2=http://10.53.2.200/yum/7.4-yum/ xdriver=vesa nomodeset quiet

initrdefi (tftp)/kernel/7.4/initrd.img

}

menuentry 'Rescue a CentOS system' --class fedora --class gnu-linux --class gnu --class os {

linuxefi (tftp)/kernel/7.4/vmlinuz inst.stage2=http://10.53.2.200/yum/7.4-yum/ rescue quiet

initrdefi (tftp)/kernel/7.4/initrd.img

}

}

 

 

注意:如上配置文件中,使用了其他服务器上的http镜像源来作为系统镜像源,实际可以使用本机输出nfs、ftp、http等作为安装源。

 

 

另外,由于能力有限,目前无法找到解决自动判断引导模式为UEFI或者传统BIOS模式,故只能其中的使用一种模式,即

finme bootx64.efi   ->   UEFI

或者

finme bootx64.efi   ->   传统BIOS

希望大家不吝赐教。

 


CenOS 7 PXE服务器配置

标签:PXE   UEFI   MBR   

原文地址:http://blog.51cto.com/8460152/2122236

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!