From 18674a4b0c2ff9815cf1d0bff7e3db7161be8dfb Mon Sep 17 00:00:00 2001 From: oddlama Date: Sat, 25 Apr 2020 18:06:38 +0200 Subject: [PATCH] UUID based fstab --- scripts/main.sh | 21 ++++++++++----------- scripts/utils.sh | 6 ++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/main.sh b/scripts/main.sh index f0745af..88f8f50 100755 --- a/scripts/main.sh +++ b/scripts/main.sh @@ -139,9 +139,7 @@ generate_initramfs() { } get_cmdline() { - local rootdev="$(resolve_device_by_id "$DISK_ID_ROOT")" - local rootuuid="$(get_blkid_field_by_device 'UUID' "$rootdev")" - echo -n "${DISK_DRACUT_CMDLINE[*]} root=UUID=$rootuuid" + echo -n "${DISK_DRACUT_CMDLINE[*]} root=UUID=$(get_blkid_uuid_for_id "$DISK_ID_ROOT")" } install_kernel_efi() { @@ -221,22 +219,23 @@ install_kernel() { fi } +add_fstab_entry() { + printf '%-46s %-24s %-6s %-96s %s' "$1" "$2" "$3" "$4" "$5" >> /etc/fstab \ + || die "Could not append entry to fstab" +} + generate_fstab() { einfo "Generating fstab" install -m0644 -o root -g root "$GENTOO_INSTALL_REPO_DIR/configs/fstab" /etc/fstab \ || die "Could not overwrite /etc/fstab" - echo "$(resolve_device_by_id "$DISK_ID_ROOT") / ext4 defaults,noatime,errors=remount-ro,discard 0 1" >> /etc/fstab \ - || die "Could not append entry to fstab" + add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_ROOT")" "/" "ext4" "defaults,noatime,errors=remount-ro,discard" "0 1" if [[ $IS_EFI == "true" ]]; then - echo "$(resolve_device_by_id "$DISK_ID_EFI") /boot/efi vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \ - || die "Could not append entry to fstab" + add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_EFI")" "/boot/efi" "vfat" "defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard" "0 2" else - echo "$(resolve_device_by_id "$DISK_ID_BIOS") /boot vfat defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard 0 2" >> /etc/fstab \ - || die "Could not append entry to fstab" + add_fstab_entry "UUID=$(get_blkid_uuid_for_id "$DISK_ID_BIOS")" "/boot" "vfat" "defaults,noatime,fmask=0022,dmask=0022,noexec,nodev,nosuid,discard" "0 2" fi if [[ -v "DISK_ID_SWAP" ]]; then - echo "$(resolve_device_by_id "$DISK_ID_SWAP") none swap defaults,discard 0 0" >> /etc/fstab \ - || die "Could not append entry to fstab" + add_fstab_entry "$(resolve_device_by_id "$DISK_ID_SWAP")" "none" "swap" "defaults,discard" "0 0" fi } diff --git a/scripts/utils.sh b/scripts/utils.sh index d92c24c..8428c8f 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -130,6 +130,12 @@ get_blkid_field_by_device() { echo -n "$val" } +get_blkid_uuid_for_id() { + local dev="$(resolve_device_by_id "$1")" + local uuid="$(get_blkid_field_by_device 'UUID' "$dev")" + echo -n "$uuid" +} + get_device_by_blkid_field() { local blkid_field="$1" local field_value="$2"