From owner-svn-src-all@freebsd.org Mon Dec 31 00:20:59 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05307143ADBB; Mon, 31 Dec 2018 00:20:59 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9AAB274A2B; Mon, 31 Dec 2018 00:20:58 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 88AD12967; Mon, 31 Dec 2018 00:20:58 +0000 (UTC) (envelope-from bcran@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wBV0Kwfl024309; Mon, 31 Dec 2018 00:20:58 GMT (envelope-from bcran@FreeBSD.org) Received: (from bcran@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wBV0Kwbo024308; Mon, 31 Dec 2018 00:20:58 GMT (envelope-from bcran@FreeBSD.org) Message-Id: <201812310020.wBV0Kwbo024308@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bcran set sender to bcran@FreeBSD.org using -f From: Rebecca Cran Date: Mon, 31 Dec 2018 00:20:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342637 - head/usr.sbin/bsdinstall/scripts X-SVN-Group: head X-SVN-Commit-Author: bcran X-SVN-Commit-Paths: head/usr.sbin/bsdinstall/scripts X-SVN-Commit-Revision: 342637 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9AAB274A2B X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.96)[-0.957,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.998,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Dec 2018 00:20:59 -0000 Author: bcran Date: Mon Dec 31 00:20:58 2018 New Revision: 342637 URL: https://svnweb.freebsd.org/changeset/base/342637 Log: Fix ESP generation when using a gmirror, and when booting from RO medium When using a gmirror, entries in /dev can be removed. So instead of using kern.disks, get the list of disks from "gpart status -sg" instead. We assume that any 'efi' partition that can't be mounted as msdosfs should be used as an ESP. However, the ESP on the CD/DVD can't be mounted read-write and so was being treated as if unformatted. Try the mount as read-only instead, to catch cases like this. Relnotes: yes Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D18645 Modified: head/usr.sbin/bsdinstall/scripts/bootconfig Modified: head/usr.sbin/bsdinstall/scripts/bootconfig ============================================================================== --- head/usr.sbin/bsdinstall/scripts/bootconfig Mon Dec 31 00:15:05 2018 (r342636) +++ head/usr.sbin/bsdinstall/scripts/bootconfig Mon Dec 31 00:20:58 2018 (r342637) @@ -84,10 +84,11 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" # The installer hasn't given us any ESPs to use. # Try and figure out which to use by looking for an # unformatted efi partition - for disk in $(sysctl -n kern.disks); do - hasfreebsd=$(gpart show "$disk" | cut -w -f 4,5 | grep "freebsd") + + for geom in $(gpart status -sg | awk '{print $1}'); do + hasfreebsd=$(gpart show "${geom}" | cut -w -f 4,5 | grep "freebsd") if [ -n "$hasfreebsd" ]; then - index=$(gpart show "$disk" | cut -w -f 4,5 | grep "efi" | cut -w -f 1) + index=$(gpart show "${geom}" | cut -w -f 4,5 | grep "efi" | cut -w -f 1) # Check that $index is a valid integer [ -n "$index" ] && [ "$index" -eq "$index" ] && [ "$index" -ge 0 ] 2> /dev/null if [ $? -ne 0 ]; then @@ -95,17 +96,17 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" fi mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) - if [ -e "/dev/${disk}p${index}" ]; then - dev=${disk}p${index} - elif [ -e "/dev/${disk}s${index}" ]; then - dev=/${disk}s${index} + if [ -e "/dev/${geom}p${index}" ]; then + dev=${geom}p${index} + elif [ -e "/dev/${geom}s${index}" ]; then + dev=/${geom}s${index} else continue fi # Try and mount it. If it fails, assume it's # unformatted and should be used. - mount -t msdosfs "/dev/${dev}" "${mntpt}" + mount -t msdosfs -o ro "/dev/${dev}" "${mntpt}" if [ $? -ne 0 ]; then ESPS="$ESPS ${dev}" num_esps=$((num_esps + 1)) @@ -118,17 +119,20 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" fi for esp in $ESPS; do + echo "Formatting /dev/${esp} as FAT32" newfs_msdos -F 32 -c 1 -L EFISYS "/dev/$esp" > /dev/null 2>&1 if [ $? -ne 0 ]; then die "Failed to format ESP $esp as FAT32" fi mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) + echo "Mounting ESP /dev/${esp}" mount -t msdosfs "/dev/${esp}" "${mntpt}" if [ $? -ne 0 ]; then die "Failed to mount ESP ${dev} on ${mntpt}" fi + echo "Installing loader.efi onto ESP" mkdir -p "$mntpt/EFI/freebsd" cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/EFI/freebsd/loader.efi" @@ -138,8 +142,10 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" bootlabel="FreeBSD" fi + echo "Creating UEFI boot entry" efibootmgr --create --label "$bootlabel" --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null + echo "Unmounting ESP" umount "${mntpt}" rmdir "${mntpt}" @@ -149,6 +155,7 @@ if [ "$(uname -m)" = "arm64" ] || [ "$X86_BOOTMETHOD" bootorder=$(efivar --name 8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head -1) bootentry=$(echo "$bootorder" | cut -w -f 3)$(echo "$bootorder" | cut -w -f 2) efibootmgr --activate "$bootentry" > /dev/null + echo "Finished configuring /dev/${esp} as ESP" done fi