← Back to list

Step-by-Step Guide to Setting Up a PXE Server and Installing Virtual Machines in QEMU/KVM - PART 1

Installing Linux using an ISO is a simple and straightforward process that even beginners can handle with minimal experience. However, the…

Mangilipallylaxminarayana · 2024-12-14 02:02 · 0 claps · 4.1 min read
#kvm #pxe-boot #kvm-qemu #linux #system-administration
Open on Medium ↗
Wiki topics: 🔓 · Open Source

Step-by-Step Guide to Setting Up a PXE Server and Installing Virtual Machines in QEMU/KVM - PART 1

Installing Linux using an ISO is a simple and straightforward process that even beginners can handle with minimal experience. However, the challenge arises when you need to install Linux on multiple machines. Manually carrying a flash drive to each machine, plugging it in, booting from it, and then installing the OS can be time-consuming and inefficient.

This is where a PXE (Preboot Execution Environment) server comes in handy. A PXE server centralizes the necessary files for OS installation, allowing machines to access these files over the network and install the OS without the need for physical media.

In this blog, we’ll walk you through configuring a PXE server and installing virtual machines using this setup. So, grab your coffee and get ready to dive in!

Configuring Fedora Server 40 as a PXE server

In this guide, we’ll configure the PXE server on Fedora Server. The process is similar for Debian and Ubuntu systems, with the main difference being the package names, which you’ll need to adjust accordingly.

To set up a PXE boot environment, several servers are required, each serving a specific purpose:

  • TFTP Server: Responsible for delivering the boot-loader (pxelinux.0) and related configuration files to client machines. It provides the initial files needed to begin the installation process.
  • DHCP Server: Guides client machines to the PXE server and provides critical information, such as the location and name of the network boot program (e.g., pxelinux.0, which we’ll use in this guide).
  • HTTP Server: Used for transferring larger files, such as OS installation images and packages. HTTP is faster and more robust than TFTP, making it ideal for this purpose.

Additionally, it’s essential to configure a static IP address on the PXE server to ensure consistency and reliability in communication with client machines.

Syslinux includes PXELINUX, a boot-loader specifically designed for PXE environments. PXELINUX simplifies the boot process by:

  • Loading configuration files and menus.
  • Supporting flexible boot options and parameters.
  • Managing the hand off from network-based boot to local OS installation or live environments.

We’ll begin by installing the essential packages required for the PXE setup, including dhcp-server, tftp-server, syslinux, and httpd.

sudo dnf install -y tftp-server syslinux dhcp-server httpd

Configuring TFTP Server

After installing the TFTP server, the necessary files, including the network bootloader and other related files, must be copied to the TFTP root directory located at /var/lib/tftpboot/. These files can typically be found in the /usr/share/syslinux/ directory.

Once the files are in place, enable and start the TFTP service to make it operational. Next, create a directory within the TFTP root to store the PXE configuration files, which will define the boot menu and options for the client machines.

sudo cp /usr/share/syslinux/* /var/lib/tftpboot
sudo systemctl enable --now tftp.socket
sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg

Configuring DHCP Server

Next, we need to configure the DHCP server — an essential step in setting up the PXE environment. The DHCP server’s configuration file is located at /etc/dhcp/dhcpd.conf.

In this file, you’ll define a subnet along with the necessary network details, such as the gateway, DNS server, and, most importantly, the static IP address of the PXE server. Additionally, specify the name of the network boot-loader file (e.g., pxelinux.0).

Once you’ve made the required changes to the configuration file, save it and start the DHCP server to apply the settings.

subnet 192.168.122.0 netmask 255.255.255.0 {
    range 192.168.122.25 192.168.122.200;
    option routers 192.168.122.1;
    option domain-name-servers 8.8.8.8;
    default-lease-time 600;
    max-lease-time 7200;

    next-server 192.168.122.10; # IP of PXE server
    filename "pxelinux.0";
}
sudo systemctl enable --now dhcpd

Configuring HTTP Server

The next step is to add the OS installation files to the HTTP server’s root directory, which is at /var/www/html. To do this, first, mount the ISO file containing the OS installation files. Then, copy all the contents of the ISO to a dedicated directory within the HTTP server’s root directory. For example, you can name this directory OS or use a specific name corresponding to the OS if you plan to serve multiple operating systems.

After copying the required files, update the SELinux context of the directory to ensure proper access by the HTTP server. Finally, start the httpd service to make the files accessible to client machines.

sudo mkdir -p /var/www/html/os
sudo mount -o loop /path/to/os.iso /mnt
sudo cp -r /mnt/* /var/www/html/os
sudo umount /mnt
sudo chcon -R -t httpd_sys_content_t /var/www/html/os
sudo systemctl enable --now httpd

Configuring PXE Boot Menu

This is the final step in setting up your PXE server. After completing all the previous steps, it’s time to define the PXE configuration file. This file specifies the PXE boot entries for the operating system(s) you plan to install.

For example, in the **LABEL linux** section of the configuration file, you can define the entry for Fedora Server 41 or any other OS. Additionally, I included configurations for performing the installation via a VNC viewer, using TigerVNC in this case.

With these settings, your PXE server is ready to use. While this example includes only one entry for Fedora Server 41, you can add multiple OS entries by copying their respective files into the web server’s root directory, organizing them into separate folders, and referencing them in the PXE configuration file. This flexibility makes it easy to serve multiple operating systems from the same PXE server.

sudo vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
TIMEOUT 600
MENU TITLE PXE Boot Menu

LABEL linux
    MENU LABEL Install Fedora Server 41
    KERNEL vmlinuz
    APPEND initrd=initrd.img inst.repo=http://192.168.122.10/os inst.stage2=http://192.168.122.10/os inst.vnc inst.vncpassword=mypassword ip=dhcp
sudo cp /var/www/html/os/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot

In this blog, we successfully set up a PXE server by configuring TFTP, DHCP, and HTTP servers, organizing OS files, and defining PXE boot entries. This PXE server is now ready to streamline operating system installations across multiple machines, eliminating the need for physical media.

But we’re not done yet! In my next blog, I’ll guide you through installing virtual machines using the PXE server we’ve created. Stay tuned for the next step in leveraging the full potential of your PXE setup.


메타데이터
post_id
cfb005c8cec4
slug
step-by-step-guide-to-setting-up-a-pxe-server-and-installing-virtual-machines-in-qemu-kvm-part-1-cfb005c8cec4
url
https://medium.com/@mangilipallylaxminarayana/step-by-step-guide-to-setting-up-a-pxe-server-and-installing-virtual-machines-in-qemu-kvm-part-1-cfb005c8cec4
canonical_url
https://medium.com/@mangilipallylaxminarayana/step-by-step-guide-to-setting-up-a-pxe-server-and-installing-virtual-machines-in-qemu-kvm-part-1-cfb005c8cec4
author_url
https://medium.com/@mangilipallylaxminarayana
status
ok
fetched_at
2026-07-14 03:02:02