nfsroot.txt 12.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
Mounting the root filesystem via NFS (nfsroot)
===============================================

Written 1996 by Gero Kuhlmann <gero@gkminix.han.de>
Updated 1997 by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
6
Updated 2006 by Nico Schottelius <nico-kernel-nfsroot@schottelius.org>
7
Updated 2006 by Horms <horms@verge.net.au>
8
Updated 2018 by Chris Novakovic <chris@chrisn.me.uk>
L
Linus Torvalds 已提交
9 10 11



12 13 14
In order to use a diskless system, such as an X-terminal or printer server
for example, it is necessary for the root filesystem to be present on a
non-disk device. This may be an initramfs (see Documentation/filesystems/
15
ramfs-rootfs-initramfs.txt), a ramdisk (see Documentation/admin-guide/initrd.rst) or a
16 17
filesystem mounted via NFS. The following text describes on how to use NFS
for the root filesystem. For the rest of this text 'client' means the
L
Linus Torvalds 已提交
18 19 20 21 22 23 24 25
diskless system, and 'server' means the NFS server.




1.) Enabling nfsroot capabilities
    -----------------------------

26 27 28 29 30 31 32
In order to use nfsroot, NFS client support needs to be selected as
built-in during configuration. Once this has been selected, the nfsroot
option will become available, which should also be selected.

In the networking options, kernel level autoconfiguration can be selected,
along with the types of autoconfiguration to support. Selecting all of
DHCP, BOOTP and RARP is safe.
L
Linus Torvalds 已提交
33 34 35 36 37 38 39




2.) Kernel command line
    -------------------

40 41 42 43
When the kernel has been loaded by a boot loader (see below) it needs to be
told what root fs device to use. And in the case of nfsroot, where to find
both the server and the name of the directory on the server to mount as root.
This can be established using the following kernel command line parameters:
L
Linus Torvalds 已提交
44 45 46 47 48 49 50 51 52 53 54


root=/dev/nfs

  This is necessary to enable the pseudo-NFS-device. Note that it's not a
  real device but just a synonym to tell the kernel to use NFS instead of
  a real device.


nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]

55 56
  If the `nfsroot' parameter is NOT given on the command line,
  the default "/tftpboot/%s" will be used.
L
Linus Torvalds 已提交
57

58 59 60 61
  <server-ip>	Specifies the IP address of the NFS server.
		The default address is determined by the `ip' parameter
		(see below). This parameter allows the use of different
		servers for IP autoconfiguration and NFS.
L
Linus Torvalds 已提交
62

63 64 65 66
  <root-dir>	Name of the directory on the server to mount as root.
		If there is a "%s" token in the string, it will be
		replaced by the ASCII-representation of the client's
		IP address.
L
Linus Torvalds 已提交
67 68

  <nfs-options>	Standard NFS options. All options are separated by commas.
69
		The following defaults are used:
L
Linus Torvalds 已提交
70
			port		= as given by server portmap daemon
71 72
			rsize		= 4096
			wsize		= 4096
L
Linus Torvalds 已提交
73 74 75 76 77 78 79 80 81
			timeo		= 7
			retrans		= 3
			acregmin	= 3
			acregmax	= 60
			acdirmin	= 30
			acdirmax	= 60
			flags		= hard, nointr, noposix, cto, ac


82
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:
83
   <dns0-ip>:<dns1-ip>:<ntp0-ip>
L
Linus Torvalds 已提交
84 85

  This parameter tells the kernel how to configure IP addresses of devices
86 87 88 89
  and also how to set up the IP routing table. It was originally called
  `nfsaddrs', but now the boot-time IP configuration works independently of
  NFS, so it was renamed to `ip' and the old name remained as an alias for
  compatibility reasons.
L
Linus Torvalds 已提交
90 91 92

  If this parameter is missing from the kernel command line, all fields are
  assumed to be empty, and the defaults mentioned below apply. In general
93 94 95 96
  this means that the kernel tries to configure everything using
  autoconfiguration.

  The <autoconf> parameter can appear alone as the value to the `ip'
97 98 99 100 101
  parameter (without all the ':' characters before).  If the value is
  "ip=off" or "ip=none", no autoconfiguration will take place, otherwise
  autoconfiguration will take place.  The most common way to use this
  is "ip=dhcp".

102
  <client-ip>	IP address of the client.
L
Linus Torvalds 已提交
103

104
  		Default:  Determined using autoconfiguration.
L
Linus Torvalds 已提交
105 106 107

  <server-ip>	IP address of the NFS server. If RARP is used to determine
		the client address and this parameter is NOT empty only
108 109
		replies from the specified server are accepted.

110
		Only required for NFS root. That is autoconfiguration
111 112 113
		will not be triggered if it is missing and NFS root is not
		in operation.

114 115 116
		Value is exported to /proc/net/pnp with the prefix "bootserver "
		(see below).

117 118 119 120 121 122 123 124
		Default: Determined using autoconfiguration.
		         The address of the autoconfiguration server is used.

  <gw-ip>	IP address of a gateway if the server is on a different subnet.

		Default: Determined using autoconfiguration.

  <netmask>	Netmask for local network interface. If unspecified
L
Linus Torvalds 已提交
125
		the netmask is derived from the client IP address assuming
126
		classful addressing.
L
Linus Torvalds 已提交
127

128
		Default:  Determined using autoconfiguration.
L
Linus Torvalds 已提交
129

130 131 132 133 134 135 136
  <hostname>	Name of the client. If a '.' character is present, anything
		before the first '.' is used as the client's hostname, and anything
		after it is used as its NIS domain name. May be supplied by
		autoconfiguration, but its absence will not trigger autoconfiguration.
		If specified and DHCP is used, the user-provided hostname (and NIS
		domain name, if present) will be carried in the DHCP request; this
		may cause a DNS record to be created or updated for the client.
L
Linus Torvalds 已提交
137

138
  		Default: Client IP address is used in ASCII notation.
L
Linus Torvalds 已提交
139

140 141 142 143 144 145 146
  <device>	Name of network device to use.

		Default: If the host only has one device, it is used.
			 Otherwise the device is determined using
			 autoconfiguration. This is done by sending
			 autoconfiguration requests out of all devices,
			 and using the device that received the first reply.
L
Linus Torvalds 已提交
147

148 149 150 151
  <autoconf>	Method to use for autoconfiguration. In the case of options
                which specify multiple autoconfiguration protocols,
		requests are sent using all protocols, and the first one
		to reply is used.
L
Linus Torvalds 已提交
152

153 154 155
		Only autoconfiguration protocols that have been compiled
		into the kernel will be used, regardless of the value of
		this option.
L
Linus Torvalds 已提交
156

157
                  off or none: don't use autoconfiguration
158
				(do static IP assignment instead)
159
		  on or any:   use any protocol available in the kernel
160
			       (default)
161 162 163 164 165
		  dhcp:        use DHCP
		  bootp:       use BOOTP
		  rarp:        use RARP
		  both:        use both BOOTP and RARP but not DHCP
		               (old option kept for backwards compatibility)
L
Linus Torvalds 已提交
166

167 168 169
		if dhcp is used, the client identifier can be used by following
		format "ip=dhcp,client-id-type,client-id-value"

170
                Default: any
L
Linus Torvalds 已提交
171

172 173 174 175 176 177 178 179 180 181
  <dns0-ip>	IP address of primary nameserver.
		Value is exported to /proc/net/pnp with the prefix "nameserver "
		(see below).

		Default: None if not using autoconfiguration; determined
		automatically if using autoconfiguration.

  <dns1-ip>	IP address of secondary nameserver.
		See <dns0-ip>.

182 183 184 185 186 187 188 189 190 191 192 193
  <ntp0-ip>	IP address of a Network Time Protocol (NTP) server.
		Value is exported to /proc/net/ipconfig/ntp_servers, but is
		otherwise unused (see below).

		Default: None if not using autoconfiguration; determined
		automatically if using autoconfiguration.

  After configuration (whether manual or automatic) is complete, two files
  are created in the following format; lines are omitted if their respective
  value is empty following configuration:

  - /proc/net/pnp:
194 195 196 197 198 199 200 201

	#PROTO: <DHCP|BOOTP|RARP|MANUAL>	(depending on configuration method)
	domain <dns-domain>			(if autoconfigured, the DNS domain)
	nameserver <dns0-ip>			(primary name server IP)
	nameserver <dns1-ip>			(secondary name server IP)
	nameserver <dns2-ip>			(tertiary name server IP)
	bootserver <server-ip>			(NFS server IP)

202 203 204 205 206 207 208 209 210
  - /proc/net/ipconfig/ntp_servers:

	<ntp0-ip>				(NTP server IP)
	<ntp1-ip>				(NTP server IP)
	<ntp2-ip>				(NTP server IP)

  <dns-domain> and <dns2-ip> (in /proc/net/pnp) and <ntp1-ip> and <ntp2-ip>
  (in /proc/net/ipconfig/ntp_servers) are requested during autoconfiguration;
  they cannot be specified as part of the "ip=" kernel command line parameter.
211

212 213 214
  Because the "domain" and "nameserver" options are recognised by DNS
  resolvers, /etc/resolv.conf is often linked to /proc/net/pnp on systems
  that use an NFS root filesystem.
215

216 217 218 219 220 221
  Note that the kernel will not synchronise the system time with any NTP
  servers it discovers; this is the responsibility of a user space process
  (e.g. an initrd/initramfs script that passes the IP addresses listed in
  /proc/net/ipconfig/ntp_servers to an NTP client before mounting the real
  root filesystem if it is on NFS).

L
Linus Torvalds 已提交
222

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
nfsrootdebug

  This parameter enables debugging messages to appear in the kernel
  log at boot time so that administrators can verify that the correct
  NFS mount options, server address, and root path are passed to the
  NFS client.


rdinit=<executable file>

  To specify which file contains the program that starts system
  initialization, administrators can use this command line parameter.
  The default value of this parameter is "/init".  If the specified
  file exists and the kernel can execute it, root filesystem related
  kernel command line parameters, including `nfsroot=', are ignored.

  A description of the process of mounting the root file system can be
  found in:

    Documentation/early-userspace/README


L
Linus Torvalds 已提交
245 246


247 248
3.) Boot Loader
    ----------
L
Linus Torvalds 已提交
249

250 251
To get the kernel into memory different approaches can be used.
They depend on various facilities being available:
L
Linus Torvalds 已提交
252 253


254
3.1)  Booting from a floppy using syslinux
L
Linus Torvalds 已提交
255

256
	When building kernels, an easy way to create a boot floppy that uses
257
	syslinux is to use the zdisk or bzdisk make targets which use zimage
258 259
      	and bzimage images respectively. Both targets accept the
     	FDARGS parameter which can be used to set the kernel command line.
L
Linus Torvalds 已提交
260

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
	e.g.
	   make bzdisk FDARGS="root=/dev/nfs"

   	Note that the user running this command will need to have
     	access to the floppy drive device, /dev/fd0

     	For more information on syslinux, including how to create bootdisks
     	for prebuilt kernels, see http://syslinux.zytor.com/

	N.B: Previously it was possible to write a kernel directly to
	     a floppy using dd, configure the boot device using rdev, and
	     boot using the resulting floppy. Linux no longer supports this
	     method of booting.

3.2) Booting from a cdrom using isolinux

     	When building kernels, an easy way to create a bootable cdrom that
     	uses isolinux is to use the isoimage target which uses a bzimage
     	image. Like zdisk and bzdisk, this target accepts the FDARGS
     	parameter which can be used to set the kernel command line.

	e.g.
	  make isoimage FDARGS="root=/dev/nfs"

     	The resulting iso image will be arch/<ARCH>/boot/image.iso
     	This can be written to a cdrom using a variety of tools including
     	cdrecord.

	e.g.
290
	  cdrecord dev=ATAPI:1,0,0 arch/x86/boot/image.iso
291 292 293

     	For more information on isolinux, including how to create bootdisks
     	for prebuilt kernels, see http://syslinux.zytor.com/
L
Linus Torvalds 已提交
294 295

3.2) Using LILO
296 297 298 299 300 301 302 303 304 305
	When using LILO all the necessary command line parameters may be
	specified using the 'append=' directive in the LILO configuration
	file.

	However, to use the 'root=' directive you also need to create
	a dummy root device, which may be removed after LILO is run.

	mknod /dev/boot255 c 0 255

	For information on configuring LILO, please refer to its documentation.
L
Linus Torvalds 已提交
306

307
3.3) Using GRUB
308 309
	When using GRUB, kernel parameter are simply appended after the kernel
	specification: kernel <kernel> <parameters>
310 311

3.4) Using loadlin
312 313 314 315 316 317 318
	loadlin may be used to boot Linux from a DOS command prompt without
	requiring a local hard disk to mount as root. This has not been
	thoroughly tested by the authors of this document, but in general
	it should be possible configure the kernel command line similarly
	to the configuration of LILO.

	Please refer to the loadlin documentation for further information.
L
Linus Torvalds 已提交
319

320
3.5) Using a boot ROM
321 322 323 324 325 326 327
	This is probably the most elegant way of booting a diskless client.
	With a boot ROM the kernel is loaded using the TFTP protocol. The
	authors of this document are not aware of any no commercial boot
	ROMs that support booting Linux over the network. However, there
	are two free implementations of a boot ROM, netboot-nfs and
	etherboot, both of which are available on sunsite.unc.edu, and both
	of which contain everything you need to boot a diskless Linux client.
L
Linus Torvalds 已提交
328

329
3.6) Using pxelinux
330 331 332 333
	Pxelinux may be used to boot linux using the PXE boot loader
	which is present on many modern network cards.

	When using pxelinux, the kernel image is specified using
334 335
	"kernel <relative-path-below /tftpboot>". The nfsroot parameters
	are passed to the kernel by adding them to the "append" line.
336
	It is common to use serial console in conjunction with pxeliunx,
337
	see Documentation/admin-guide/serial-console.rst for more information.
338 339 340

	For more information on isolinux, including how to create bootdisks
	for prebuilt kernels, see http://syslinux.zytor.com/
341

L
Linus Torvalds 已提交
342 343 344 345 346 347 348 349 350 351 352 353 354 355



4.) Credits
    -------

  The nfsroot code in the kernel and the RARP support have been written
  by Gero Kuhlmann <gero@gkminix.han.de>.

  The rest of the IP layer autoconfiguration code has been written
  by Martin Mares <mj@atrey.karlin.mff.cuni.cz>.

  In order to write the initial version of nfsroot I would like to thank
  Jens-Uwe Mager <jum@anubis.han.de> for his help.