Read-Only Diskless Debian10
Read-Only Diskless Debian10
with Debian 10
CTRL.01.01.013
Sébastien BLANCHET
Contents
1 Introduction 5
Chapter 1
Introduction
Prerequesites
• a DHCP server, to provide IP address to the clients when they boot.
• a TFTP server, to allow the clients to download the kernel and initial root
ram disk (initrd).
• a recent PXE file tree1 with menu.c32, pxelinux.0 and the pxelinux.cfg
directory.
Tips
The DHCP and TFTP servers can be easily validated with a basic test: boot
memtest86+ over PXE.
1
these files come from the Syslinux Project: http://syslinux.org
Chapter 2
2.1.3 Bootstrap
debootstrap creates a basic Debian system.
# apt install -y debootstrap
# debootstrap buster ${NFSROOT} http://ftp2.fr.debian.org/debian
The mirror URL is optional, but it downloads faster if you select a mirror close
to you. See manual debootstrap(8) for details.
Now we customize this basic Debian system in $NFSROOT.
1
If you wish to recompile a custom kernel then prepare a 30 GiB virtual hard disk, otherwise
15 GiB is enough.
# security patches
deb http://security.debian.org/debian-security buster/updates main non-free contrib
# chroot $NFSROOT
# apt update
# apt -y install bind9-host locales
Configure locale
# locale-gen en_US.UTF-8
# dpkg-reconfigure locales
$NFSROOT/bin/whereami
Create a script /bin/whereami to setup client hostname from /etc/hosts
Listing 2.2: $NFSROOT/bin/whereami
#!/bin/bash
#finds node’s hostname based on matching IP in DNS
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# get IP address
MYIP=(‘ip address show label ${GWDEV} | tr ’/’ ’␣’‘)
MYIP=${MYIP[1]}
# chmod +x ${NFSROOT}/bin/whereami
$NFSROOT/etc/rc.local
Even if Debian uses systemd, /etc/rc.local is very convenient. So create the
file $NFSROOT/etc/rc.local
# touch ${NFSROOT}/etc/rc.local
# chmod +x ${NFSROOT}/etc/rc.local
# chroot ${NFSROOT}
# apt -y install nfs-common
# exit
Unlike “/”, /home is mounted with read-write privilege from another NFS
share.
The nolock nfs option is very important, otherwise sqlite does not work on
these mount points. See man 5 nfs, for other nfs options.
# chroot ${NFSROOT}
# passwd root
# mv /root /home/root
# usermod -d /home/root root
# exit
BUSYBOX=y
KEYMAP=n
COMPRESS=xz
DEVICE=
NFSROOT=auto
BOOT=nfs
# chroot $NFSROOT
# update-initramfs -u
# exit
$NFSROOT/etc/default
Finaly configure ramdisk for temporary files. See manuals rcS(5) and tmpfs(5)
for details.
# chroot ${NFSROOT}
# echo ASYNCMOUNTNFS=no >> /etc/default/rcS
# echo RAMTMP=yes >> /etc/default/tmpfs
# exit
# cd /home
# tar cvfj nfsroot10.tar.bz2 ${NFSROOT}
# scp nfsroot10.tar.bz2 root@nfsserver:/path/to/exportdir
I usually rename the initrd from .img to .pxe to avoid any confusion, but
it is not mandatory.
ontimeout linux-4.19.0-6-amd64-buster
timeout 50
label linux-4.19.0-6-amd64-buster
menu label linux-4.19.0-6-amd64 buster
kernel vmlinuz-4.19.0-6-amd64
append root=/dev/nfs initrd=initrd.pxe-4.19.0-6-amd64 \
nfsroot=nfsserver:/path/to/nfsroot ro panic=60 \
ipv6.disable=1 ip=:::::eno1
Note
• the backslash in the append line is only for printing purpose, to show that
the line continue. But indeed, all the arguments must be on the same line.
• If you wish that one diskless PC has read-write acces to easily modifying
the filesystem, replace ro by rw in the append configuration line.
• If you do not use IPv6, disable it on the command line to boot faster.
• Never use the ipappend option, it creates problems on computer with sev-
eral interfaces.
• If you have several Ethernet interfaces, specify which one to use with
ip:::::ethernetname to boot faster.
• If you have DHCP issue2 at the kernel level you must specify a static IP
address on the kernel command line3
ip=<client-ip> :<server-ip> :<gw-ip> :<netmask> :<hostname> :<device> :
<autoconf> :<dns0-ip> :<dns1-ip> :<ntp0-ip>
2
For an unknown reason, the DHCP request for TFTP is always faster and more reliable
than the second DHCP request for the kernel
3
See Linux kernel documentation Documentation/filesystems/nfs/nfsroot.txt for more
details.
Chapter 3
This chapter shows how to optimize the NFS root to match the IRAM needs.
# cd /usr/src
# wget https://kernel.org/pub/linux/kernel/v4.x/linux-4.14.155.tar.xz
# tar xf linux-4.14.155.tar.xz
# make clean
# scripts/config --disable MODULE_SIG
# scripts/config --disable DEBUG_INFO
# scripts/config --set-str SYSTEM_TRUSTED_KEYS ""
# make deb-pkg
# apt update
# apt install xorg mesa-utils xfce4 wdm
check-local-server
no-ignore-nologin
no-restart-on-upgrade
use-sessreg
#auto-update-wmlist
3.4.2 NTP
The computer clock is controlled by NTP. Install ntp
Each computer must save its own ntp drift file on a persistant storage, oth-
erwise it may take some hours to compensate the residual timing errors. But all
computers shares the same ntp.conf, and this file does not support shell variable
expanding. Therefore a small patch is added to /etc/init.d/ntp to preprocess
/etc/ntp.conf. With such a trick we can use $HOSTNAME in filename.
...
3.5 Network
3.5.1 iptables
# apt -y install iptables iptables-persistent
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that
# doesn’t use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
COMMIT