1, PXE introduction
1.1 PXE introduction
PXE (pre boot execution environment) is the latest technology developed by Intel. It works in the network mode of Client/Server, supports workstations to download images from remote servers through the network, and thus supports the startup process of operating systems from the network.
1.2 PXE working principle
PXE client is the computer where os needs to be installed. TFTP Server, DHCP Server and HTTP server are deployed on the PXE Server side. Bootstrap files, configuration files and Linux root file system are placed in the root directory of TFTP Server on Linux Server, and iso and automatic deployment are placed in HTTP server
1.3 PXE requirements
- pxe client must support PXE function and select network startup when starting up, so that the system can enter PXE startup program in the form of network (network card supporting PXE + BIOS implementing PXE)
- pxe server must provide at least DHCP and TFTP services
- The server using one of NFS/HTTP/FTP provides communication protocols such as programs and software sources required by pxe client
2, Workflow and environment
2.1.1 introduction to installation environment
Ubuntu 20.04 Server supports pxe automatic deployment with cloud init configuration. This paper mainly introduces how to build a deployment environment for automatically installing Ubuntu 20.04 Server on Ubuntu 20.04 desktop
2.1.2 introduction to DHCP, TFTP and HTTP
- Introduction to DHCP
Dynamic Host Configuration Protocol (DHCP) is a communication protocol that enables network administrators to centrally manage and automatically assign IP network addresses. It works with UDP protocol. DHCP uses a unified port as BOOTP: 67/udp for the server and 68/udp for the client. It is mainly used for internal network or network service providers to automatically assign IP addresses to users; It is used by the internal network administrator as a means of central management of all computers.
- Introduction to TFTP
TFTP (triple file transfer protocol) is a simple protocol used to transfer files. It runs on UDP (User Datagram Protocol) and is a simplified version of FTP. TFTP is designed to be small, simple and easy to run. Therefore, it lacks many features of the standard FTP protocol. TFTP can only read and write files (mail) from the remote server or transfer read and write files to the remote server. It cannot list directories and currently does not provide user authentication.
- http introduction
HTTP protocol is the abbreviation of Hyper Text Transfer Protocol, which is used to transfer hypertext from the world wide web server to the local browser.. HTTP is a communication protocol based on TCP/IP to transfer data (HTML files, picture files, query results, etc.).
2.1.3 PXE process
3, Operation process
3.1 install server side software
- Install DHCP and TFTP servers
dnsmasq implements DHCP, TFTP and DNS servers at the same time
sudo apt-get install dnsmasq
During installation, you will see some errors and warnings. At this stage, this is an expected behavior. Additional configuration is required later
- Install HTTP server
apache originally referred to the http server program and later became the organization name of the program, so the original program name was set as httpd, which was also called apache 2 after version 2.0. apache 2 is one of the most popular Web server software
sudo apt-get install apache2
3.2 download startup file
- The client BIOS I use only supports UEFI
Download uefi boot file and boot program loaded by shim.signed and grub-efi-amd64-signed security boot chain
sudo apt-get download shim.signed sudo apt-get download grub-efi-amd64-signed
And extract the content into its private folders (shim and grub). pxeboot uefi client needs these files
Extract with dpkg -x
Download the leakcy boot file (BIOS here only supports UEFI, so it is ignored)
wget https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.zip
- Download ubuntu 20.04 server iso
Download address
3.3 configuring dnsmasq
Use ifconfig to confirm the network card interface
Reconfigure dnsmsq.conf
- Configure DHCP address segment
- Configure boot file directory
- Configure tftp root directory
- Configure log path
- Configure the service network card. Pay attention to multi network card machines
sudo vim /etc/dnsmasq.conf
#Interface information #--Using ip addr to view the system network interface ## Specifies the network card for the service interface=enp7s0,lo # Binding port bind-interfaces domain=c-nergy.local #-------------------------- #DHCP Settings #-------------------------- #-- Set dhcp scope dhcp-range=192.168.1.100,192.168.1.240,255.255.255.0,12h #--The specified gateway address has nothing to do with installation and should not be configured dhcp-option=3,192.168.1.1 #--The specified DNS server address has nothing to do with installation and should not be configured #dhcp-option=6,114.114.114.114 #--Configure external DNS server address #server=114.114.114.114 #----------------------# # Specify TFTP Options # #----------------------# #--Sets the path of the bootstrap relative to the tftp root directory #dhcp-boot=/bios/pxelinux.0,pxeserver,192.168.1.10 #--Open tftp service enable-tftp #--Set tftp root path tftp-root=/tftp #--Detect the schema and send the correct boot loader file dhcp-match=set:efi-x86_64,option:client-arch,7 dhcp-boot=tag:efi-x86_64,grub/bootx64.efi
service dnsmasq restart service dnsmasq status
3.4 configuring HTTP
The default service root directory of Apache 2 is / var/www/html
First, mount a good iso file
mkdir /var/www/html/server mkdir /var/www/html/server/ubuntu2004 mkdir /var/www/html/iso cp ubuntu-20.04.3-live-server-amd64.iso /var/www/html/iso/ mount ubuntu-20.04.3-live-server-amd64.iso /mnt/ cp /mnt/* -r /var/www/html/server/ubuntu2004/ mkdir /var/www/html/autoinstall touch /var/www/html/autoinstall/user-data touch /var/www/html/autoinstall/meta-data chmod -R 777 /var/www/html/
- The autoinstall directory stores parameter automatic configuration files. User data and meta data are the file names required by cloud init. Meta data does not need to be modified. The user data description configuration is as follows
- The iso directory stores the operating system image files
Configure user data
vim /var/www/html/autoinstall/user-data
#cloud-config autoinstall: version: 1 # Modify apt service address apt: primary: - arches: [default] uri: https://mirrors.tuna.tsinghua.edu.cn/ubuntu user-data: # Configure time zone timezone: Asia/Shanghai # To enable the root account disable_root: true # Configure user identity: hostname: ubuntu-server password: "123123" username: ubuntu # configure keyboard keyboard: {layout: us, variant: ''} locale: en_US.UTF-8 # Configure agent # proxy: http://192.168.1.112:3128 # ssh server is installed by default ssh: install-server: true # Specify the package to install packages: # - net-tools # - python3-pip # Configure disk partitions storage: grub: reorder_uefi: False config: - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: false, type: disk, id: disk-sda} - {device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1, preserve: false, grub_device: true, type: partition, id: partition-0} - {fstype: fat32, volume: partition-0, preserve: false, type: format, id: format-0} - {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 2, preserve: false, type: partition, id: partition-1} - {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-1} - {device: format-1, path: /, type: mount, id: mount-1} - {device: format-0, path: /boot/efi, type: mount, id: mount-0}
3.5 configuring TFTP
mkdir /tftp mkdir /tftp/boot mkdir /tftp/boot/live-server mkdir /tftp/grub
See #2.1.4 the uefi boot file we downloaded, using
dpkg -x decompression
dpkg -x grub-efi-amd64-signed_1.167.2+2.04-1ubuntu44.2_amd64.deb grub dpkg -x shim-signed_1.40.7+15.4-0ubuntu9_amd64.deb shim cp grub/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed /tftp/boot/live-server/grubx64.efi cp shim/usr/lib/shim/shimx64.efi.signed /tftp/grub/bootx64.efi
Copy kernel image file
cp /var/www/html/server/ubuntu2004/casper/vmlinuz /tftp/boot/live-server/ cp /var/www/html/server/ubuntu2004/casper/initrd /tftp/boot/live-server/
Copy grub files
cp /var/www/html/server/ubuntu2004/boot/grub/font.pf2 /tftp/grub/ cp /var/www/html/server/ubuntu2004/boot/grub/grub.cfg /tftp/grub/ chmod -R 777 /tftp/
Configure grub
if loadfont /grub/font.pf2 ; then set gfxmode=auto insmod efi_gop insmod efi_uga insmod gfxterm terminal_output gfxterm fi set menu_color_normal=white/black set menu_color_highlight=black/light-gray set timeout=5 menuentry "Autoinstall Ubuntu 20.04 Server" { set gfxpayload=keep linux /boot/live-server/vmlinuz root=/dev/ram0 ramdisk_size=1500000 ip=dhcp url='http://192.168.1.10/iso/ubuntu-20.04.3-live-server-amd64.iso' autoinstall ds=nocloud-net\;s=http://192.168.1.10/autoinstall/ --- initrd /boot/live-server/initrd }
root=/dev/ram0 ramdisk_size=1500000 to specify the kernel image mounting space, whether it can be deleted remains to be confirmed
ip=dhcp specifies that DHCP is used to obtain the IP address after the kernel image is mounted
url = specify the network storage path of ISO files
‘autoinstall ds=nocloud-net;s=http://192.168.1.9/autoinstall/ - 'this parameter is automatically filled in and indicates the path where the configuration file is located
3.6 server side network settings
3.6.1 setting server static ip
Right side of the top bar - > Expand wired connection - > select wired settings
perhaps
Edit / etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: enp7s0: dhcp4: yes dhcp6: no addresses: [192.168.1.10/24] gateway4: 192.168.1.1 nameservers: addresses: [114.114.114.114]
3.3.2 turn off the firewall
Use ufw disable to turn off the firewall and ufw status to check whether the shutdown status is OK
sudo ufw disable The firewall is automatically disabled when the system starts sudo ufw status View status sudo ufw enable Turn on the firewall to allow access to specific ports
3.8 conduct PXE
Set the corresponding network port of the client end to DHCP, and select the network startup of the corresponding network port
The server uses service dnsmasq status to view the interaction status
The results are as follows:
Reference:
https://segmentfault.com/a/1190000040527863
https://c-nergy.be/blog/?p=15664