Operations 21 min read

Automate OS Installation: Step‑by‑Step PXE & Cobbler Setup Guide

This guide walks through the complete PXE boot process, explains how Cobbler extends PXE with automated DHCP/TFTP management, and provides detailed commands and configuration examples for installing Cobbler, fixing common issues, importing a local ISO, creating kickstart files and profiles, and finally launching a fully automated OS installation.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Automate OS Installation: Step‑by‑Step PXE & Cobbler Setup Guide

The PXE boot workflow starts with a client requesting an IP address from a DHCP server, which supplies the next-server (the TFTP server) and the bootloader filename ( pxelinux.0). The client downloads pxelinux.0, reads the configuration in pxelinux.cfg (usually the default file), obtains the kernel and initrd locations, optionally fetches a kickstart file, and then loads the kernel to begin the OS installation.

Cobbler is a higher‑level tool that automates the same PXE process while also managing DNS, DHCP, TFTP, and rsync services. It stores distributions (distro) and profiles, where a distro represents a complete set of installation files (vmlinuz, initrd, RPMs) and a profile defines how those files are used, including the associated kickstart.

Installation : on a RHEL/CentOS system install the required packages from the EPEL repository:

yum -y install cobbler cobbler-web pykickstart debmirror httpd dhcp

After installation, the /etc/cobbler directory contains configuration files such as settings, dhcp.template, and tftpd.template. Start the services:

systemctl start httpd.service
systemctl start cobblerd.service

Run cobbler check and address the reported items, for example:

Set server and next_server in /etc/cobbler/settings to the real IP (e.g., 172.16.10.10) instead of localhost.

Download missing PXE loaders with cobbler get-loaders or copy pxelinux.0 and menu.c32 from the syslinux package to /var/lib/cobbler/loaders.

Change disable = no in /etc/xinetd.d/rsync and enable the rsync service.

Comment out the dists and arches lines in /etc/debmirror.conf if Debian support is not needed.

Install pykickstart to satisfy the kickstart validator.

Replace the default encrypted password in /etc/cobbler/settings with a new one generated by

openssl passwd -1 -salt $(openssl rand -hex 8) 'your-password'

.

Install fencing tools (e.g., cman or fence-agents) if power‑management features are required.

After fixing the issues, restart Cobbler and sync the configuration:

systemctl restart cobblerd.service
cobbler sync

DHCP/TFTP configuration : if Cobbler is set to manage DHCP ( manage_dhcp: 1) edit /etc/cobbler/dhcp.template; otherwise edit the system /etc/dhcp/dhcpd.conf directly. An example DHCP stanza:

subnet 172.16.10.0 netmask 255.255.255.0 {
    range 172.16.10.20 172.16.10.50;
    option subnet-mask 255.255.255.0;
    next-server 172.16.10.10;   # TFTP server address
    filename "pxelinux.0";      # Bootloader path relative to /var/lib/tftpboot
}

Restart the DHCP daemon after editing: service dhcpd restart Creating a distro from a local ISO : mount the CD/DVD and import it with Cobbler:

mkdir /mnt
mount /dev/cdrom /mnt
cobbler import --name=CentOS7.2 --path=/mnt

The import copies the ISO contents to /var/www/cobbler/images/CentOS7.2‑x86_64 and creates a matching entry under /var/www/cobbler/ks_mirror. Verify the URL http://172.16.10.10/cobbler/ks_mirror/CentOS7.2/ is reachable.

Kickstart file : edit /var/lib/cobbler/kickstarts/CentOS7.2.ks. A minimal example includes language, network, root password (encrypted), partitioning, and post‑install script sections. The file can be referenced by a profile.

#version=DEVEL
install
url --url=http://172.16.10.10/cobbler/ks_mirror/CentOS7.2/
text
firewall --disabled
firstboot --disable
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --hostname=node1.example.com
rootpw --iscrypted $6$random$encryptedhash
selinux --disabled
bootloader --append="quiet crashkernel=auto" --location=mbr --boot-drive=sda
zerombr
clearpart --all --initlabel
part /boot --fstype="xfs" --size=250
part swap --fstype="swap" --size=2000
part / --fstype="xfs" --grow --size=5000
%post
# custom commands, e.g. repo setup, SSH hardening
%end

Profile creation : after the distro import, Cobbler automatically creates a profile. List profiles: cobbler profile list Edit the profile to point to the new kickstart and add kernel options that disable predictable network interface names:

cobbler profile edit --name=CentOS7.2-x86_64 \
    --kickstart=/var/lib/cobbler/kickstarts/CentOS7.2.ks \
    --kopts="net.ifnames=0 biosdevname=0"

Alternatively, add a brand‑new profile:

cobbler profile add --name=CentOS7.2.1-x86_64 \
    --distro=CentOS7.2-x86_64 \
    --kickstart=/var/lib/cobbler/kickstarts/CentOS7.2.ks

Each profile adds a LABEL entry to /var/lib/tftpboot/pxelinux.cfg/default. Example snippet after editing:

LABEL CentOS7.2-x86_64
    kernel /images/CentOS7.2-x86_64/vmlinuz
    MENU LABEL CentOS7.2-x86_64
    append initrd=/images/CentOS7.2-x86_64/initrd.img \
           ksdevice=bootif lang= text \
           net.ifnames=0 biosdevname=0 \
           ks=http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2-x86_64
    ipappend 2

Adjust the menu defaults (e.g., use vesamenu.c32, shorten TIMEOUT to 20 seconds, set ONTIMEOUT to a specific label) to achieve a fully unattended installation.

Running the installation : power on a new machine on the same network; after the DHCP lease it will receive the PXE configuration, load the kernel and initrd, fetch the kickstart, and start the automated install. The system reboots automatically when finished and boots locally.

Key take‑aways : Cobbler provides the same core functionality as raw PXE+Kickstart but adds variable handling, API/GUI management, and automated file distribution, making large‑scale OS provisioning far easier.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AutomationLinuxPXEKickstartDHCPTFTPCobbler
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.