1.\"- 2.\" SPDX-License-Identifier: BSD-3-Clause 3.\" 4.\" Copyright (c) 1994 Gordon W. Ross, Theo de Raadt 5.\" Updated by Luigi Rizzo, Robert Watson 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. The name of the author may not be used to endorse or promote products 17.\" derived from this software without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd August 11, 2024 31.Dt DISKLESS 8 32.Os 33.Sh NAME 34.Nm diskless 35.Nd booting a system over the network with PXE 36.Sh DESCRIPTION 37The ability to boot a machine over the network is useful for 38.Em diskless 39or 40.Em dataless 41machines, or as a temporary measure while repairing or 42re-installing file systems on a local disk. 43This file provides a general description of the interactions between 44a client and its server when a client is booting over the network. 45.Sh OPERATION 46When booting a system over the network, there are three 47phases of interaction between client and server: 48.Bl -enum 49.It 50The stage-1 bootstrap, typically PXE built into your Ethernet 51card, loads a second-stage boot program. 52.It 53The second-stage boot program, typically 54.Xr pxeboot 8 , 55loads modules and 56the kernel, and boots the kernel. 57.It 58The kernel 59.Tn NFS 60mounts the root directory and continues from there. 61.El 62.Pp 63Each of these phases are described in further detail below. 64.Pp 65First, the stage-1 bootstrap loads the stage-2 boot program over 66the network. 67The stage-1 bootstrap typically uses 68.Tn BOOTP 69or 70.Tn DHCP 71to obtain the filename to load, then uses 72.Tn TFTP 73to load the file. 74This file is typically called 75.Pa pxeboot , 76and should be copied from 77.Pa /boot/pxeboot 78into the 79.Tn TFTP 80directory on the server, which is typically 81.Pa /tftpdir . 82.Pp 83The stage-2 boot program then loads additional modules and the kernel. 84These files may not exist on the 85.Tn DHCP 86or 87.Tn BOOTP 88server. 89You can use the 90.Ic next-server 91option available in 92.Tn DHCP 93configurations to specify the server holding 94the second stage boot files and kernel. 95The stage-2 program uses 96.Tn NFS 97or 98.Tn TFTP 99to obtain these files. 100By default, 101.Tn NFS 102is used. 103If you are using 104.Xr pxeboot 8 , 105you can install a version that uses 106.Tn TFTP 107by setting 108.Li LOADER_TFTP_SUPPORT=YES 109in your 110.Xr make.conf 5 , 111then recompiling and reinstalling 112.Xr pxeboot 8 113via the command listed below. 114It is often necessary to use 115.Tn TFTP 116here so you can place a custom kernel 117in 118.Pa /tftpdir/ . 119If you use 120.Tn NFS 121and do not have a custom root file system for the 122.Nm 123client, the stage-2 boot will load your server's kernel as the kernel for 124the 125.Nm 126machine, which may not be what you want to have happen. 127.Bd -literal -offset indent 128cd /usr/src/stand 129make clean; make; make install 130cp /boot/pxeboot /tftpdir/ 131.Ed 132.Pp 133In phase 3, the kernel acquires IP networking configuration in one 134of two ways, and then proceeds to mount the root file system and start 135operation. 136If the phase 2 loader supports passing network configuration to the 137kernel using the kernel environment, then the kernel will configure 138the network interface using that information. 139Otherwise, it must use 140.Tn DHCP 141or 142.Tn BOOTP 143to acquire 144configuration information. 145The boot 146scripts recognize a 147.Nm 148startup and perform 149the actions found in 150.Pa /etc/rc.d/resolv , 151.Pa /etc/rc.d/tmp , 152.Pa /etc/rc.d/var , 153and 154.Pa /etc/rc.initdiskless . 155.Sh CONFIGURATION 156In order to run a 157.Nm 158client, you need the following: 159.Bl -bullet 160.It 161An 162.Tn NFS 163server which exports a root and 164.Pa /usr 165partitions with appropriate permissions. 166The 167.Nm 168scripts work with read-only partitions, as long as root is exported with 169.Fl maproot Ns =0 170so that some system files can be accessed. 171As an example, 172.Pa /etc/exports 173can contain the following lines: 174.Bd -literal -offset indent 175<ROOT> -ro -maproot=0 -alldirs <list of diskless clients> 176/usr -ro -alldirs <list of diskless clients> 177.Ed 178.Pp 179where 180.Aq ROOT 181is the mount point on the server of the root partition. 182The script 183.Pa /usr/share/examples/diskless/clone_root 184can be used to create a shared read-only root partition, 185but in many cases you may decide to export 186(again as read-only) the root directory used by 187the server itself. 188.It 189A 190.Tn BOOTP 191or 192.Tn DHCP 193server. 194.Xr bootpd 8 195can be enabled by 196uncommenting the 197.Dq Li bootps 198line in 199.Pa /etc/inetd.conf . 200A sample 201.Pa /etc/bootptab 202can be the following: 203.Bd -literal -offset indent 204 .default:\\ 205 hn:ht=1:vm=rfc1048:\\ 206 :sm=255.255.255.0:\\ 207 :sa=<SERVER>:\\ 208 :gw=<GATEWAY>:\\ 209 :rp="<SERVER>:<ROOT>": 210 211<CLIENT>:ha=0123456789ab:tc=.default 212.Ed 213.Pp 214where 215.Aq SERVER , 216.Aq GATEWAY 217and 218.Aq ROOT 219have the obvious meanings. 220.It 221A properly initialized root partition. 222The script 223.Pa /usr/share/examples/diskless/clone_root 224can help in creating it, using the server's root partition 225as a reference. 226If you are just starting out, you should 227simply use the server's own root directory, 228.Pa / , 229and not try to clone it. 230.Pp 231You often do not want to use the same 232.Pa rc.conf 233or 234.Pa rc.local 235files for the 236.Nm 237boot as you do on the server. 238The 239.Nm 240boot 241scripts provide a mechanism through which you can override various files 242in 243.Pa /etc 244(as well as other subdirectories of root). 245.Pp 246One difference that you should pay particular attention to is 247the value of 248.Va local_startup 249in 250.Pa /etc/defaults/rc.conf . 251A typical value for a 252.Nm 253boot is 254.Va mountcritremote , 255however your needs may be different. 256.Pp 257The scripts provide four 258overriding directories situated in 259.Pa /conf/base , 260.Pa /conf/default , 261.Pa /conf/<broadcast-ip> , 262and 263.Pa /conf/<machine-ip> . 264You should always create 265.Pa /conf/base/etc , 266which will entirely replace the server's 267.Pa /etc 268on the 269.Nm 270machine. 271You can clone the server's 272.Pa /etc 273here or you can create a special file which tells the 274.Nm 275boot scripts 276to remount the server's 277.Pa /etc 278onto 279.Pa /conf/base/etc . 280You do this by creating the file 281.Pa /conf/base/etc/diskless_remount 282containing the mount point to use as a basis of the 283.Nm 284machine's 285.Pa /etc . 286For example, the file might contain: 287.Pp 288.Dl 10.0.0.1:/etc 289.Pp 290Alternatively, if the server contains several independent roots, the file 291might contain: 292.Pp 293.Dl 10.0.0.1:/usr/diskless/4.7-RELEASE/etc 294.Pp 295This would work, but if you copied 296.Pa /usr/diskless/4.7-RELEASE 297to 298.Pa /usr/diskless/4.8-RELEASE 299and upgraded the installation, you would need to modify the 300.Pa diskless_remount 301files to reflect that move. 302To avoid that, paths in 303.Pa diskless_remount 304files beginning with 305.Pa / 306have the actual path of the client's root prepended to them so the file 307could instead contain: 308.Pp 309.Dl /etc 310.Pp 311The 312.Nm 313scripts create memory file systems to hold the overridden 314directories. 315Only a 5MB partition is created by default, which may not 316be sufficient for your purposes. 317To override this, you can create the 318file 319.Pa /conf/base/etc/md_size 320containing the size, in 512 byte sectors, of the memory disk to create 321for that directory. 322.Pp 323You then typically provide file-by-file overrides in the 324.Pa /conf/default/etc 325directory. 326At a minimum, you must provide overrides for 327.Pa /etc/fstab , /etc/rc.conf , 328and 329.Pa /etc/rc.local 330via 331.Pa /conf/default/etc/fstab , /conf/default/etc/rc.conf , 332and 333.Pa /conf/default/etc/rc.local . 334.Pp 335Overrides are hierarchical. 336You can supply network-specific defaults 337in the 338.Pa /conf/ Ns Ao Ar BROADCASTIP Ac Ns Pa /etc 339directory, where 340.Aq Ar BROADCASTIP 341represents the broadcast IP address of 342the 343.Nm 344system as given to it via 345.Tn BOOTP . 346The 347.Pa diskless_remount 348and 349.Pa md_size 350features work in any of these directories. 351The configuration feature works on directories other then 352.Pa /etc , 353you simply create the directory you wish to replace or override in 354.Pa /conf/{base,default,<broadcast>,<ip>}/* 355and work it in the same way that you work 356.Pa /etc . 357.Pp 358Since you normally clone the server's 359.Pa /etc 360using the 361.Pa /conf/base/etc/diskless_remount , 362you might wish to remove unneeded files from the memory file system. 363For example, 364if the server has a firewall but you do not, you might wish 365to remove 366.Pa /etc/ipfw.conf . 367You can do this by creating a 368.Pa /conf/base/ Ns Ao Ar DIRECTORY Ac Ns Pa .remove 369file. 370For example, 371.Pa /conf/base/etc.remove , 372which contains a list of relative paths that the boot scripts should remove 373from the memory file systems. 374.Pp 375As a minimum, you normally need to have the following in 376.Pa /conf/default/etc/fstab 377.Bd -literal -offset indent 378<SERVER>:<ROOT> / nfs ro 0 0 379<SERVER>:/usr /usr nfs ro 0 0 380.Ed 381.Pp 382You also need to create a customized version of 383.Pa /conf/default/etc/rc.conf 384which should contain 385the startup options for the 386.Nm 387client, and 388.Pa /conf/default/etc/rc.local 389which could be empty but prevents the server's own 390.Pa /etc/rc.local 391from leaking onto the 392.Nm 393system. 394.Pp 395In 396.Pa rc.conf , 397most likely 398you will not need to set 399.Va hostname 400and 401.Va ifconfig_* 402because these will be already set by the startup code. 403Finally, it might be convenient to use a 404.Ic case 405statement using 406.Li `hostname` 407as the switch variable to do machine-specific configuration 408in case a number of 409.Nm 410clients share the same configuration 411files. 412.It 413The kernel for the 414.Nm 415clients, which will be loaded using 416.Tn NFS 417or 418.Tn TFTP , 419must include support for the NFS client: 420.Pp 421.D1 Cd "options NFSCL" 422.D1 Cd "options NFS_ROOT" 423.Pp 424If you are using a boot mechanism that does not pass network configuration 425to the kernel using the kernel environment, you will also need to include 426the following options: 427.Pp 428.D1 Cd "options BOOTP" 429.D1 Cd "options BOOTP_NFSROOT" 430.D1 Cd "options BOOTP_COMPAT" 431.Pp 432.Em Note : 433the PXE environment does not require these options. 434.Pp 435The 436.Nm 437booting environment relies on memory-backed file systems to 438support temporary local storage in the event that the root file system 439is mounted read-only; as such, it is necessary to add the following 440to the device section of the kernel configuration: 441.Pp 442.D1 Cd "device md" 443.Pp 444If you use the firewall, remember to default to 445.Dq open , 446or your kernel 447will not be able to send/receive the 448.Tn BOOTP 449packets. 450.El 451.Sh SECURITY ISSUES 452Be warned that using unencrypted 453.Tn NFS 454to mount root and user 455partitions may expose information such as 456encryption keys. 457.Sh SEE ALSO 458.Xr ethers 5 , 459.Xr exports 5 , 460.Xr make.conf 5 , 461.Xr bootpd 8 , 462.Xr mountd 8 , 463.Xr nfsd 8 , 464.Xr pxeboot 8 , 465.Xr reboot 8 , 466.Xr tftpd 8 467.Pp 468.Pa ports/net/etherboot 469.Sh HISTORY 470The 471.Nm 472environment first appeared in 473.Fx 2.2.5 . 474.Sh BUGS 475This manpage is probably incomplete. 476.Pp 477.Fx 478sometimes requires to write onto 479the root partition, so the startup scripts mount MFS 480file systems on some locations (e.g.\& 481.Pa /etc 482and 483.Pa /var ) , 484while 485trying to preserve the original content. 486The process might not handle all cases. 487