A PXE install server allows your client computers to boot and install a Linux distribution over the network, without the need of burning Linux iso images, or human interaction.
To install a PXE server, you will need the following components:
1. DHCP Server
2. TFTP Server
3. NFS/FTP/HTTPD server (to store installing files)
Step 1 - Install dhcp server
[root@server1 ~] # yum install dhcp
Dhcpd configuration file is located at /etc/dhcpd.conf. You can use /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample as a sample config, or you can use my config below as a base, make sure you change the subnet.
ddns-update-style interim; not authoritative; option domain-name "test.org"; option domain-name-servers 208.67.222.222, 208.67.220.220; option subnet-mask 255.255.255.0; subnet 172.20.30.0 netmask 255.255.255.0 { authoritative; range 172.20.30.10 172.20.30.90; option routers 172.20.30.254; allow unknown-clients; allow booting allow bootp next-server 172.20.30.100; filename "pxelinux.0"; }
Step 2 - Install tftp-server
[root@server1 ~] # yum install tftp-server
Edit /etc/xinetd.d/tftp and set disable to no.
service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4 }
Step 3 - Create Network Install source
We can use three methods to store the installation files on the network and retrieve it when booting the client using PXE - nfs, ftp or http. I have chosen ftp:
[root@server1 ~] # yum install vsftpd
Public accessible ftp site is located in /var/ftp. Create installation tree in this folder.
[root@server1 ~] # mkdir -p /var/ftp/install/centos/i386/5.2 [root@server1 ~] # mkdir -p /var/ftp/install/debian/i386/4 [root@server1 ~] # mkdir -p /var/ftp/install/ubuntu-desktop/i386/8.10 [root@server1 ~] # mkdir -p /var/ftp/install/ubuntu-server/i386/8.10
If you have download dvd or cd iso files, you can mount them and copy the files:
[root@server1 ~] # mount -t iso9660 -o loop CentOS-5.2-i386-bin-DVD.iso /mnt/iso
Once mounted copy the installation files to /var/ftp/install/centos/i386/5.2. do this for each Linux distribution you want to include in your PXE server:
[root@server1 ~] # cp -avr /mnt/iso/* /var/ftp/install/centos/i386/5.2
Step 4 Restart dhcpd, tftpd and vsftpd Services
[root@server1 ~] # /etc/init.d/dhcpd restart [root@server1 ~] # /etc/init.d/xinetd restart [root@server1 ~] # /etc/init.d/vsftpd restart
and make the services persistent across reboots:
[root@server1 ~] # chkconfig --level 345 dhcpd on [root@server1 ~] # chkconfig --level 345 vsftpd on
tftpd server is managed by xinetd which is on after reboot by default.
Step 5 - Setup tftp network boot files
Create /tftpboot/images/ directory and populate it with the files necessary to start the installation program via PXE.
1. Copy the /usr/lib/syslinux/pxelinux.0 file installed by the syslinux package into /tftpboot/
[root@server1 tftpboot] # cp /usr/lib/syslinux/pxelinux.0 /tftpboot
2. Create /tftpboot/images/ directory tree and copy vmlinuz and inetrd files which are in the first cd/dvd or install-souce (/images/pxeboot/vmlinuz and /images/pxeboot/initrd).
[root@server1 tftpboot] # mkdir -p images/centos/i386/5.2 [root@server1 tftpboot] # cp /var/ftp/install/centos/i386/5.2/images/pxeboot/vmlinuz images/centos/i386/5.2 [root@server1 tftpboot] # cp /var/ftp/install/centos/i386/5.2/images/pxeboot/initrd images/centos/i386/5.2
Step 6 - Create PXE Menu
Use the following steps to configure the PXE menu:
1. Copy menu.c32 file from /usr/lib/syslinux/menu.c32 into /tftpboot
[root@server1 ~] # cp /usr/lib/syslinux/menu.c32 /tftpboot
2. Create /tftpboot/pxelinux.cnf directory
[root@server1 ~] # mkdir /tftpboot/pxelinux.cfg
3. Create /tftpboot/pxelinux.cnf/default configuration file. The following is my default file configuration:
default menu.c32 prompt 0 timeout 300 MENU TITLE PXE Menu LABEL CentoS 5.2 i386 MENU LABEL CentOS 5.2 i386 KERNEL images/centos/i386/5.2/vmlinuz append vga=normal initrd=images/centos/i386/5.2/initrd.img ramdisk_size=32768 method=ftp://172.20.30.100/install/centos/i386/5.2 LABEL Debian etch i386 MENU LABEL Debian etch i386 KERNEL images/debian/i386/4/vmlinuz append vga=normal initrd=images/debian/i386/4/initrd.gz ramdisk_size=32768 method=ftp://172.20.30.100/install/debian/i386/4 LABEL Ubuntu-Server 8.10 MENU LABEL Ubuntu-Server 8.10 KERNEL images/ubuntu-server/i386/8.10/linux append vga=normal initrd=images/ubuntu-server/i386/8.10/initrd.gz ramdisk_size=32768 LABEL Ubuntu-Desktop 8.10 MENU LABEL Ubuntu-Desktop 8.10 KERNEL images/ubuntu-desktop/i386/8.10/linux append vga=normal initrd=images/ubuntu-desktop/i386/8.10/initrd.gz ramdisk_size=32768
tftp server files structure should look like this:
[root@server1 ~]# tree /tftpboot/ /tftpboot/ |-- images | |-- centos | | `-- i386 | | `-- 5.2 | | |-- initrd.img | | `-- vmlinuz | |-- debian | | `-- i386 | | `-- 4 | | |-- initrd.gz | | `-- vmlinuz | |-- ubuntu-desktop | | `-- i386 | | `-- 8.10 | | |-- initrd.gz | | `-- linux | `-- ubuntu-server | `-- i386 | `-- 8.10 | |-- initrd.gz | `-- linux |-- menu.c32 |-- pxelinux.0 `-- pxelinux.cfg |-- default
FTP files structure should look like this:
[root@server1 ~]# tree -L 3 /var/ftp /install/ /var/ftp/install/ |-- centos | `-- i386 | `-- 5.2 |-- debian | `-- i386 | `-- 4 |-- ks | `-- ks.cfg |-- ubuntu-desktop | `-- i386 | `-- 8.10 `-- ubuntu-server `-- i386 `-- 8.10
Automating CenOS installation using kickstart
1. Install kickstart.
[root@server1 ~] # yum install system-config-kickstart
2. Create kickstart file
Create kickstart file and place it on your installation source ftp site. Following is my kickstart configuration file that have been placed in ftp://172.20.30.100/install/ks/ks.cfg
#platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Use graphical install graphical # Firewall configuration firewall --enabled --ssh # Run the Setup Agent on first boot firstboot --disable # System keyboard keyboard uk # System language lang en_GB # Installation logging level logging --level=info # Use network installation url --url=ftp://172.20.30.100/install/centos/i386/5.2 # Network information network --bootproto=dhcp --device=eth0 --onboot=on #network --bootproto=dhcp --device=eth1 --onboot=on # Reboot after installation reboot #Root password rootpw --iscrypted $1$dfadfaaffafarae1 # SELinux configuration selinux --enforcing # System timezone timezone Europe/London # Install OS instead of upgrade install # X Window System configuration information xconfig --defaultdesktop=GNOME --depth=8 --resolution=800x600 # Disk partitioning information part swap --bytes-per-inode=4096 --fstype="swap" --size=1000 part / --bytes-per-inode=4096 --fstype="ext3" --size=4000 %packages @base
3. Modify /ftpboot/pxelinux.cfg/default
Edit /ftpboot/pxelinux.cfg/default file and add ks parameter.
LABEL CentoS 5.2 i386 MENU LABEL CentOS 5.2 i386 KERNEL images/centos/i386/5.2/vmlinuz append vga=normal initrd=images/centos/i386/5.2/initrd.img ramdisk_size=32768 ks=ftp://172.20.30.100/install/ks/ks.cfg