bsdinstall: Mount /dev and /packages after using the shell to partition disks

Normally after partitions are created by the installer, the 'mount'
script is used to mount the target disk partitions under /mnt.  The
tail end of this script also mounts a couple of additional filesystems
under /mnt so that chrooted programs can work such as devfs and
/packages.

When the "Shell" option is used to permit the user to manually mount
the destination filesystem, the "mount" script is not used as the user
is instructed to mount the target filesystems and construct
/mnt/etc/fstab, etc.  However, this means that the user is responsible
for mounting devfs (which is not included in /etc/fstab) and /packages
as well.  The help message for the "Shell" option doesn't mention
these requirements, so users may not know to do so.  This can lead to
confusing errors as chrooted commands can fail to find needed /dev
entries.  For example, running fwget to fetch wireless firmware fails
because /dev/pci doesn't exist.

To make this less painful for users using this option, split out the
bottom half of the 'mount' script that mounts these non-fstab-related
filesystems into a separate 'mount_aux' script.  Invoke 'mount_aux'
after using "Shell" to create the filesystem to ensure that these
filesystems are always present.

PR:		290901
Reported by:	Peter <freebsd@peterk.org>
Tested by:	Peter <freebsd@peterk.org>
Differential Revision:	https://reviews.freebsd.org/D53770

(cherry picked from commit f63a8c0a0915a3eceac179d4d18b2c03b1319fa2)
This commit is contained in:
John Baldwin 2025-12-08 16:33:30 -05:00 committed by Franco Fichtner
parent 042e2967b3
commit 53fff8286e
5 changed files with 43 additions and 9 deletions

View file

@ -424,6 +424,7 @@ OLD_FILES+=usr/libexec/bsdinstall/jail
OLD_FILES+=usr/libexec/bsdinstall/keymap
OLD_FILES+=usr/libexec/bsdinstall/mirrorselect
OLD_FILES+=usr/libexec/bsdinstall/mount
OLD_FILES+=usr/libexec/bsdinstall/mount_aux
OLD_FILES+=usr/libexec/bsdinstall/netconfig
OLD_FILES+=usr/libexec/bsdinstall/netconfig_ipv4
OLD_FILES+=usr/libexec/bsdinstall/netconfig_ipv6

View file

@ -14,6 +14,7 @@ SCRIPTS=auto \
keymap \
mirrorselect \
mount \
mount_aux \
netconfig \
netconfig_ipv4 \
netconfig_ipv6 \

View file

@ -366,6 +366,7 @@ case "$PARTMODE" in
clear
echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'."
sh 2>&1
bsdinstall mount_aux || error "Failed to mount auxiliary filesystems"
;;
"$msg_manual") # Manual
if f_isset debugFile; then

View file

@ -52,12 +52,4 @@ for i in $FILESYSTEMS; do
fi
done
# User might want a shell and require devfs, so mount it
mkdir $BSDINSTALL_CHROOT/dev 2>/dev/null
mount -t devfs devfs $BSDINSTALL_CHROOT/dev
# If installing from the DVD, mount packages where they'll be accessible
if [ -d /packages ]; then
mkdir -p $BSDINSTALL_CHROOT/dist/packages
mount -t nullfs /packages $BSDINSTALL_CHROOT/dist/packages
fi
bsdinstall mount_aux

View file

@ -0,0 +1,39 @@
#!/bin/sh
#-
# 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.
#
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
# User might want a shell and require devfs, so mount it
mkdir $BSDINSTALL_CHROOT/dev 2>/dev/null
mount -t devfs devfs $BSDINSTALL_CHROOT/dev
# If installing from the DVD, mount packages where they'll be accessible
if [ -d /packages ]; then
mkdir -p $BSDINSTALL_CHROOT/dist/packages
mount -t nullfs /packages $BSDINSTALL_CHROOT/dist/packages
fi