Fedora 25: Install PXE Boot server for automated install

This article will run PXE Boot server for automated install, and automatically install Fedora 25 on client which is connected to PXE Boot server via network. You must make client memory be rather than 1536MB.

1 Install PXE Boot server

The following script will install PXE Boot server. Change the variables to your environment.

  • SERVER_IPADDR is IP adress of PXE Boot server.
  • DHCP_SUBNET is network address for DHCP.
  • DHCP_NETMASK is subnet for DHCP.
  • DHCP_DOMAIN is domain for DHCP.
  • DHCP_DNS is DNS for DHCP.
  • DHCP_ROUTER is gateway for DHCP.
  • DHCP_CLIENT_HOSTNAME is hostname of client.
  • DHCP_CLIENT_IPADDR is IP address of client.
  • DHCP_CLIENT_MACADDR is MAC address of client.
  • KICKSTART_LANGUAGE is language for Kickstart.
  • KICKSTART_KEYMAP is keyboard layout for Kickstart.
  • KICKSTART_TIMEZONE is time zone for Kickstart.
  • MIRROR_URL is repository URL for network installation.

Preseed runs the following.

  • Set root user password to "fedora".
  • Create user which name is "fedora" and password is "fedora".
  • Password is hashed with this.
  • Install packages for GNOME desktop environment.
  • This article creates fedora-25-ks.cfg. But you can use /root/anaconda-ks.cfg by making "cdrom" to comment out.
#!/bin/sh

set -e

# Change the following variable to yours.
[ -z "${SERVER_IPADDR}" ] && \
  SERVER_IPADDR=$(hostname -I | awk '{ print $1 }')
[ -z "${DHCP_SUBNET}" ] && DHCP_SUBNET=192.168.11.0
[ -z "${DHCP_NETMASK}" ] && DHCP_NETMASK=255.255.255.0
[ -z "${DHCP_DOMAIN}" ] && DHCP_DOMAIN=hiroom2.com
[ -z "${DHCP_DNS}" ] && DHCP_DNS="192.168.11.2, 192.168.11.1"
[ -z "${DHCP_ROUTER}" ] && DHCP_ROUTER=192.168.11.1
[ -z "${DHCP_CLIENT_HOSTNAME}" ] && \
  DHCP_CLIENT_HOSTNAME=fedora-25-pxeboot-client
[ -z "${DHCP_CLIENT_IPADDR}" ] && DHCP_CLIENT_IPADDR=192.168.11.254
[ -z "${DHCP_CLIENT_MACADDR}" ] && DHCP_CLIENT_MACADDR=52:54:00:5e:7a:a4
[ -z "${KICKSTART_LANGUAGE}" ] && KICKSTART_LANGUAGE=en_US.UTF-8
[ -z "${KICKSTART_KEYMAP}" ] && KICKSTART_KEYMAP=jp
[ -z "${KICKSTART_TIMEZONE}" ] && KICKSTART_TIMEZONE=Asia/Tokyo

if [ -z "${MIRROR_URL}" ]; then
  F25=https://dl.fedoraproject.org/pub/fedora/linux/releases/25
  MIRROR_URL=${F25}/Workstation/x86_64/os/
fi

tftp_server_install()
{
  sudo dnf install -y tftp-server
  sudo firewall-cmd --add-service=tftp --permanent
  sudo firewall-cmd --reload
  sudo systemctl enable tftp
  sudo systemctl restart tftp
}

dhcp_install()
{
  sudo dnf install -y dhcp

  cat <<EOF | sudo tee /etc/dhcp/dhcpd.conf
subnet ${DHCP_SUBNET} netmask ${DHCP_NETMASK} {
  option domain-name "${DHCP_DOMAIN}";
  option domain-name-servers ${DHCP_DNS};
  option routers ${DHCP_ROUTER};
  next-server ${SERVER_IPADDR};
  filename "pxelinux.0";
}

host ${DHCP_CLIENT_HOSTNAME} {
  hardware ethernet ${DHCP_CLIENT_MACADDR};
  fixed-address ${DHCP_CLIENT_IPADDR};
}
EOF

  sudo firewall-cmd --add-service=dhcp --permanent
  sudo firewall-cmd --reload
  sudo systemctl enable dhcpd
  sudo systemctl restart dhcpd
}

nfs_utils_install()
{
  sudo dnf install -y nfs-utils
  sudo firewall-cmd --add-service=nfs --permanent
  sudo firewall-cmd --reload
  sudo systemctl enable nfs
  sudo systemctl restart nfs

  sudo mkdir /var/lib/nfsroot
  cat <<EOF | sudo tee /etc/exports
/var/lib/nfsroot *(rw,sync,no_root_squash,no_subtree_check)
EOF
  sudo exportfs -ra
}

syslinux_install()
{
  sudo dnf install -y syslinux

  cd /var/lib/tftpboot
  sudo cp /usr/share/syslinux/pxelinux.0 .
  sudo cp -a /usr/share/syslinux .

  sudo wget -q ${MIRROR_URL}/isolinux/initrd.img
  sudo wget -q ${MIRROR_URL}/isolinux/vmlinuz

  sudo mkdir pxelinux.cfg
  cat <<EOF | sudo tee pxelinux.cfg/default
path syslinux
include menu.cfg
default syslinux/vesamenu.c32
prompt 0
timeout 50
EOF

  cat <<EOF | sudo tee menu.cfg
menu hshift 13
menu width 49
menu margin 8
menu tabmsg

menu title automated install boot menu
label fedora-25-automated-install
  menu label ^Fedora 25 automated install
  kernel vmlinuz
  append vga=788 initrd=initrd.img ip=dhcp inst.repo=${MIRROR_URL} \
    ks=nfs:${SERVER_IPADDR}:/var/lib/nfsroot/fedora-25-ks.cfg
menu end
EOF
}

kickstart_install()
{
  root_passwd=$(python -c "
import crypt
print(crypt.crypt(\"fedora\", crypt.mksalt(crypt.METHOD_SHA512)))
")
  user_passwd=$(python -c "
import crypt
print(crypt.crypt(\"fedora\", crypt.mksalt(crypt.METHOD_SHA512)))
")

  cat <<EOF | sudo tee /var/lib/nfsroot/fedora-25-ks.cfg
%pre
if [ -b /dev/vda ]; then
  echo "ignoredisk --only-use=vda" > /tmp/drive-ks.cfg
  echo "bootloader --location=mbr --boot-drive=vda" >> /tmp/drive-ks.cfg
else
  echo "ignoredisk --only-use=sda" > /tmp/drive-ks.cfg
  echo "bootloader --location=mbr --boot-drive=sda" >> /tmp/drive-ks.cfg
fi
%end

%include /tmp/drive-ks.cfg
auth --enableshadow --passalgo=sha512
graphical
firstboot --disable
eula --agreed
keyboard --vckeymap=${KICKSTART_KEYMAP} --xlayouts='${KICKSTART_KEYMAP}'
lang ${KICKSTART_LANGUAGE}
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network --hostname=${DHCP_CLIENT_HOSTNAME}
rootpw --iscrypted ${root_passwd}
timezone ${KICKSTART_TIMEZONE} --isUtc
user --groups=wheel --name=fedora --password=${user_passwd} --iscrypted
xconfig  --startxonboot
autopart --type=lvm
clearpart --none --initlabel
reboot

# Fedora Workstation.
%packages
@^workstation-product-environment
%end

%addon com_redhat_kdump --disable --reserve-mb='128'
%end
EOF
}

pxeboot_main()
{
  tftp_server_install
  dhcp_install
  nfs_utils_install
  syslinux_install
  kickstart_install
}

pxeboot_main

2 Install Fedora 25 automatically

This article installs Fedora 25 on virtual machine on KVM. Virtual machine on VirtualBox and real machine too can be installed Fedora 25 automatically with enabling network boot. Please check your BIOS setting.

Enable "NIC" of "Boot device order" with virt-manager. If CDROM is not empty or Disk is already installed some OS, you need to change order in order to NIC be top.

0001_BootDeviceOrder.png

iPXE sends DHCP requests, receives DHCP response from PXE Boot server, download and run boot image.

0002_iPXE.png

syslinux's menu is displayed. After 5 seconds, "Fedora 25 automated install" will be selected automatically.

0003_syslinux.png

Automated install is started.

0004_AutomatedInstall.png

Virtual machine is rebooted automatically when automated install is completed. Installed Fedora 25 is started.

0005_AutomatedInstalledFedora.png