PXE installs Linux automatically

Source: Internet
Author: User
Tags change settings file permissions iptables

About PXE

In many cases it is unrealistic to install the operating system manually, especially when the number is large. It's time to draw on other technologies. PXE is one of them.
The PXE full name is: Preboot excution environment Pre-boot execution environment is a client/server-based network model developed by Intel Corporation that enables remote hosts to download images from remote servers over the network and thereby support booting the operating system over a network PXE can boot and install multiple operating systems such as Windows,linux, which only says Linux does not speak windows.
PXE specific work is somewhat complicated, but more introduction, interested in Baidu can be self-described here only to realize. All of the following are based on virtual machine implementations. vm14,cent7.5

General process

1. Environmental preparedness
2. Check the firewall and SELinux settings to make sure it is turned off
3. Install the necessary packages and open the corresponding service
4. Prepare the installation source
5. Prepare the automatic answer file and place it where it can be accessed.
6. Configure the DHCP service and start
7. Copy the necessary files to the relevant directory
8. Modify the boot menu, as well as some other configuration files
8. Start the test

Installation process Environment preparation

Start by preparing at least two virtual machines, one of which is used as a server. (Basic all configuration operations are on the server where the client machine does not need to be configured.) Also requires at least one installation source (System installation image file)
1. Configure two virtual machine NICs to host-only mode (primarily, and external network isolation, to affect the DHCP service of the physical machine in the face)
2. Turn off VMware's DHCP service
Click on "edit → Virtual network editor" in VMware Main interface
In the Open interface, select only the host type of connection and tick off the following using the local DHCP service (if the check box is gray, click Change settings to give him administrator privileges)

3. Assign an IP address to the server, and the address is proposed as a static address. The configuration file is as follows:

TYPE=EthernetBOOTPROTO=staticIPADDR=192.168.11.2PREFIX=24GATEWAY=192.168.11.1NAME=ens33DEVICE=ens33ONBOOT=yes

4. Edit the virtual network card configuration under win so that it can communicate with the virtual machine
Open Control Panel → network and sharing center → change adapter settings
Typically only the host's connection name is VMnet1

Addresses can be arbitrarily assigned, but make sure the address here is the gateway for the address assigned in the previous step. If you can ping the gateway in the virtual machine, the configuration is not a problem.

Check server-Related settings

Make sure that SELinux and the firewall are turned off.
Change the selinux=xxx in the/etc/selinux/config file to selinux=disabled and restart.
Can be viewed through the command Getenforce, if it is disabled or permissive is off state
Perform the following two commands to make sure the firewall is turned off

systemctl stop firewalldsystemctl disable firewalld以上是Cent7,如果是6的话service iptables stopchkconfig iptables off
Install the necessary software

For convenience, the software installation is all installed using Yum, and if there is no Yum source, configure it yourself.
Execute the following command to install the relevant software and start the service, DHCP is skipped because of the need to modify the configuration file separately

yum install httpd dhcp syslinux tftp-serversystemctl start httpd tftp.socketsystemctl enable dhcpd tftp.socket httpd

Use Ss-tan to confirm that the TCP80 port is turned on
Use SS-UNL to confirm that the UDP69 port is turned on

Preparing the installation Source

In this experiment we use HTTP as the installation source, so we can only attach our prepared installation image to the HTTP directory. The specific directory is/var/www/html/in order to facilitate the extension can also be set up in this directory several folders to store different versions of system files.
Specific implementation:
1. Create a folder using Mkdir-p/VAR/WWW/HTML/CENTOS/7
2. Attach the disc to the/VAR/WWW/HTML/CENTOS/7 directory
3. Add automatic mount information to the/etc/fstab file, typically
/ETC/SR0/VAR/WWW/HTML/CENTOS/7 iso9660 default 0 0
4. Use Df-h to confirm Mount Information
5. On the host using the browser access HTTP://192.168.11.2/CENTOS/7 confirm that you can see the mounted installation files

Prepare the Auto answer file

Auto answer file is a very important part of the whole process (in fact, each part is very important) The automatic answer file can be generated by installing the System-config-kickstart package under the graphical interface, or, The system is installed by default in the root home directory has a file called Anaconda-ks.cfg, you can also directly modify the file. Because the graphical interface is relatively simple, the Anaconda-ks.cfg file is modified directly here. Where the lines beginning with # represent comments, if you have not modified the contents of this file, then the content should be as follows (Chinese is added):
Note: Minimize the contents of the installation file, if it is a graphical interface, the content will be slightly different

#platform =86, AMD64, or Intel em64t#version=devel# System authorization Informationauth--useshadow--passalgo=sha512# I Nstall OS instead of upgrade# Select Upgrade or install, install is installed, upgrade is upgrade install# use CDROM installation media# installation media, here is the place to modify cdrom# Use text mode install# using a graphical installation or text interface, usually automatically installed we do not need graphics text# Firewall configuration# firewall option, usually choose to close Firewall-- Disabledfirstboot--disableignoredisk--only-use=sda# Keyboard layouts# old format:keyboard us# new Format:keyboard--VC Keymap=us--xlayouts= ' # System Languagelang en_US. utf-8# network information# After installation, you can change the onboot to on, or you can specify a hostnamenetwork--bootproto=dhcp--device=ens33 by the way-- Onboot=off--ipv6=auto--no-activatenetwork--hostname=localhost.localdomain# Reboot after installation# installation restart Reboot # root password# root account password, here the password is encrypted after the password ROOTPW--iscrypted $1$hwddpzbi$jcacpj2.qtbrqgnwup8hr1# SELinux configuration# SELinux option SELinux--disabled# System servicesservices--enabled= "chronyd" # do not configure the X Window systemskipx# syste M timezone# Time zone timezoneasia/shanghai# System bootloader configurationbootloader--append= "Crashkernel=auto"--location=mbr--BOOT-DRIVE=SDA #Clear the Master Boot record#zerombr #清除MBR # Partition clearing information#clearpart--all--initlabel # Empty Disk # Disk part Itioning information# The following three lines are partition information, and be careful to modify them according to your own circumstances. Size unit is Mb#part swap--fstype= "swap"--size=2048#part/--fstype= "XFS"--size=20480#part/boot--fstype= "XFS"--size= 1024# the package to be installed @ begins with a package group, no @ is a separate package%packages@corezsh%end%addon com_redhat_kdump--enable--reserve-mb= ' auto '%end

It seems a lot of content, there may be a lot of different, but there is no relationship, many things do not need to understand, need to change the place is not much
Some of the following modifications are possible:
1. Install media to change CDROM to the following content

url --url="http://192.168.11.2/centos/7/"

2. Firewalls and SELinux choose to turn on or off according to your needs
3. If there is no zerombr and Clearpart--all--initlabel, manually add if the previous #, remove
4. Before removing the partition information #
5. Select the package you want to install according to your own needs, minimizing only one core
6. Save the file to a location that can be accessed by HTTP, such as/var/www/html/, to ensure that the file permissions are 644
7. In the host access http://192.168.11.2/anaconda-ks.cfg if you can access it successfully, this step is OK

Modifying an answer file manually sometimes may not be a wise choice, and if you're not sure, using a graphical tool is a better choice.
Note that the answer file and the system to install the corresponding, such as the installation of 6 system please use 6 to generate the answer file

Configuring the DHCP server

By default, the DHCP service is empty after the installation is complete, and therefore the DHCP service must be configured to start, and the DHCP service profile path is:/etc/dhcp/dhcpd.conf, a sample of the format of the configuration file
Network segment: A network segment of addresses that the server can assign, which can specify multiple
Mask: The mask corresponding to the network segment
Default tenancy: The lease of the default IP address in seconds
Maximum Lease period: The client can request a lease, which is used to limit this in seconds
Address pool: The range of IP addresses that the server can allocate in an assignable network segment
DNS: DNS addresses used by clients to obtain from a DHCP server
As in the next example:

# 指定从DHCP服务器获取的DNS地址option domain-name-servers 114.114.114.114# 默认IP地址的租期default-lease-time 600;# 最长租期max-lease-time 7200;# subnet用来指定网段,netmask是掩码subnet 192.168.11.0 netmask 255.255.255.0{    # 使用range指定IP地址池    range 192.168.11.3 192.168.11.124;}

This is sufficient for a DHCP server, but there are two less important options for PXE,
Next-server 192.168.11.2
FileName "pxelinux.0"
Next-server used to specify the location of the TFTP server
FileName is used to specify which file on the TFTP server to access
That is to say, here is the configuration file for our DHCP server.

option domain-name-servers 114.114.114.114default-lease-time 600;max-lease-time 7200;subnet 192.168.11.0 netmask 255.255.255.0{    next-server 192.168.11.2;    filename "pxelinux.0";    range 192.168.11.3 192.168.11.124;}

Next use Systemctl start DHCPD to start the DHCP service, use SS-UNL to see if Port 67 is turned on

Copy related files to the TFTP shared directory

TFTP shared directory under/var/lib/tftpboot/, considering that flexibility can still be given to different versions of the system in separate directories
Create a 7 directory here
Copy the initrd.img and Vmlinuz to the/VAR/LIB/TFTPBOOT/7 directory under Isolinux in the CD directory
Create a folder named Pxelinux.cfg under the shared directory and copy the isolinux.cfg under Isolinux in the disc directory to the PXELINUX.CFG directory and name default
Copy/usr/share/syslinux/menu.c32 to the/var/lib/tftpboot directory, this file is a menu background file
Copy the/usr/share/syslinux/pxelinux.0 to the/var/lib/tftpboot directory
If there is only one system, there should be 5 files two directories, the structure is as follows

[[email protected]_Svr]/var/lib/tftpboot# tree.├── 7│?? ├── initrd.img│?? └── vmlinuz├── menu.c32├── pxelinux.0└── pxelinux.cfg    └── default
One final step

Modify the default file, copied from the CD file has a lot of content, not much we do not need, refer to the following content on it

#就是刚才复制到菜单文件default menu.c32#超时时间,就是菜单倒计时timeout 600display boot.msg# 启动菜单的具体配置# menu label 用来指定菜单名称,可以自定义,^符号用来确定光标位置,# 同时其后的字母也是调到对应菜单的快捷键# kernel指定内核文件路径,由于我们放在了文件夹中所以路径是7/vmlinuz# 指定initrd的路径,以及ks应答文件文件的路径# 务必确保应答文件可以访问label linux  menu label ^Install CentOS 7  kernel 7/vmlinuz  append initrd=7/initrd.img ks=http://192.168.11.2/anaconda-ks.cfg# 本地硬盘启动# menu default表示此项菜单为默认菜单,由于自动安装的风险,建议将本地启动作为默认启动label local  menu default  menu label Boot from ^local drive  localboot 0xffffmenu end
Start test

Another virtual machine NIC is also configured as a host only, and the network card uses the IP for automatic acquisition.
Finally, verify that the installation source and the answer file are accessible, and that the path in the default file is configured correctly.
Verify that the firewall and SELinux are turned off.
Confirm the error, you can start the test. Good LUCK

PXE installs Linux automatically

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.