diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8 index c58f6636493a..e9f7dd808f73 100644 --- a/usr.sbin/bsdinstall/bsdinstall.8 +++ b/usr.sbin/bsdinstall/bsdinstall.8 @@ -1,606 +1,618 @@ .\"- .\" Copyright (c) 2011-2013 Nathan Whitehorn All rights reserved. .\" Copyright (c) 2018 Roberto Fernandez Cueto .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE .\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd March 22, 2021 +.Dd March 26, 2021 .Dt BSDINSTALL 8 .Os .Sh NAME .Nm bsdinstall .Nd system installer .Sh SYNOPSIS .Nm .Op Ar options .Op Ar target .Op Ar ... .Sh DESCRIPTION .Nm is used for installation of new systems, both for system setup from installation media, e.g., CD-ROMs, and for use on live systems to prepare VM images and jails. .Pp Much like .Xr make 1 , Nm takes a target and possible parameters of the target as arguments. If invoked with no arguments, it will invoke the .Cm auto target, which provides a standard interactive installation, invoking the others in sequence. To perform a scripted installation, these subtargets can be invoked separately by an installation script. .Sh OPTIONS .Nm supports the following options, global to all targets: .Bl -tag -width indent+ .It Fl D Ar file Provide a path for the installation log file .Pq overrides Ev BSDINSTALL_LOG . See .Sx ENVIRONMENT VARIABLES for more information on .Ev BSDINSTALL_LOG . .El .Sh TARGETS Most of the following targets are only useful for scripting the installer. For interactive use, most users will be interested only in the .Cm auto , .Cm jail , and .Cm script targets. .Bl -tag -width ".Cm jail Ar destination" .It Cm auto Run the standard interactive installation, including disk partitioning. .It Cm jail Ar destination Sets up a new chroot system at .Pa destination , suitable for use with .Xr jail 8 . Behavior is generally similar to .Cm auto , except that disk partitioning and network setup are skipped and a kernel is not installed into the new system. .It Cm script Ar script Runs the installation script at .Pa script . See .Sx SCRIPTING for more information on this target. .It Cm keymap If the current controlling TTY is a .Xr syscons 4 or .Xr vt 4 console, asks the user to set the current keymap, and saves the result to the new system's .Pa rc.conf . .It Cm hostname Prompts the user for a host name for the new system and saves the result to the new system's .Pa rc.conf . If .Ev BSDINSTALL_CONFIGCURRENT is set, also sets the host name of the current system. .It Cm netconfig Interactively configures network interfaces (first invoking .Cm wlanconfig on wireless interfaces), saving the result to the new system's .Pa rc.conf and .Pa resolv.conf . If .Ev BSDINSTALL_CONFIGCURRENT is set, also configures the network interfaces of the current system to match. .It Cm autopart Provides the installer's interactive guided disk partitioner for single-disk installations. Defaults to UFS. .It Cm bootconfig Detects an appropriate partition and installs UEFI boot loader files. .It Cm zfsboot Provides a ZFS-only automatic interactive disk partitioner. Creates a single .Ic zpool with separate datasets for .Pa /tmp , .Pa /usr , .Pa /usr/home , .Pa /usr/ports , .Pa /usr/src , and .Pa /var . Optionally can set up .Xr geli 8 to encrypt the disk. .It Cm partedit Provides the installer's interactive manual disk partitioner with an interface identical to .Xr sade 8 . Supports multiple disks as well as UFS, ZFS, and FAT file systems. ZFS is set up with one pool and dataset per partition. .It Cm scriptedpart Ar parameters Sets up disks like .Cm autopart and .Cm partedit , but non-interactively according to the disk setup specified in .Ar parameters . Each disk setup is specified by a three-part argument: .Pp .Ar disk .Op Ar scheme .Op Ar {partitions} .Pp Multiple disk setups are separated by semicolons. The .Ar disk argument specifies the disk on which to operate (which will be erased), -while the +or the special value +.Em DEFAULT , +which will result in either a selection window (as in +.Cm autopart ) +for the destination disk or, if there is only one possible disk, will +automatically select it. +The .Ar scheme argument specifies the .Xr gpart 8 partition scheme to apply to the disk. If .Ar scheme is unspecified, .Cm scriptedpart will apply the default bootable scheme on your platform. The .Ar partitions argument is also optional and specifies how to partition .Ar disk . It consists of a comma-separated list of partitions to create enclosed in curly braces. Each partition declaration takes the form .Pp .Ar size .Ar type .Op Ar mount point .Pp .Ar size specifies the partition size to create in bytes (K, M, and G suffixes can be appended to specify kilobytes, megabytes, and gigabytes respectively), while the .Em auto keyword causes the partition to take all the remaining space on the disk. The .Ar type option chooses the .Xr gpart 8 filesystem type, e.g., freebsd-ufs, freebsd-zfs, or freebsd-swap. The optional .Ar mount point argument sets where the created partition is to be mounted in the installed system. As an example, a typical invocation looks like: .Pp bsdinstall scriptedpart ada0 { 20G freebsd-ufs /, 4G freebsd-swap, 20G freebsd-ufs /var, auto freebsd-ufs /usr } .Pp Note that the list of partitions should .Em not include boot partitions (e.g. EFI system partitions), which will be created automatically on whatever disk includes /. .Pp A shorter invocation to use the default partitioning (as .Cm autopart would have used) on the same disk: .Pp bsdinstall scriptedpart ada0 +.Pp +or, even shorter: +.Pp +bsdinstall scriptedpart DEFAULT .It Cm mount Mounts the file systems previously configured by .Cm autopart , .Cm partedit , or .Cm scriptedpart under .Ev BSDINSTALL_CHROOT . .It Cm distfetch Fetches the distributions in .Ev DISTRIBUTIONS to .Ev BSDINSTALL_DISTDIR from .Ev BSDINSTALL_DISTSITE . .It Cm checksum Verifies the checksums of the distributions listed in .Ev DISTRIBUTIONS against the distribution manifest. .It Cm distextract Extracts the distributions listed in .Ev DISTRIBUTIONS into .Ev BSDINSTALL_CHROOT . .It Cm rootpass Interactively invokes .Xr passwd 1 in the new system to set the root user's password. .It Cm adduser Interactively invokes .Xr adduser 8 in the new system. .It Cm time Interactively sets the time, date, and time zone of the new system. .It Cm services Queries the user for the system daemons to begin at system startup, writing the result into the new system's .Pa rc.conf . .It Cm entropy Reads a small amount of data from .Pa /dev/random and stores it in a file in the new system's root directory. .It Cm config Installs the configuration files destined for the new system, e.g., .Xr rc.conf 5 fragments generated by .Cm netconfig , etc.) onto the new system. .El .Sh ENVIRONMENT VARIABLES The following environment variables control various aspects of the installation process. Many are used internally during installation and have reasonable default values for most installation scenarios. Others are set by various interactive user prompts, and can be usefully overridden when making scripted or customized installers. .Bl -tag -width ".Ev BSDINSTALL_DISTSITE" .It Ev TMPDIR The directory to use for temporary files. Default: .Dq Pa /tmp .It Ev DISTRIBUTIONS The set of distributions to install, e.g., "base.txz kernel.txz ports.txz". Default: unset .It Ev PARTITIONS The partitioning of the disk onto which the system is being installed. See .Cm scriptedpart of the .Sx TARGETS -section for format details. +section for format details. If this variable is unset, the installer will +use the default partitioning as in +.Cm autopart . Default: unset .It Ev BSDINSTALL_DISTDIR The directory in which the distribution files can be found (or to which they should be downloaded). Default: .Dq Pa /usr/freebsd-dist .It Ev BSDINSTALL_DISTSITE URL from which the distribution files should be downloaded if they are not already present in the directory defined by .Ev BSDINSTALL_DISTDIR . This should be a full path to the files, including architecture and release names. Most targets, e.g., .Cm auto and .Cm jail , that prompt for a .Fx mirror will skip that step if this variable is already defined in the environment. Example: .Pa ftp://ftp.freebsd.org/pub/FreeBSD/releases/powerpc/powerpc64/9.1-RELEASE .It Ev BSDINSTALL_CHROOT The directory into which the distribution files should be unpacked and the directory at which the root file system of the new system should be mounted. Default: .Dq Pa /mnt .It Ev BSDINSTALL_LOG Path to a log file for the installation. Default: .Dq Pa $TMPDIR/bsdinstall_log .It Ev BSDINSTALL_TMPETC Directory where files destined for the new system's .Pa /etc will be stored until the .Cm config target is executed. If this directory does not already exist, it will be created. Default: .Dq Pa $TMPDIR/bsdinstall_etc .It Ev BSDINSTALL_TMPBOOT Directory where files destined for the new system's .Pa /boot will be stored until the .Cm config target is executed. If this directory does not already exist, it will be created. Default: .Dq Pa $TMPDIR/bsdinstall_boot .It Ev ZFSBOOT_POOL_NAME Name for the pool containing the base system. Default: .Dq zroot .It Ev ZFSBOOT_POOL_CREATE_OPTIONS Options to be used when creating the base system's pool. Each option must be followed by the -O flag to be taken into consideration or the pool will not be created due to errors using the command .Cm zpool . Default: .Dq Li "-O compress=lz4 -O atime=off" .It Ev ZFSBOOT_BEROOT_NAME Name for the boot environment parent dataset. This is a non-mountable dataset meant to be a parent dataset where different boot environment are going to be created. Default: .Dq ROOT .It Ev ZFSBOOT_BOOTFS_NAME Name for the primary boot environment, which will be the default boot environment for the system. Default: .Dq default .It Ev ZFSBOOT_VDEV_TYPE The type of pool to be created for the base system. This variable can take one of this values: stripe (No redundancy), mirror (n-Way mirroring), raid10 (RAID 1+0 - n x 2-Way Mirrors), raidz1 (RAID-Z1 - Single Redundancy RAID), raidz2 (RAID-Z2 - Double Redundancy RAID) or raidz3 (RAID-Z3 Triple Redundancy RAID). Default: .Dq stripe .It Ev ZFSBOOT_FORCE_4K_SECTORS Indicates either the pool will use 4K or 512 sectors. If this variable is not empty, 4K sectors will be used. Default: .Dq 1 .It Ev ZFSBOOT_GELI_ENCRYPTION If this variable is not empty, it will use .Xr geli 8 to encrypt the root pool, enabling automatically the .Ev ZFSBOOT_BOOT_POOL variable. Default: .Dq "" .It Ev ZFSBOOT_GELI_KEY_FILE Path to the .Xr geli 8 keyfile used to encrypt the pool where the base system is stored. Default: .Dq Pa /boot/encryption.key .It Ev ZFSBOOT_BOOT_POOL If set a separated boot pool will be created for the kernel of the system and .Xr loader 8 . Default: unset .It Ev ZFSBOOT_BOOT_POOL_CREATE_OPTIONS Options to use when creating the boot pool, when enabled (See .Ev ZFSBOOT_BOOT_POOL ). Default: unset .It Ev ZFSBOOT_BOOT_POOL_NAME Name for the optional boot pool when it is enabled, (See .Ev ZFSBOOT_BOOT_POOL ). Default: .Dq bootpool .It Ev ZFSBOOT_BOOT_POOL_SIZE Size of the boot pool when it is enabled (See .Ev ZFSBOOT_BOOT_POOL ). Default: .Dq 2g .It Ev ZFSBOOT_DISKS Disks to be used for the base system, including the boot pool. This variable must only be used on a scripted installation. See .Sx SCRIPTING for more information. Default: unset .It Ev ZFSBOOT_SWAP_SIZE Size of the swap partition on each block device. This variable will be passed to .Xr gpart 8 ; which supports SI unit suffixes. Default: .Dq 2g .It Ev ZFSBOOT_SWAP_ENCRYPTION If set, enables the encryption of the swap partition using .Xr geli 8 . Default: "" .It Ev ZFSBOOT_SWAP_MIRROR If set, enables a swap mirroring using .Xr gmirror 8 . Default: unset .It Ev ZFSBOOT_DATASETS ZFS datasets to be created on the root zpool, it requires the following datasets: .Pa /tmp , .Pa /var/tmp , .Pa /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME . See .Sx ZFS DATASETS for more information about who to write this variable and to take a look into the default value of it. .It Ev ZFSBOOT_CONFIRM_LAYOUT If set and the installation is interactive, allow the user to confirm the layout before continuing with the installation. Default: .Dq 1 .El .Sh SCRIPTING .Nm scripts consist of two parts: a .Em preamble and a .Em setup script . The preamble sets up the options for the installation (how to partition the disk[s], which distributions to install, etc.) and the optional second part is a shell script run under .Xr chroot 8 in the newly installed system before .Nm exits. The two parts are separated by the usual script header (#!), which also sets the interpreter for the setup script. .Pp A typical bsdinstall script looks like this: .Bd -literal -offset indent -PARTITIONS=ada0 +PARTITIONS=DEFAULT DISTRIBUTIONS="kernel.txz base.txz" #!/bin/sh sysrc ifconfig_DEFAULT=DHCP sysrc sshd_enable=YES pkg install puppet .Ed .Pp For a ZFS scripted installation, the script looks like this: .Bd -literal -offset indent DISTRIBUTIONS="kernel.txz base.txz" export ZFSBOOT_VDEV_TYPE=stripe export ZFSBOOT_DISKS=ada0 export nonInteractive="YES" #!/bin/sh echo "ifconfig_DEFAULT=DHCP" >> /etc/rc.conf echo "sshd_enable=YES" >> /etc/rc.conf pkg install puppet .Ed .Pp On .Fx release media, such a script placed at .Pa /etc/installerconfig will be run at boot time and the system will be rebooted automatically after the installation has completed. This can be used for unattended network installation of new systems; see .Xr diskless 8 for details. .Ss PREAMBLE The preamble consists of installer settings. These control global installation parameters (see .Sx ENVIRONMENT VARIABLES ) as well as disk partitioning. The preamble is interpreted as a .Xr sh 1 script run at the very beginning of the install. If more complicated behavior than setting these variables is desired, arbitrary commands can be run here to extend the installer. In addition to the variables in .Sx ENVIRONMENT VARIABLES , in particular .Ev DISTRIBUTIONS , the preamble can contain a variable .Ev PARTITIONS which is passed to the .Cm scriptedpart target to control disk setup. Alternatively, to use .Cm zfsboot instead of .Cm partedit , the preamble can contain the variable .Ev ZFSBOOT_DATASETS instead of .Ev PARTITIONS , and setting the variables .Ev ZFSBOOT_DISKS and .Ev ZFSBOOT_VDEV_TYPE to create the pool of disks for the base system. Usually, for a mirrored booting disk, this two variables looks like this: .Bd -literal -offset indent ZFSBOOT_DISKS="ada0 ada1" ZFSBOOT_VDEV_TYPE=mirror .Ed .Pp Remember to export all the variables for the .Cm zfsboot command, otherwise it will not get set. .Ss SETUP SCRIPT Following the preamble is an optional shell script, beginning with a #! declaration. This script will be run at the end of the installation process inside a .Xr chroot 8 environment in the newly installed system and can be used to set up configuration files, install packages, etc. Note that newly configured system services, e.g., networking have not been started in the installed system at this time and only installation host services are available. .Ss ZFS DATASETS The .Cm zfsboot partitioning takes the .Ev ZFSBOOT_DATASETS variable to create the datasets on the base system. This variable can get pretty huge if the pool contains a lot of datasets. The default value of the .Ev ZFSBOOT_DATASETS looks like this: .Bd -literal -offset indent # DATASET OPTIONS (comma or space separated; or both) # Boot Environment [BE] root and default boot dataset /$ZFSBOOT_BEROOT_NAME mountpoint=none /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ # Compress /tmp, allow exec but not setuid /tmp mountpoint=/tmp,exec=on,setuid=off # Do not mount /usr so that 'base' files go to the BEROOT /usr mountpoint=/usr,canmount=off # Home directories separated so they are common to all BEs /usr/home # NB: /home is a symlink to /usr/home # Ports tree /usr/ports setuid=off # Source tree (compressed) /usr/src # Create /var and friends /var mountpoint=/var,canmount=off /var/audit exec=off,setuid=off /var/crash exec=off,setuid=off /var/log exec=off,setuid=off /var/mail atime=on /var/tmp setuid=off .Ed .Pp The first column if the dataset to be created on the top of the .Ev ZFSBOOT_POOL_NAME and the rest of the columns are the options to be set on each dataset. The options must be written on a coma or space separated list, or both. And everything behind a pound/hash character is ignored as a comment. .Ss BUILDING AUTOMATIC INSTALL MEDIA If building automatic install media, use tar to extract a release ISO: .Dl mkdir release-media .Dl tar xvf -C release-media FreeBSD-13.0-RELEASE-amd64-disc1.iso .Pp Then place a script as above in .Pa etc/installerconfig .Pp This directory can then be used directly as an NFS root for .Xr diskless 8 installations or it can be rebuilt into an ISO image using the release scripts in .Pa /usr/src/release . For example, on amd64: .Dl sh /usr/src/release/amd64/mkisoimages.sh -b '13_0_RELEASE_AMD64_CD' output.iso release-media .Sh HISTORY This version of .Nm first appeared in .Fx 9.0 . .Sh AUTHORS .An Nathan Whitehorn Aq Mt nwhitehorn@FreeBSD.org diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c index 3160e1f049ea..9f7158a4801e 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -1,368 +1,367 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011 Nathan Whitehorn * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include "partedit.h" #define MIN_FREE_SPACE (1024*1024*1024) /* 1 GB */ #define SWAP_SIZE(available) MIN(available/20, 4*1024*1024*1024LL) -static char *boot_disk(struct gmesh *mesh); static char *wizard_partition(struct gmesh *mesh, const char *disk); int part_wizard(const char *fsreq) { char *disk, *schemeroot; const char *fstype; struct gmesh mesh; int error; if (fsreq != NULL) fstype = fsreq; else fstype = "ufs"; startwizard: error = geom_gettree(&mesh); dlg_put_backtitle(); error = geom_gettree(&mesh); - disk = boot_disk(&mesh); + disk = boot_disk_select(&mesh); if (disk == NULL) return (1); dlg_clear(); dlg_put_backtitle(); schemeroot = wizard_partition(&mesh, disk); free(disk); if (schemeroot == NULL) return (1); geom_deletetree(&mesh); dlg_clear(); dlg_put_backtitle(); error = geom_gettree(&mesh); error = wizard_makeparts(&mesh, schemeroot, fstype, 1); if (error) goto startwizard; free(schemeroot); geom_deletetree(&mesh); return (0); } -static char * -boot_disk(struct gmesh *mesh) +char * +boot_disk_select(struct gmesh *mesh) { struct gclass *classp; struct gconfig *gc; struct ggeom *gp; struct gprovider *pp; DIALOG_LISTITEM *disks = NULL; const char *type, *desc; char diskdesc[512]; char *chosen; int i, err, selected, n = 0; LIST_FOREACH(classp, &mesh->lg_class, lg_class) { if (strcmp(classp->lg_name, "DISK") != 0 && strcmp(classp->lg_name, "RAID") != 0 && strcmp(classp->lg_name, "MD") != 0) continue; LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { if (LIST_EMPTY(&gp->lg_provider)) continue; LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { desc = type = NULL; LIST_FOREACH(gc, &pp->lg_config, lg_config) { if (strcmp(gc->lg_name, "type") == 0) type = gc->lg_val; if (strcmp(gc->lg_name, "descr") == 0) desc = gc->lg_val; } /* Skip swap-backed md and WORM devices */ if (strcmp(classp->lg_name, "MD") == 0 && type != NULL && strcmp(type, "swap") == 0) continue; if (strncmp(pp->lg_name, "cd", 2) == 0) continue; disks = realloc(disks, (++n)*sizeof(disks[0])); disks[n-1].name = pp->lg_name; humanize_number(diskdesc, 7, pp->lg_mediasize, "B", HN_AUTOSCALE, HN_DECIMAL); if (strncmp(pp->lg_name, "ad", 2) == 0) strcat(diskdesc, " ATA Hard Disk"); else if (strncmp(pp->lg_name, "md", 2) == 0) strcat(diskdesc, " Memory Disk"); else strcat(diskdesc, " Disk"); if (desc != NULL) snprintf(diskdesc, sizeof(diskdesc), "%s <%s>", diskdesc, desc); disks[n-1].text = strdup(diskdesc); disks[n-1].help = NULL; disks[n-1].state = 0; } } } if (n > 1) { err = dlg_menu("Partitioning", "Select the disk on which to install FreeBSD.", 0, 0, 0, n, disks, &selected, NULL); chosen = (err == 0) ? strdup(disks[selected].name) : NULL; } else if (n == 1) { chosen = strdup(disks[0].name); } else { chosen = NULL; } for (i = 0; i < n; i++) free(disks[i].text); return (chosen); } static struct gprovider * provider_for_name(struct gmesh *mesh, const char *name) { struct gclass *classp; struct gprovider *pp = NULL; struct ggeom *gp; LIST_FOREACH(classp, &mesh->lg_class, lg_class) { LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { if (LIST_EMPTY(&gp->lg_provider)) continue; LIST_FOREACH(pp, &gp->lg_provider, lg_provider) if (strcmp(pp->lg_name, name) == 0) break; if (pp != NULL) break; } if (pp != NULL) break; } return (pp); } static char * wizard_partition(struct gmesh *mesh, const char *disk) { struct gclass *classp; struct ggeom *gpart = NULL; struct gconfig *gc; char *retval = NULL; const char *scheme = NULL; char message[512]; int choice; LIST_FOREACH(classp, &mesh->lg_class, lg_class) if (strcmp(classp->lg_name, "PART") == 0) break; if (classp != NULL) { LIST_FOREACH(gpart, &classp->lg_geom, lg_geom) if (strcmp(gpart->lg_name, disk) == 0) break; } if (gpart != NULL) { LIST_FOREACH(gc, &gpart->lg_config, lg_config) { if (strcmp(gc->lg_name, "scheme") == 0) { scheme = gc->lg_val; break; } } } /* Treat uncommitted scheme deletions as no scheme */ if (scheme != NULL && strcmp(scheme, "(none)") == 0) scheme = NULL; query: dialog_vars.yes_label = "Entire Disk"; dialog_vars.no_label = "Partition"; if (gpart != NULL) dialog_vars.defaultno = TRUE; snprintf(message, sizeof(message), "Would you like to use this entire " "disk (%s) for FreeBSD or partition it to share it with other " "operating systems? Using the entire disk will erase any data " "currently stored there.", disk); choice = dialog_yesno("Partition", message, 0, 0); dialog_vars.yes_label = NULL; dialog_vars.no_label = NULL; dialog_vars.defaultno = FALSE; if (choice == 1 && scheme != NULL && !is_scheme_bootable(scheme)) { char warning[512]; int subchoice; sprintf(warning, "The existing partition scheme on this " "disk (%s) is not bootable on this platform. To install " "FreeBSD, it must be repartitioned. This will destroy all " "data on the disk. Are you sure you want to proceed?", scheme); subchoice = dialog_yesno("Non-bootable Disk", warning, 0, 0); if (subchoice != 0) goto query; gpart_destroy(gpart); scheme = choose_part_type(default_scheme()); if (scheme == NULL) return NULL; gpart_partition(disk, scheme); } if (scheme == NULL || choice == 0) { if (gpart != NULL && scheme != NULL) { /* Erase partitioned disk */ choice = dialog_yesno("Confirmation", "This will erase " "the disk. Are you sure you want to proceed?", 0, 0); if (choice != 0) goto query; gpart_destroy(gpart); } scheme = choose_part_type(default_scheme()); if (scheme == NULL) return NULL; gpart_partition(disk, scheme); } if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; geom_gettree(&submesh); gpart_create(provider_for_name(&submesh, disk), "freebsd", NULL, NULL, &retval, choice /* Non-interactive for "Entire Disk" */); geom_deletetree(&submesh); } else { retval = strdup(disk); } return (retval); } int wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, int interactive) { struct gclass *classp; struct ggeom *gp; struct gprovider *pp; char *fsnames[] = {"freebsd-ufs", "freebsd-zfs"}; char *fsname; struct gmesh submesh; char swapsizestr[10], rootsizestr[10]; intmax_t swapsize, available; int retval; if (strcmp(fstype, "zfs") == 0) { fsname = fsnames[1]; } else { /* default to UFS */ fsname = fsnames[0]; } LIST_FOREACH(classp, &mesh->lg_class, lg_class) if (strcmp(classp->lg_name, "PART") == 0) break; LIST_FOREACH(gp, &classp->lg_geom, lg_geom) if (strcmp(gp->lg_name, disk) == 0) break; pp = provider_for_name(mesh, disk); available = gpart_max_free(gp, NULL)*pp->lg_sectorsize; if (interactive && available < MIN_FREE_SPACE) { char availablestr[10], neededstr[10], message[512]; humanize_number(availablestr, 7, available, "B", HN_AUTOSCALE, HN_DECIMAL); humanize_number(neededstr, 7, MIN_FREE_SPACE, "B", HN_AUTOSCALE, HN_DECIMAL); sprintf(message, "There is not enough free space on %s to " "install FreeBSD (%s free, %s required). Would you like " "to choose another disk or to open the partition editor?", disk, availablestr, neededstr); dialog_vars.yes_label = "Another Disk"; dialog_vars.no_label = "Editor"; retval = dialog_yesno("Warning", message, 0, 0); dialog_vars.yes_label = NULL; dialog_vars.no_label = NULL; return (!retval); /* Editor -> return 0 */ } swapsize = SWAP_SIZE(available); humanize_number(swapsizestr, 7, swapsize, "B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); humanize_number(rootsizestr, 7, available - swapsize - 1024*1024, "B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); geom_gettree(&submesh); pp = provider_for_name(&submesh, disk); gpart_create(pp, fsname, rootsizestr, "/", NULL, 0); geom_deletetree(&submesh); geom_gettree(&submesh); pp = provider_for_name(&submesh, disk); gpart_create(pp, "freebsd-swap", swapsizestr, NULL, NULL, 0); geom_deletetree(&submesh); return (0); } diff --git a/usr.sbin/bsdinstall/partedit/partedit.h b/usr.sbin/bsdinstall/partedit/partedit.h index e989decc2359..20d2047c1408 100644 --- a/usr.sbin/bsdinstall/partedit/partedit.h +++ b/usr.sbin/bsdinstall/partedit/partedit.h @@ -1,109 +1,110 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011 Nathan Whitehorn * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _PARTEDIT_PARTEDIT_H #define _PARTEDIT_PARTEDIT_H #include #include #include struct gprovider; struct gmesh; struct ggeom; extern int tmpdfd; TAILQ_HEAD(pmetadata_head, partition_metadata); extern struct pmetadata_head part_metadata; struct partition_metadata { char *name; /* name of this partition, as in GEOM */ struct fstab *fstab; /* fstab data for this partition */ char *newfs; /* shell command to initialize partition */ int bootcode; TAILQ_ENTRY(partition_metadata) metadata; }; struct partition_metadata *get_part_metadata(const char *name, int create); void delete_part_metadata(const char *name); int part_wizard(const char *fstype); int scripted_editor(int argc, const char **argv); +char *boot_disk_select(struct gmesh *mesh); int wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, int interactive); /* gpart operations */ void gpart_delete(struct gprovider *pp); void gpart_destroy(struct ggeom *lg_geom); void gpart_edit(struct gprovider *pp); void gpart_create(struct gprovider *pp, const char *default_type, const char *default_size, const char *default_mountpoint, char **output, int interactive); intmax_t gpart_max_free(struct ggeom *gp, intmax_t *start); void gpart_revert(struct gprovider *pp); void gpart_revert_all(struct gmesh *mesh); void gpart_commit(struct gmesh *mesh); int gpart_partition(const char *lg_name, const char *scheme); void set_default_part_metadata(const char *name, const char *scheme, const char *type, const char *mountpoint, const char *newfs); void gpart_set_root(const char *lg_name, const char *attribute); const char *choose_part_type(const char *def_scheme); /* machine-dependent bootability checks */ const char *default_scheme(void); /* Default partition scheme */ int is_scheme_bootable(const char *scheme); /* Non-zero if scheme boots */ int is_fs_bootable(const char *scheme, const char *fs); /* Ditto if FS boots */ /* Size of boot partition in bytes. Zero if no boot partition */ size_t bootpart_size(const char *scheme); /* * Type and mountpoint of boot partition for given scheme. If boot partition * should not be mounted, set mountpoint to NULL or leave it unchanged. * Note that mountpoint non-NULL implies partcode_path() will be ignored. * Do *NOT* set both! */ const char *bootpart_type(const char *scheme, const char **mountpoint); /* Path to bootcode that goes in the scheme (e.g. disk MBR). NULL if none */ const char *bootcode_path(const char *scheme); /* * Path to boot blocks to be dd'ed into the partition suggested by bootpart_* * for the given scheme and root filesystem type. If the boot partition should * be mounted rather than dd'ed to, return NULL here. */ const char *partcode_path(const char *scheme, const char *fs_type); #endif diff --git a/usr.sbin/bsdinstall/partedit/scripted.c b/usr.sbin/bsdinstall/partedit/scripted.c index 57dcbca816a3..37ac6de131b5 100644 --- a/usr.sbin/bsdinstall/partedit/scripted.c +++ b/usr.sbin/bsdinstall/partedit/scripted.c @@ -1,215 +1,219 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2013 Nathan Whitehorn * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #include #include #include #include "partedit.h" static struct gprovider * provider_for_name(struct gmesh *mesh, const char *name) { struct gclass *classp; struct gprovider *pp = NULL; struct ggeom *gp; LIST_FOREACH(classp, &mesh->lg_class, lg_class) { LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { if (LIST_EMPTY(&gp->lg_provider)) continue; LIST_FOREACH(pp, &gp->lg_provider, lg_provider) if (strcmp(pp->lg_name, name) == 0) break; if (pp != NULL) break; } if (pp != NULL) break; } return (pp); } static int part_config(char *disk, const char *scheme, char *config) { char *partition, *ap, *size = NULL, *type = NULL, *mount = NULL; struct gclass *classp; struct gmesh mesh; struct ggeom *gpart = NULL; int error; if (scheme == NULL) scheme = default_scheme(); error = geom_gettree(&mesh); if (provider_for_name(&mesh, disk) == NULL) { fprintf(stderr, "GEOM provider %s not found\n", disk); geom_deletetree(&mesh); return (-1); } /* Remove any existing partitioning and create new scheme */ LIST_FOREACH(classp, &mesh.lg_class, lg_class) if (strcmp(classp->lg_name, "PART") == 0) break; if (classp != NULL) { LIST_FOREACH(gpart, &classp->lg_geom, lg_geom) if (strcmp(gpart->lg_name, disk) == 0) break; } if (gpart != NULL) gpart_destroy(gpart); gpart_partition(disk, scheme); if (strcmp(scheme, "MBR") == 0) { struct gmesh submesh; geom_gettree(&submesh); gpart_create(provider_for_name(&submesh, disk), "freebsd", NULL, NULL, &disk, 0); geom_deletetree(&submesh); } else { disk= strdup(disk); } geom_deletetree(&mesh); error = geom_gettree(&mesh); /* Create partitions */ if (config == NULL) { wizard_makeparts(&mesh, disk, "ufs", 0); goto finished; } while ((partition = strsep(&config, ",")) != NULL) { while ((ap = strsep(&partition, " \t\n")) != NULL) { if (*ap == '\0') continue; if (size == NULL) size = ap; else if (type == NULL) type = ap; else if (mount == NULL) mount = ap; } if (size == NULL) continue; if (strcmp(size, "auto") == 0) size = NULL; gpart_create(provider_for_name(&mesh, disk), type, size, mount, NULL, 0); geom_deletetree(&mesh); error = geom_gettree(&mesh); size = type = mount = NULL; } finished: geom_deletetree(&mesh); free(disk); return (0); } static int parse_disk_config(char *input) { char *ap; char *disk = NULL, *scheme = NULL, *partconfig = NULL; while (input != NULL && *input != 0) { if (isspace(*input)) { input++; continue; } switch(*input) { case '{': input++; partconfig = strchr(input, '}'); if (partconfig == NULL) { fprintf(stderr, "Malformed partition setup " "string: %s\n", input); return (1); } *partconfig = '\0'; ap = partconfig+1; partconfig = input; input = ap; break; default: if (disk == NULL) disk = strsep(&input, " \t\n"); else if (scheme == NULL) scheme = strsep(&input, " \t\n"); else { fprintf(stderr, "Unknown directive: %s\n", strsep(&input, " \t\n")); return (1); } } } while (input != NULL && *input != 0); - if (disk != NULL) - return (part_config(disk, scheme, partconfig)); + if (disk == NULL || strcmp(disk, "DEFAULT") == 0) { + struct gmesh mesh; + geom_gettree(&mesh); + disk = boot_disk_select(&mesh); + geom_deletetree(&mesh); + } - return (0); + return (part_config(disk, scheme, partconfig)); } int scripted_editor(int argc, const char **argv) { char *token; int i, error = 0, len = 0; for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1; char inputbuf[len], *input = inputbuf; strcpy(input, argv[1]); for (i = 2; i < argc; i++) { strcat(input, " "); strcat(input, argv[i]); } while ((token = strsep(&input, ";")) != NULL) { error = parse_disk_config(token); if (error != 0) return (error); } return (0); }