Debian 9: Install PXE Boot server for thin client with NFS

Table of Contents

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_SERVER_INTERFACESv4 is network interface name for DHCP. DHCP will be provided via this network interface.
  • DHCP_SUBNET is network address for DHCP.
  • DHCP_NETMASK is subnet 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.

NFS root filesystem is set to the following.

  • Set root user password to “debian”.
  • Create user which name is “debian” and password is “debian”.
  • Install task-gnome-desktop package and openssh-server package.

#!/bin/shset -e# Change the following variable to yours.[ -z “${SERVER_IPADDR}” ] && SERVER_IPADDR=$(hostname -I | awk ‘{ print $1 }’)[ -z “${DHCP_SERVER_INTERFACESv4}” ] && DHCP_SERVER_INTERFACESv4=ens3[ -z “${DHCP_SUBNET}” ] && DHCP_SUBNET=[ -z “${DHCP_NETMASK}” ] && DHCP_NETMASK=[ -z “${DHCP_DOMAIN}” ] &&[ -z “${DHCP_DNS}” ] && DHCP_DNS=”,″[ -z “${DHCP_ROUTER}” ] && DHCP_ROUTER=[ -z “${DHCP_CLIENT_HOSTNAME}” ] && DHCP_CLIENT_HOSTNAME=debian-9-pxeboot-client[ -z “${DHCP_CLIENT_IPADDR}” ] && DHCP_CLIENT_IPADDR=[ -z “${DHCP_CLIENT_MACADDR}” ] && DHCP_CLIENT_MACADDR=52:54:00:5e:7a:a4atftpd_install(){ sudo apt install -y atftpd sudo systemctl enable atftpd sudo systemctl restart atftpd}isc_dhcp_server_install(){ sudo apt install -y isc-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 cat <<EOF | sudo tee /etc/dhcp/dhcpd.confsubnet ${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 systemctl restart isc-dhcp-server}nfs_kernel_server_install(){ # Set NFS server. sudo apt install -y nfs-kernel-server debootstrap systemd-container sudo mkdir /srv/nfs4 echo “/srv/nfs4 *(rw,sync,no_root_squash,no_subtree_check)” | sudo tee /etc/exports sudo exportfs -ra # Create root filesystem. URL=$(grep “^deb .* stretch main” /etc/apt/sources.list | awk ‘{ print $2 }’) sudo debootstrap stretch /srv/nfs4 “${URL}” # Get debconf from server for locale and keyboard. sudo apt install -y debconf-utils systemd-container sudo debconf-get-selections | grep locale | sudo tee /srv/nfs4/debconf.txt sudo debconf-get-selections | grep keyboard-configuration | sudo tee -a /srv/nfs4/debconf.txt sudo systemd-nspawn -D /srv/nfs4 sh -c “apt update -yapt upgrade -y# Set debconf to client for locale and debconf.txt | debconf-set-selectionsapt install –reinstall -y locales keyboard-configurationrm -f debconf.txt# Install kernel and create initrd.apt install -y initramfs-tools linux-image-amd64cat <<EOF > /etc/initramfs-tools/initramfs.confMODULES=netbootBUSYBOX=autoKEYMAP=nCOMPRESS=gzipDEVICE=NFSROOT=${SERVER_IPADDR}:/srv/nfs4BOOT=nfsEOFupdate-initramfs -tu# Install GNOME desktop and OpenSSH server.apt install -y task-gnome-desktop openssh-server# Set root password and create user.yes debian | passwduseradd -m -s /bin/bash debianyes debian | passwd debian# systemd needs /etc/fstab entry too while using nfsroot.echo ‘${SERVER_IPADDR}:/srv/nfs4 / nfs defaults 0 0’ > /etc/fstab# Generate /etc/resolv.conf with dhclient.rm -f /etc/resolv.confcat <<EOF > /lib/systemd/system/dhclient.service[Unit]Description=Run dhclient to generate /etc/[Service]ExecStart=/sbin/dhclientExecReload=/sbin/dhclient[Install]WantedBy=multi-user.targetEOFln -s /lib/systemd/system/dhclient.service /etc/systemd/system/”}pxelinux_install(){ cd /srv/tftp sudo apt install -y pxelinux syslinux sudo ln -s /usr/lib/syslinux/modules/bios sudo ln -s /usr/lib/PXELINUX/pxelinux.0 sudo ln -s /usr/lib/syslinux/modules/bios/ldlinux.c32 sudo ln -s /srv/nfs4/vmlinuz sudo ln -s /srv/nfs4/initrd.img sudo mkdir pxelinux.cfg cat <<EOF | sudo tee pxelinux.cfg/defaultpath biosinclude menu.cfgdefault bios/vesamenu.c32prompt 0timeout 10EOF cat <<EOF | sudo tee menu.cfgmenu hshift 13menu width 49menu margin 8menu tabmsgmenu title Thin client boot menulabel debian-9-thin-client menu label ^Debian 9 thin client kernel vmlinuz append vga=788 initrd=initrd.img ip=dhcp nfsroot=${SERVER_IPADDR}:/srv/nfs4 rwmenu endEOF}pxeboot_main(){ atftpd_install isc_dhcp_server_install nfs_kernel_server_install pxelinux_install}pxeboot_main

2 Run Debian 9 thin client with NFS

This article runs Debian 9 thin client on virtual machine on KVM. Virtual machine on VirtualBox and real machine too can run Debian 9 thin client with enabling network boot. Please check your BIOS setting.

Enable “NIC” of “Boot device order” and make it top of order with virt-manager.


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


syslinux’s menu is displayed. After 1 second, “Debian 9 thin client” will be selected automatically.


Debian 9 thin client is started.


Login is displayed.


Android | Linux | SDL - Narrow Escape