Integrating Ubuntu Cobbler with a DHCP Server for Automated OS Deployment
Cobbler simplifies network-based OS installations by automating PXE boot, kickstart file distribution, and package management. When paired with a DHCP server, it eliminates manual IP assignment—allowing clients to automatically retrieve network settings and initiate installations. Below is a structured guide to configuring this integration on Ubuntu.
1. Prerequisites
Before starting, ensure your Ubuntu server has:
- A static IP address (e.g.,
192.168.1.2). - Internet access to download Cobbler and OS images.
- Basic familiarity with command-line tools (e.g.,
apt,nano).
2. Install Cobbler and Dependencies
Update your package list and install Cobbler along with required components (DHCP server, TFTP server, and xinetd for TFTP management):
sudo apt update
sudo apt install cobbler cobbler-web isc-dhcp-server tftpd-hpa xinetd -y
This installs Cobbler (the core tool), ISC DHCP (for IP allocation), TFTP (for boot files), and xinetd (to manage TFTP as a service).
3. Configure Cobbler’s Core Settings
Edit Cobbler’s main configuration file to define its network identity and enable DHCP/TFTP management:
sudo nano /etc/cobbler/settings
Update the following key parameters:
server: Set to your Cobbler server’s static IP (e.g.,192.168.1.2). This tells clients where to find Cobbler’s files.next_server: Also set to your Cobbler server’s IP (same asserver). This points clients to the TFTP server for boot files.manage_dhcp: Set to1to allow Cobbler to generate and manage the DHCP configuration file (avoids manual edits).default_password_crypted: Generate a default root password for installed systems usingopenssl passwd -1(e.g.,$1$rLza5zNH$xLKFqWoK32/IA/zslG3Up0) and paste it here.
Save and exit the file.
4. Configure the DHCP Template
Cobbler uses a template to generate the DHCP configuration file. Edit the template to define your network’s IP range, gateway, DNS, and PXE boot settings:
sudo nano /etc/cobbler/dhcp.template
Add/modify the following block (customize values for your network):
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.100 192.168.1.200; # IP range for clients
option routers 192.168.1.1; # Gateway
option domain-name-servers 8.8.8.8, 8.8.4.4; # DNS servers
filename "pxelinux.0"; # Boot file for PXE
next-server $next_server; # Cobbler server (from settings)
default-lease-time 21600; # 6-hour lease
max-lease-time 43200; # 12-hour max lease
}
Key notes:
- Replace
192.168.1.0/24with your subnet. - Ensure
next-serveruses$next_server(a Cobbler variable that auto-replaces with thenext_servervalue from/etc/cobbler/settings).
5. Configure TFTP for PXE Boot
TFTP serves the initial boot files (e.g., pxelinux.0) to clients. Edit the TFTP configuration file to enable the service and set the root directory:
sudo nano /etc/xinetd.d/tftp
Modify the service tftp section to enable TFTP and specify the root directory (where Cobbler stores boot files):
service tftp
{
disable = no # Enable TFTP
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot # Root directory for TFTP files
per_source = 11
cps = 100 2
flags = IPv4
}
Save and exit.
6. Synchronize Cobbler Configuration
After making changes, run cobbler sync to apply them. This command:
- Generates the DHCP configuration file from the template (
/etc/cobbler/dhcp.template). - Copies boot files (e.g.,
pxelinux.0) to the TFTP root directory (/var/lib/tftpboot). - Restarts related services (Cobbler, DHCP, TFTP) to apply changes.
Run the command:
sudo cobbler sync
7. Restart Network Services
Restart the DHCP and TFTP services to load the new configurations:
sudo systemctl restart isc-dhcp-server
sudo systemctl restart xinetd
Enable them to start on boot (optional but recommended):
sudo systemctl enable isc-dhcp-server
sudo systemctl enable xinetd
8. Verify DHCP and Cobbler Setup
Check DHCP Service Status
Ensure the DHCP service is running without errors:
sudo systemctl status isc-dhcp-server
Look for “active (running)” in the output.
Test DHCP IP Allocation
On a client machine connected to the same network, release and renew its IP address to verify it receives an IP from Cobbler’s range:
sudo dhclient -r eth0 # Release current IP
sudo dhclient eth0 # Request new IP
ip a # Check assigned IP (should be in 192.168.1.100-200 range)
Validate PXE Boot
Set the client to boot from the network (via BIOS/UEFI: prioritize “Network Boot” or “PXE”). If configured correctly, the client should:
- Receive an IP from the DHCP server.
- Download the
pxelinux.0boot file from the Cobbler server (TFTP). - Display a Cobbler boot menu (if kickstart files are configured).
9. Optional: Import an OS Image and Create a Kickstart File
To automate OS installation (e.g., Ubuntu Server), import an OS image and create a kickstart file:
Import an OS Image
Download an Ubuntu ISO (e.g., ubuntu-22.04-live-server-amd64.iso) and place it in /tmp. Import it into Cobbler:
sudo cobbler import --path /tmp/ubuntu-22.04-live-server-amd64.iso --name ubuntu-22.04
This creates a “distro” (OS distribution) in Cobbler.
Create a Kickstart File
Generate a default kickstart file (for automated installation):
sudo cobbler profile edit --name ubuntu-22.04 --kickstart /var/lib/cobbler/kickstarts/ubuntu-22.04.seed
Customize the kickstart file (e.g., partitioning, user creation) as needed.
Add a System Profile
Link the distro to a system profile (used to install specific machines):
sudo cobbler profile add --name ubuntu-22.04-profile --distro ubuntu-22.04 --kickstart /var/lib/cobbler/kickstarts/ubuntu-22.04.seed
Troubleshooting Tips
- DHCP Not Assigning IPs: Check the DHCP template syntax (e.g., missing braces, typos) and ensure
manage_dhcpis set to1in/etc/cobbler/settings. - Clients Not PXE Booting: Verify TFTP is running (
systemctl status xinetd) and boot files exist in/var/lib/tftpboot. - Cobbler Sync Errors: Review logs at
/var/log/cobbler/cobbler.logfor details.
By following these steps, you’ll have a fully integrated Cobbler-DHCP setup that automates IP allocation and OS deployment over your network.