]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/bsdinstall/bsdinstall.8
bsdinstall: stop messing with file descriptors
[FreeBSD/FreeBSD.git] / usr.sbin / bsdinstall / bsdinstall.8
1 .\"-
2 .\" Copyright (c) 2011-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org> All rights reserved.
3 .\" Copyright (c) 2018 Roberto Fernandez Cueto <roberfern@gmail.com>
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 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 .\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
18 .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
23 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 .\" POSSIBILITY OF SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd March 26, 2021
29 .Dt BSDINSTALL 8
30 .Os
31 .Sh NAME
32 .Nm bsdinstall
33 .Nd system installer
34 .Sh SYNOPSIS
35 .Nm
36 .Op Ar options
37 .Op Ar target
38 .Op Ar ...
39 .Sh DESCRIPTION
40 .Nm
41 is used for installation of new systems, both for system setup from
42 installation media, e.g., CD-ROMs, and for use on live systems to prepare
43 VM images and jails.
44 .Pp
45 Much like
46 .Xr make 1 , Nm
47 takes a target and possible parameters of the target as arguments.
48 If invoked with no arguments, it will invoke the
49 .Cm auto
50 target, which provides a standard interactive installation, invoking the
51 others in sequence.
52 To perform a scripted installation,
53 these subtargets can be invoked separately by an installation script.
54 .Sh OPTIONS
55 .Nm
56 supports the following options, global to all targets:
57 .Bl -tag -width indent+
58 .It Fl D Ar file
59 Provide a path for the installation log file
60 .Pq overrides Ev BSDINSTALL_LOG .
61 See
62 .Sx ENVIRONMENT VARIABLES
63 for more information on
64 .Ev BSDINSTALL_LOG .
65 .El
66 .Sh TARGETS
67 Most of the following targets are only useful for scripting the installer.
68 For interactive use, most users will be interested only in the
69 .Cm auto ,
70 .Cm jail ,
71 and
72 .Cm script
73 targets.
74 .Bl -tag -width ".Cm jail Ar destination"
75 .It Cm auto
76 Run the standard interactive installation, including disk partitioning.
77 .It Cm jail Ar destination
78 Sets up a new chroot system at
79 .Pa destination ,
80 suitable for use with
81 .Xr jail 8 .
82 Behavior is generally similar to
83 .Cm auto ,
84 except that disk partitioning and network setup are skipped and a kernel is
85 not installed into the new system.
86 .It Cm script Ar script
87 Runs the installation script at
88 .Pa script .
89 See
90 .Sx SCRIPTING
91 for more information on this target.
92 .It Cm keymap
93 If the current controlling TTY is a
94 .Xr syscons 4
95 or
96 .Xr vt 4
97 console, asks the user to set the current keymap, and saves the result to the
98 new system's
99 .Pa rc.conf .
100 .It Cm hostname
101 Prompts the user for a host name for the new system and saves the result to the
102 new system's
103 .Pa rc.conf .
104 If
105 .Ev BSDINSTALL_CONFIGCURRENT
106 is set, also sets the host name of the current system.
107 .It Cm netconfig
108 Interactively configures network interfaces (first invoking
109 .Cm wlanconfig
110 on wireless interfaces), saving the result to the new system's
111 .Pa rc.conf
112 and
113 .Pa resolv.conf .
114 If
115 .Ev BSDINSTALL_CONFIGCURRENT
116 is set, also configures the network interfaces of the current system to match.
117 .It Cm autopart
118 Provides the installer's interactive guided disk partitioner for single-disk
119 installations.
120 Defaults to UFS.
121 .It Cm bootconfig
122 Detects an appropriate partition and installs UEFI boot loader files.
123 .It Cm zfsboot
124 Provides a ZFS-only automatic interactive disk partitioner.
125 Creates a single
126 .Ic zpool
127 with separate datasets for
128 .Pa /tmp ,
129 .Pa /usr ,
130 .Pa /usr/home ,
131 .Pa /usr/ports ,
132 .Pa /usr/src ,
133 and
134 .Pa /var .
135 Optionally can set up
136 .Xr geli 8
137 to encrypt the disk.
138 .It Cm partedit
139 Provides the installer's interactive manual disk partitioner with an interface
140 identical to
141 .Xr sade 8 .
142 Supports multiple disks as well as UFS, ZFS, and FAT file systems.
143 ZFS is set up with one pool and dataset per partition.
144 .It Cm scriptedpart Ar parameters
145 Sets up disks like
146 .Cm autopart
147 and
148 .Cm partedit ,
149 but non-interactively according to the disk setup specified in
150 .Ar parameters .
151 Each disk setup is specified by a three-part argument:
152 .Pp
153 .Ar disk
154 .Op Ar scheme
155 .Op Ar {partitions}
156 .Pp
157 Multiple disk setups are separated by semicolons.
158 The
159 .Ar disk
160 argument specifies the disk on which to operate (which will be erased),
161 or the special value
162 .Em DEFAULT ,
163 which will result in either a selection window (as in
164 .Cm autopart )
165 for the destination disk or, if there is only one possible disk, will
166 automatically select it.
167 The
168 .Ar scheme
169 argument specifies the
170 .Xr gpart 8
171 partition scheme to apply to the disk.
172 If
173 .Ar scheme
174 is unspecified,
175 .Cm scriptedpart
176 will apply the default bootable scheme on your platform.
177 The
178 .Ar partitions
179 argument is also optional and specifies how to partition
180 .Ar disk .
181 It consists of a comma-separated list of partitions to create enclosed in
182 curly braces.
183 Each partition declaration takes the form
184 .Pp
185 .Ar size
186 .Ar type
187 .Op Ar mount point
188 .Pp
189 .Ar size
190 specifies the partition size to create in bytes (K, M, and G suffixes
191 can be appended to specify kilobytes, megabytes, and gigabytes respectively),
192 while the
193 .Em auto
194 keyword causes the partition to take all the remaining space on the disk.
195 The
196 .Ar type
197 option chooses the
198 .Xr gpart 8
199 filesystem type, e.g., freebsd-ufs, freebsd-zfs, or freebsd-swap.
200 The optional
201 .Ar mount point
202 argument sets where the created partition is to be mounted in the installed
203 system.
204 As an example, a typical invocation looks like:
205 .Pp
206 bsdinstall scriptedpart ada0 { 20G freebsd-ufs /, 4G freebsd-swap, 20G freebsd-ufs /var, auto freebsd-ufs /usr }
207 .Pp
208 Note that the list of partitions should
209 .Em not
210 include boot partitions (e.g. EFI system partitions), which will be created automatically on whatever disk includes /.
211 .Pp
212 A shorter invocation to use the default partitioning (as
213 .Cm autopart
214 would have used) on the same disk:
215 .Pp
216 bsdinstall scriptedpart ada0
217 .Pp
218 or, even shorter:
219 .Pp
220 bsdinstall scriptedpart DEFAULT
221 .It Cm mount
222 Mounts the file systems previously configured by
223 .Cm autopart ,
224 .Cm partedit ,
225 or
226 .Cm scriptedpart
227 under
228 .Ev BSDINSTALL_CHROOT .
229 .It Cm distfetch
230 Fetches the distributions in
231 .Ev DISTRIBUTIONS
232 to
233 .Ev BSDINSTALL_DISTDIR
234 from
235 .Ev BSDINSTALL_DISTSITE .
236 .It Cm checksum
237 Verifies the checksums of the distributions listed in
238 .Ev DISTRIBUTIONS
239 against the distribution manifest.
240 .It Cm distextract
241 Extracts the distributions listed in
242 .Ev DISTRIBUTIONS
243 into
244 .Ev BSDINSTALL_CHROOT .
245 .It Cm rootpass
246 Interactively invokes
247 .Xr passwd 1
248 in the new system to set the root user's password.
249 .It Cm adduser
250 Interactively invokes
251 .Xr adduser 8
252 in the new system.
253 .It Cm time
254 Interactively sets the time, date, and time zone of the new system.
255 .It Cm services
256 Queries the user for the system daemons to begin at system startup,
257 writing the result into the new system's
258 .Pa rc.conf .
259 .It Cm entropy
260 Reads a small amount of data from
261 .Pa /dev/random
262 and stores it in a file in the new system's root directory.
263 .It Cm config
264 Installs the configuration files destined for the new system, e.g.,
265 .Xr rc.conf 5
266 fragments generated by
267 .Cm netconfig ,
268 etc.) onto the new system.
269 .El
270 .Sh ENVIRONMENT VARIABLES
271 The following environment variables control various aspects of the installation
272 process.
273 Many are used internally during installation and have reasonable default values
274 for most installation scenarios.
275 Others are set by various interactive user prompts, and can be usefully
276 overridden when making scripted or customized installers.
277 .Bl -tag -width ".Ev BSDINSTALL_DISTSITE"
278 .It Ev TMPDIR
279 The directory to use for temporary files.
280 Default:
281 .Dq Pa /tmp
282 .It Ev DISTRIBUTIONS
283 The set of distributions to install, e.g., "base.txz kernel.txz ports.txz".
284 Default: unset
285 .It Ev PARTITIONS
286 The partitioning of the disk onto which the system is being installed.
287 See
288 .Cm scriptedpart
289 of
290 the
291 .Sx TARGETS
292 section for format details. If this variable is unset, the installer will
293 use the default partitioning as in
294 .Cm autopart .
295 Default: unset
296 .It Ev BSDINSTALL_DISTDIR
297 The directory in which the distribution files can be found (or to which they
298 should be downloaded).
299 Default:
300 .Dq Pa /usr/freebsd-dist
301 .It Ev BSDINSTALL_DISTSITE
302 URL from which the distribution files should be downloaded if they are not
303 already present in the directory defined by
304 .Ev BSDINSTALL_DISTDIR .
305 This should be a full path to the files, including architecture and release
306 names.
307 Most targets, e.g.,
308 .Cm auto
309 and
310 .Cm jail ,
311 that prompt for a
312 .Fx
313 mirror will skip that step if this variable is already defined in the
314 environment.
315 Example:
316 .Pa ftp://ftp.freebsd.org/pub/FreeBSD/releases/powerpc/powerpc64/9.1-RELEASE
317 .It Ev BSDINSTALL_CHROOT
318 The directory into which the distribution files should be unpacked and the
319 directory at which the root file system of the new system should be mounted.
320 Default:
321 .Dq Pa /mnt
322 .It Ev BSDINSTALL_LOG
323 Path to a log file for the installation.
324 Default:
325 .Dq Pa $TMPDIR/bsdinstall_log
326 .It Ev BSDINSTALL_TMPETC
327 Directory where files destined for the new system's
328 .Pa /etc
329 will be stored until the
330 .Cm config
331 target is executed.
332 If this directory does not already exist, it will be created.
333 Default:
334 .Dq Pa $TMPDIR/bsdinstall_etc
335 .It Ev BSDINSTALL_TMPBOOT
336 Directory where files destined for the new system's
337 .Pa /boot
338 will be stored until the
339 .Cm config
340 target is executed.
341 If this directory does not already exist, it will be created.
342 Default:
343 .Dq Pa $TMPDIR/bsdinstall_boot
344 .It Ev ZFSBOOT_POOL_NAME
345 Name for the pool containing the base system.
346 Default:
347 .Dq zroot
348 .It Ev ZFSBOOT_POOL_CREATE_OPTIONS
349 Options to be used when creating the base system's pool.
350 Each option must be followed by the -O flag to be taken into consideration
351 or the pool will not be created due to errors using the command
352 .Cm zpool .
353 Default:
354 .Dq Li "-O compress=lz4 -O atime=off"
355 .It Ev ZFSBOOT_BEROOT_NAME
356 Name for the boot environment parent dataset.
357 This is a non-mountable dataset meant to be a parent dataset where different
358 boot environment are going to be created.
359 Default:
360 .Dq ROOT
361 .It Ev ZFSBOOT_BOOTFS_NAME
362 Name for the primary boot environment, which will be the default boot
363 environment for the system.
364 Default:
365 .Dq default
366 .It Ev ZFSBOOT_VDEV_TYPE
367 The type of pool to be created for the base system.
368 This variable can take one of this values: stripe (No redundancy),
369 mirror (n-Way mirroring), raid10 (RAID 1+0 - n x 2-Way Mirrors),
370 raidz1 (RAID-Z1 - Single Redundancy RAID), raidz2 (RAID-Z2 - Double Redundancy RAID)
371 or raidz3 (RAID-Z3 Triple Redundancy RAID).
372 Default:
373 .Dq stripe
374 .It Ev ZFSBOOT_FORCE_4K_SECTORS
375 Indicates either the pool will use 4K or 512 sectors.
376 If this variable is not empty, 4K sectors will be used.
377 Default:
378 .Dq 1
379 .It Ev ZFSBOOT_GELI_ENCRYPTION
380 If this variable is not empty, it will use
381 .Xr geli 8
382 to encrypt the root pool, enabling automatically the
383 .Ev ZFSBOOT_BOOT_POOL
384 variable.
385 Default:
386 .Dq ""
387 .It Ev ZFSBOOT_GELI_KEY_FILE
388 Path to the
389 .Xr geli 8
390 keyfile used to encrypt the pool where the base system is stored.
391 Default:
392 .Dq Pa /boot/encryption.key
393 .It Ev ZFSBOOT_BOOT_POOL
394 If set a separated boot pool will be created for the kernel of the
395 system and
396 .Xr loader 8 .
397 Default: unset
398 .It Ev ZFSBOOT_BOOT_POOL_CREATE_OPTIONS
399 Options to use when creating the boot pool, when enabled (See
400 .Ev ZFSBOOT_BOOT_POOL ).
401 Default: unset
402 .It Ev ZFSBOOT_BOOT_POOL_NAME
403 Name for the optional boot pool when it is enabled, (See
404 .Ev ZFSBOOT_BOOT_POOL ).
405 Default:
406 .Dq bootpool
407 .It Ev ZFSBOOT_BOOT_POOL_SIZE
408 Size of the boot pool when it is enabled (See
409 .Ev ZFSBOOT_BOOT_POOL ).
410 Default:
411 .Dq 2g
412 .It Ev ZFSBOOT_DISKS
413 Disks to be used for the base system, including the boot pool.
414 This variable must only be used on a scripted installation.
415 See
416 .Sx SCRIPTING
417 for more information.
418 Default: unset
419 .It Ev ZFSBOOT_SWAP_SIZE
420 Size of the swap partition on each block device.
421 This variable will be passed to
422 .Xr gpart 8 ;
423 which supports SI unit suffixes.
424 Default:
425 .Dq 2g
426 .It Ev ZFSBOOT_SWAP_ENCRYPTION
427 If set, enables the encryption of the swap partition using
428 .Xr geli 8 .
429 Default: ""
430 .It Ev ZFSBOOT_SWAP_MIRROR
431 If set, enables a swap mirroring using
432 .Xr gmirror 8 .
433 Default:
434 unset
435 .It Ev ZFSBOOT_DATASETS
436 ZFS datasets to be created on the root zpool, it requires the
437 following datasets:
438 .Pa /tmp ,
439 .Pa /var/tmp ,
440 .Pa /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME .
441 See
442 .Sx ZFS DATASETS
443 for more information about who to write this variable and to
444 take a look into the default value of it.
445 .It Ev ZFSBOOT_CONFIRM_LAYOUT
446 If set and the installation is interactive, allow the user to confirm
447 the layout before continuing with the installation.
448 Default:
449 .Dq 1
450 .El
451 .Sh SCRIPTING
452 .Nm
453 supports unattended, or minimally-attended, installations using scripting.
454 This can be used with either modified physical installation media or with
455 .Xr diskless 8
456 installations over the network; information on preparing such media can be
457 found in
458 .Sx BUILDING AUTOMATIC INSTALL MEDIA
459 .Pp
460 Scripted installations follow an essentially identical path to interactive
461 installations, though with some minor feature differences (for example,
462 scripted installations do not support fetching of remote distribution files
463 since scripted installations normally install the same files and the distributions
464 can be added directly to the installation media).
465 .Nm
466 scripts consist of two parts: a
467 .Em preamble
468 and a
469 .Em setup script .
470 The preamble sets up the options for the installation (how to partition the
471 disk[s], which distributions to install, etc.) and the optional second part is
472 a shell script run under
473 .Xr chroot 8
474 in the newly installed system before
475 .Nm
476 exits.
477 The two parts are separated by the usual script header (#!), which also sets
478 the interpreter for the setup script.
479 .Pp
480 A typical bsdinstall script, using the default filesystem layout and the UFS
481 filesystem, looks like this:
482 .Bd -literal -offset indent
483 PARTITIONS=DEFAULT
484 DISTRIBUTIONS="kernel.txz base.txz"
485
486 #!/bin/sh
487 sysrc ifconfig_DEFAULT=DHCP
488 sysrc sshd_enable=YES
489 pkg install puppet
490 .Ed
491 .Pp
492 For a scripted installation involving a ZFS pool spanning multiple disks,
493 the script instead looks like this:
494 .Bd -literal -offset indent
495 DISTRIBUTIONS="kernel.txz base.txz"
496 export ZFSBOOT_VDEV_TYPE=stripe
497 export ZFSBOOT_DISKS="ada0 ada1"
498 export nonInteractive="YES"
499
500 #!/bin/sh
501 echo "ifconfig_DEFAULT=DHCP" >> /etc/rc.conf
502 echo "sshd_enable=YES" >> /etc/rc.conf
503 pkg install puppet
504 .Ed
505 .Pp
506 On
507 .Fx
508 release media, such a script placed at
509 .Pa /etc/installerconfig
510 will be run at boot time and the system will be rebooted automatically after
511 the installation has completed.
512 This can be used for unattended network installation of new systems; see
513 .Xr diskless 8
514 for details.
515 .Ss PREAMBLE
516 The preamble consists of installer settings.
517 These control global installation parameters (see
518 .Sx ENVIRONMENT VARIABLES )
519 as well as disk partitioning.
520 The preamble is interpreted as a
521 .Xr sh 1
522 script run at the very beginning of the install.
523 If more complicated behavior than setting these variables is desired,
524 arbitrary commands can be run here to extend the installer.
525 In addition to the variables in
526 .Sx ENVIRONMENT VARIABLES ,
527 in particular
528 .Ev DISTRIBUTIONS ,
529 the preamble can contain a variable
530 .Ev PARTITIONS
531 which is passed to the
532 .Cm scriptedpart
533 target to control disk setup.
534 .Pp
535 Alternatively,
536 to use
537 .Cm zfsboot
538 instead of
539 .Cm partedit ,
540 the preamble can contain the variable
541 .Ev ZFSBOOT_DATASETS
542 instead of
543 .Ev PARTITIONS
544 (see below).
545 If using .Cm zfsboot, the variables
546 .Ev ZFSBOOT_DISKS
547 and
548 .Ev ZFSBOOT_VDEV_TYPE
549 must be set to create the pool of disks for the base system.
550 Usually, for a mirrored booting disk, this two variables looks like this:
551 .Bd -literal -offset indent
552 ZFSBOOT_DISKS="ada0 ada1"
553 ZFSBOOT_VDEV_TYPE=mirror
554 .Ed
555 .Pp
556 Remember to export all the variables for the
557 .Cm zfsboot
558 command, otherwise installation will fail.
559 .Ss SETUP SCRIPT
560 Following the preamble is an optional shell script, beginning with a #!
561 declaration.
562 This script will be run at the end of the installation process inside a
563 .Xr chroot 8
564 environment in the newly installed system and can be used to set up
565 configuration files, install packages, etc.
566 Note that newly configured system services, e.g., networking have not
567 been started in the installed system at this time and only installation
568 host services are available.
569 .Ss ZFS DATASETS
570 If using
571 .Cm zfsboot
572 in an installation script, the
573 .Cm zfsboot
574 partitioning tool takes the
575 .Ev ZFSBOOT_DATASETS
576 variable to create the ZFS datasets on the base system.
577 This variable definition can become large if the pool contains many datasets.
578 The default value of the
579 .Ev ZFSBOOT_DATASETS
580 is:
581 .Bd -literal -offset indent
582 # DATASET       OPTIONS (comma or space separated; or both)
583
584 # Boot Environment [BE] root and default boot dataset
585 /$ZFSBOOT_BEROOT_NAME                           mountpoint=none
586 /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME      mountpoint=/
587
588 # Compress /tmp, allow exec but not setuid
589 /tmp            mountpoint=/tmp,exec=on,setuid=off
590
591 # Do not mount /usr so that 'base' files go to the BEROOT
592 /usr            mountpoint=/usr,canmount=off
593
594 # Home directories separated so they are common to all BEs
595 /usr/home       # NB: /home is a symlink to /usr/home
596
597 # Ports tree
598 /usr/ports      setuid=off
599
600 # Source tree (compressed)
601 /usr/src
602
603 # Create /var and friends
604 /var            mountpoint=/var,canmount=off
605 /var/audit      exec=off,setuid=off
606 /var/crash      exec=off,setuid=off
607 /var/log        exec=off,setuid=off
608 /var/mail       atime=on
609 /var/tmp        setuid=off
610 .Ed
611 .Pp
612 The first column is the name of the dataset to be created as part of the
613 .Ev ZFSBOOT_POOL_NAME
614 pool and the remainder of each line contains the options to be set on each dataset.
615 If multiple options are given, they can be separated by either commas or whitespace;
616 everything following a pound/hash character is ignored as a comment.
617 .Ss BUILDING AUTOMATIC INSTALL MEDIA
618 If building automatic install media, use tar to extract a release ISO:
619 .Dl mkdir release-media
620 .Dl tar xvf -C release-media FreeBSD-13.0-RELEASE-amd64-disc1.iso
621 .Pp
622 Then place a script as above in
623 .Pa etc/installerconfig
624 .Pp
625 This directory can then be used directly as an NFS root for
626 .Xr diskless 8
627 installations or it can be rebuilt into an ISO image using the release scripts in
628 .Pa /usr/src/release .
629 For example, on amd64:
630 .Dl sh /usr/src/release/amd64/mkisoimages.sh -b '13_0_RELEASE_AMD64_CD' output.iso release-media
631 .Sh HISTORY
632 This version of
633 .Nm
634 first appeared in
635 .Fx 9.0 .
636 .Sh AUTHORS
637 .An Nathan Whitehorn Aq Mt nwhitehorn@FreeBSD.org
638 .An Devin Teske Aq Mt dteske@FreeBSD.org
639 .An Allan Jude Aq Mt allanjude@FreeBSD.org