For a fact, every system administrator always wants to have the easiest and shortest time when managing their environment. For that reason, they are continuously coming up with ways to automate tasks in their environment. This helps eliminate the errors made by manual configurations and also reduces the monotony of repeating the same tasks over and over.
When installing hosts, net booting or PXE booting can be used for automation. Preboot eXexution Environment abbreviated as PXE is a standardized client-sever architecture used to boot, run and instal multiple Operating Systems using the network interface. This technology was introduced back in 1999 by Intel. Ever since this tool has brought a lot of benefits to the IT industry, some of which include:
- No storage is required when installing the operating system
- Simple system maintenance as it can be done remotely
- It is vendor independent which makes it easier to add new client computers and network extension
- Improved information security due to centralised data storage.
In this guide, we will learn how we can automate Debian 12 installation using PXE Boot. Here, we will set up the below components to serve different functions:
- DHCP server: this will provide DNS and DHCP services for the PXE boot
- TFTP server: it is a simple lockstep FTP used to create bootable images to be downloaded over the network
1. Install and Configure DHCP Server
For this guide, we will be working with a Debian-based system as the server/workstation. You need to ensure that you have the DHCP server installed and working.
To install the DHCP server, use:
sudo apt update
sudo apt install isc-dhcp-server
Once installed, export the required variables:
export DHCP_SERVER_INTERFACESv4=ens18
Now create the config for the DHCP server.
sudo sed -e 's/^#DHCPDv4_CONF=/DHCPDv4_CONF=/g' \
-e 's/^#DHCPDv4_PID=/DHCPDv4_PID=/g' \
-e "s/INTERFACESv4=\"\"/INTERFACESv4=\"${DHCP_SERVER_INTERFACESv4}\"/g" \
-i /etc/default/isc-dhcp-server
Also, open the DHCP config file for editing:
sudo vim /etc/dhcp/dhcpd.conf
In the fie, provide the network settings as desired:
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.56 192.168.200.250;
option broadcast-address 192.168.200.255;
option routers 192.168.200.1;
option subnet-mask 255.255.255.0;
option domain-name "mydomain.com";
option domain-name-servers 192.168.200.1;
next-server 192.168.200.56; # our Server/Workstatation
filename "pxelinux.0";
}
In the above config, we have the subnet as 192.168.200.0/24 and the workstation or server for TFTP as 192.168.200.56. Once the config has been created, start and enable the service:
sudo systemctl restart isc-dhcp-server
Check if the service is running:
$ systemctl status isc-dhcp-server
● isc-dhcp-server.service - LSB: DHCP server
Loaded: loaded (/etc/init.d/isc-dhcp-server; generated)
Active: active (running) since Wed 2023-06-28 07:27:37 EDT; 7s ago
Docs: man:systemd-sysv-generator(8)
Process: 175177 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=0/SUCCESS)
Tasks: 1 (limit: 4623)
Memory: 4.4M
CPU: 29ms
CGroup: /system.slice/isc-dhcp-server.service
└─175187 /usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf ens18
2. Install and Configure TFTP Server
The next thing we need to install and configure is the TFTP Server. This can be installed on a Debian-based host using the command:
sudo apt install atftpd -y
Once complete, start and enable the service:
sudo systemctl enable atftpd
sudo systemctl start atftpd
The TFTP will be used to serve the boot files. So we will add the Debian 12 image. First, witch to the TFTP directory:
cd /srv/tftp
Download and extract the image files. Export the variables for the mirror:
export MIRROR=http://ftp.debian.org/debian/dists/bookworm
export ARCH=amd64
export IMAGE_URL=${MIRROR}/main/installer-$ARCH/current/images/netboot/netboot.tar.gz
Now download the extract the boot image for Debian 12
wget -q -O - ${IMAGE_URL} | sudo tar xzf -
3. Configure the PXE Server
We also need to configure the PXE server. First, provide the SYSLinux PXE bootloader config:
cat <<EOF | sudo tee debian-installer/amd64/boot-screens/syslinux.cfg
path debian-installer/$ARCH/boot-screens
include debian-installer/$ARCH/boot-screens/menu.cfg
default debian-installer/$ARCH/boot-screens/vesamenu.c32
prompt 0
timeout 50
EOF
Then proceed and create the boot screen menu. First export the TFTP server IP address:
export SERVER_IPADDR=192.168.200.56
Now create the config:
cat <<EOF | sudo tee debian-installer/amd64/boot-screens/menu.cfg
menu hshift 13
menu width 49
menu margin 8
menu tabmsg
menu title Installer boot menu
label Debian-12-automated-installation
menu label ^Debian 12 automated Installation
kernel debian-installer/amd64/linux
append auto=true priority=critical vga=788 \
initrd=debian-installer/amd64/initrd.gz \
preseed/url=tftp://${SERVER_IPADDR}/preseed/debian-12-preseed.cfg
menu end
EOF
4. Create Configurations for Debian installation
For the Debian 12 installation to be fully automated, we will use the debian-12-preseed.cfg which contains the required variables when running the installation. This includes setting the locales, user passwords, timezone, disk partitioning etc.
Create the file in the pressed directory:
sudo mkdir preseed
Export the required variables:
export PRESEED_LOCALE=en_US
export PRESEED_LANGUAGE=en
export PRESEED_COUNTRY=KE
export PRESEED_KEYMAP=us
export PRESEED_MIRROR=ftp.jp.debian.org
export PRESEED_TIMEZONE=Africa/Nairobi
Create the configuration as shown:
cat <<EOF | sudo tee preseed/debian-12-preseed.cfg
d-i debian-installer/locale string ${PRESEED_LOCALE}
d-i debian-installer/language string ${PRESEED_LANGUAGE}
d-i debian-installer/country string ${PRESEED_COUNTRY}
d-i keyboard-configuration/xkb-keymap select ${PRESEED_KEYMAP}
d-i passwd/user-fullname string
d-i passwd/username string debian
d-i passwd/root-password password Passw0rd
d-i passwd/root-password-again password Passw0rd
d-i passwd/user-password password Passw0rd2
d-i passwd/user-password-again password Passw0rd2
d-i user-setup/allow-password-weak boolean true
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i mirror/country string manual
d-i mirror/http/hostname string ${PRESEED_MIRROR}
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
d-i time/zone string ${PRESEED_TIMEZONE}
d-i partman/confirm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm_nooverwrite boolean true
d-i partman-auto/disk string /dev/[sv]da
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select atomic
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-partitioning/confirm_write_new_label boolean true
d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/[sv]da
d-i pkgsel/update-policy select none
d-i pkgsel/include string task-gnome-desktop openssh-server
d-i finish-install/reboot_in_progress note
EOF
Now the config will be used to automate the Debian 12 to the end without any human interaction. Restart TFTP
sudo systemctl restart atftpd
If you have a firewall enabled, you need to allow TFTP through it:
sudo ufw allow 69/udp
5. Debian 12 Automated Installation
The next thing to do is to create a VM or use a real machine that exists on the same network as the TFTP machine. If it is a VM, create the hard disk and attach a network interface.
You also need to ensure that network boot is enabled and sits just after the hard disk as shown:
Now start the machine and it will download and run the boot image as shown.
The created SYSLinux boot menu should appear as shown:
Select the option and wait for the full installation to happen without any interactions.
Once complete, the machine will reboot as shown:
Login using the created user password and enjoy.
Now you can make post-installation configurations on your Debian 12 system using the guide below:
Verdict
We can all agree that we have automated the Debian 12 installation using PXE Boot. This can be so vital if you have a large environment and you need to have automated system installations. I hope this was of importance to you.
See more:
- Install Virtual Machines on KVM using PXE and Kickstart
- How To Install Docker on Debian 12 (Bookworm)
- Using Docker Compose / Podman Compose on Debian 12 (Bookworm)