From nobody Wed Dec 15 14:24:38 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 64C9318E9451; Wed, 15 Dec 2021 14:24:39 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JDcvW0HBJz3s1m; Wed, 15 Dec 2021 14:24:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DE7311D922; Wed, 15 Dec 2021 14:24:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BFEOcZs037328; Wed, 15 Dec 2021 14:24:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BFEOcKD037327; Wed, 15 Dec 2021 14:24:38 GMT (envelope-from git) Date: Wed, 15 Dec 2021 14:24:38 GMT Message-Id: <202112151424.1BFEOcKD037327@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 40c928e7b80a - main - bsdinstall: bootconfig: Try to clean old efi boot entries List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 40c928e7b80a7e2ba3652f7c3dc1d30fe92e5b48 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639578279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4V97I31uYyDEZTiKw1Xp2EVddvjrBnUFMIQ0vh12FNA=; b=W5uMMGOg3weAJNm9DBMzPtKEx07ybvud2xLIHqxBJ2F4KJEiJ5jv0PIJxRxSK3r7qsV/yj GjHNsmEIUEQDXnhOo72qt8Pr6r7OAl+hz5SrtyEfO9LNSq0Hi3v4/3Pphc2HTkyO65KD7a zIsmkFyG4HcufX5DPyIamw7MwJ8/Uvg+Eerl/LtHAEXDH3BfPKo14Qwg6m9uwRS8b0FXDY TesvuGY/sx84ts+2LVg4yX7jFU53kyAG/+CXu5Nu9wRRJRuzJ9jbIPFsXxCz6oVNpXNaY1 FjLi8l0JRIMMGMfktsRF4zJgrWWnaDatqfW0llArmNQuKMFQm0gC5GrXj/UrNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639578279; a=rsa-sha256; cv=none; b=kR22+llXvYIQjsH1sBfSAO760b4SAxNstoD85N242Ww4zRF656K+ngv4KFSC6PavXOFo5L ixOM4iKp9K4TqtXjb0IJLwvQynSLp0UYpwU44pw7KFpEWhqk+i84giTAg5Uo7LY3IHQrC2 Dpjtuz3UoTmrFTAmazWLIJAqvK3R8PP23UeJidGnvHhPRIsycaF7i29ym7NGIJjg5XiaO9 ThnVPm4qemCMHPaCLti/eshgyZH5kPkbkPhjmJnbyhkv9C4+hyFRz6SjV7D4/5TTXnCXUb rk8KLB1q+0JWA+TrSZquHGDchOYVTlPLKiYEBlgPAX0Emikq6wSEMRLqLVgjHg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=40c928e7b80a7e2ba3652f7c3dc1d30fe92e5b48 commit 40c928e7b80a7e2ba3652f7c3dc1d30fe92e5b48 Author: Emmanuel Vadot AuthorDate: 2021-12-08 09:37:54 +0000 Commit: Emmanuel Vadot CommitDate: 2021-12-15 14:23:27 +0000 bsdinstall: bootconfig: Try to clean old efi boot entries If one install FreeBSD on the same machine multiple times in a row or on different harddrive they have a lot of 'FreeBSD' efi boot entries added. With this patch we now do : - If there is no 'FreeBSD' entry we add one like before - If there is one or more entries we ask the user if they want to delete them all and add a new one - If they say yes we do that - If they say no we prompt them an inputbox so they can enter a different entry name if they want, it defaults to 'FreeBSD' Reviewed by: bapt, imp MFC after: 2 weeks Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D33330 --- usr.sbin/bsdinstall/scripts/bootconfig | 54 ++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig index c5218b10a271..8c0e87991248 100755 --- a/usr.sbin/bsdinstall/scripts/bootconfig +++ b/usr.sbin/bsdinstall/scripts/bootconfig @@ -32,6 +32,8 @@ FREEBSD_BOOTLABEL="FreeBSD" BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 +f_dprintf "%s: loading_includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr : ${TMPDIR:="/tmp"} @@ -40,6 +42,55 @@ die() { exit 1 } +dialog_uefi_entryname() +{ + local prompt="Please enter a name for the new entry" + local hline= + local value="$*" + local height width + + f_dialog_inputbox_size height width \ + "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline" + + $DIALOG \ + --title "$DIALOG_TITLE" \ + --backtitle "$DIALOG_BACKTITLE" \ + --hline "$hline" \ + --ok-label "Ok" \ + --no-cancel \ + --inputbox "$prompt" \ + $height $width "$value" \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD +} + +update_uefi_bootentry() +{ + nentries=$(efibootmgr | grep -c 'FreeBSD$') + # No entries so directly create one and return + if [ ${nentries} -eq 0 ]; then + f_dprintf "Creating UEFI boot entry" + efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null + return + fi + + $DIALOG --backtitle 'FreeBSD Installer' --title 'Boot configuration' \ + --yesno 'There is multiple "FreeBSD" efi boot entries, would you like to remove them all and add a new one?' 0 0 + if [ $? -eq $DIALOG_OK ]; then + for entry in $(efibootmgr | awk '$NF == "FreeBSD" { sub(/.*Boot/,"", $1); sub(/\*/,"", $1); print $1 }'); do + efibootmgr -B -b ${entry} + done + efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null + return + fi + + FREEBSD_BOOTLABEL=$(dialog_uefi_entryname "${FREEBSD_BOOTLABEL}") + [ $? -eq $DIALOG_CANCEL ] && exit 1 + efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null +} + +f_dialog_title "Boot configuration" +f_dialog_backtitle "FreeBSD Installer" + if [ `uname -m` == powerpc ]; then platform=`sysctl -n hw.platform` if [ "$platform" == ps3 -o "$platform" == powernv ]; then @@ -87,8 +138,7 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then fi if [ "$BSDINSTALL_CONFIGCURRENT" ]; then - f_dprintf "Creating UEFI boot entry" - efibootmgr --create --activate --label "$FREEBSD_BOOTLABEL" --loader "${mntpt}/${FREEBSD_BOOTNAME}" > /dev/null + update_uefi_bootentry fi f_dprintf "Finished configuring ESP"