feat: canonicalize devices before use to /dev/disk/by-id/ if possible.

This is beneficial for ZFS pools and for humans to see whether the
correct disk was selected.
This commit is contained in:
oddlama 2022-05-13 22:43:58 +02:00
parent 20a69f41ec
commit 50ec673974
No known key found for this signature in database
GPG Key ID: 14EFE510775FE39A
4 changed files with 11 additions and 6 deletions

5
configure vendored
View File

@ -2,8 +2,6 @@
set -uo pipefail
#todo "test ZFS compression really on"
#todo "disks by id also in resolve step"
#todo "the device you want to partitoin ---> to use?"
################################################
# Initialize script environment
@ -649,7 +647,8 @@ function menu_radiolist() {
function menu_select_device() {
local title="$1"
local desc="$2"
local prev_selected=$(canonicalize_device "$3")
local prev_selected
prev_selected=$(canonicalize_device "$3")
while true; do
local all_devices=()

View File

@ -96,7 +96,7 @@ while [[ $# -gt 0 ]]; do
done
# Check configuration location
[[ -z "${CONFIG%%$GENTOO_INSTALL_REPO_DIR*}" ]] \
[[ -z "${CONFIG%%"$GENTOO_INSTALL_REPO_DIR"*}" ]] \
|| die "Configuration file must be inside the installation directory. This is needed so it is accessible from within the chroot environment."
if [[ -z "$ACTION" ]]; then

View File

@ -6,8 +6,6 @@ source "$GENTOO_INSTALL_REPO_DIR/scripts/protection.sh" || exit 1
# Functions
function install_stage3() {
[[ $# == 0 ]] || die "Too many arguments"
prepare_installation_environment
apply_disk_configuration
download_stage3

View File

@ -242,6 +242,14 @@ function create_resolve_entry_device() {
# Return matching device from /dev/disk/by-id/ if possible,
# otherwise return the parameter unchanged.
function canonicalize_device() {
given_dev="$(realpath "$1")"
for dev in /dev/disk/by-id/*; do
if [[ "$(realpath "$dev")" == "$given_dev" ]]; then
echo -n "$dev"
return 0
fi
done
echo -n "$1"
}