From nobody Thu Dec 30 09:10:14 2021 X-Original-To: dev-commits-src-branches@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 C35671927543; Thu, 30 Dec 2021 09:10:14 +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 4JPjCp3hpxz4fkM; Thu, 30 Dec 2021 09:10:14 +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 5AE7915F1A; Thu, 30 Dec 2021 09:10:14 +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 1BU9AE2p096594; Thu, 30 Dec 2021 09:10:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BU9AERC096588; Thu, 30 Dec 2021 09:10:14 GMT (envelope-from git) Date: Thu, 30 Dec 2021 09:10:14 GMT Message-Id: <202112300910.1BU9AERC096588@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Emmanuel Vadot Subject: git: 477fbe6732fe - stable/13 - bsdinstall: bootconfig: Try to clean old efi boot entries List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 477fbe6732feb9f37e2790f153c78dba3b7df239 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640855414; 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=3B/ox4pXEtkTGvwaskUfJ/DIZtGdWWfVfA3Lq6CYPrk=; b=GzxOtkOhG6r5bL2rhqCb7Z1ugD9K4GnjzucL/MYZJ4IvezMePUBzcgEHHoSqTVs75y0oaJ b1QVsxEw75Ll4FnGRDCAGX2eN4Zc7skd63dPYTG9M4SNFGYy0MV6Natgl3lLjk32TLGl7E JtK2do9tNVdsNVblS6Cc47yuep5QjUQsUMxjuyk4fcI7efIlzm1OyFiScWPX0DURq8Jqz+ zEydslbUJZt3MgdGXMZmlUCl5F6cR6PmgcCxKtCJF7B1NxuN44qwVFYWxwjugS6FyHBvqG GqZVzb4DJn0cMGAul/jY5d5VM47nKH2k4kzebXfTPQ+a0vBilBFyJKuW+JVoEQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640855414; a=rsa-sha256; cv=none; b=Hf5IXFgXqLwrucbvfgk0W9K7f0VFlATaXMug78IuEgMGI48NAX/EU8DOkZH5M1GwckKC1Y z1dbpZmb4m1cCq/FDeXSmHs4FIPThlTCYYsJcjYDNT4aUWvGzYSEPjXP5wbMWfOM5N70Cs FXTo/8Ll7LK9naQOGR+LjN0N6spaLJfMLYAaS1QGxkM6Fux/ug4JjbiXdaxHhLHy3ngYFP 2a2CEUgEtghW28yDIo5UFu+mq/K1oYhg0w58D+yurTcmJ7NSkLYSYoydPdtFSb2Mi7Xp9U fzaP45832ohRuvWoK8OKiabA0Jpcez7/p0VutHR3yenSZJDPzwvLbXC3oXzHeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=477fbe6732feb9f37e2790f153c78dba3b7df239 commit 477fbe6732feb9f37e2790f153c78dba3b7df239 Author: Emmanuel Vadot AuthorDate: 2021-12-08 09:37:54 +0000 Commit: Emmanuel Vadot CommitDate: 2021-12-30 09:09:57 +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 (cherry picked from commit 40c928e7b80a7e2ba3652f7c3dc1d30fe92e5b48) --- 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"