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