From: Plom Heller Date: Wed, 9 Sep 2026 01:58:41 +0000 (+0200) Subject: Assume it's always nvme0n1, and …p1, …p3. X-Git-Url: https://plomlompom.com/repos/booking/test.html?a=commitdiff_plain;h=e2b0f23b43401d698f36d1d08857b4844c705c4b;p=confplom Assume it's always nvme0n1, and …p1, …p3. --- diff --git a/setup_scripts/_lib.sh b/setup_scripts/_lib.sh index f8b1fec..3fd2041 100644 --- a/setup_scripts/_lib.sh +++ b/setup_scripts/_lib.sh @@ -3,16 +3,19 @@ SCRIPT_NAME=$0 cd "$(dirname "${SCRIPT_NAME}")" # constants unlikely to change +DIRNAME_DEV=dev DIRNAME_SSH=.ssh FNAME_INITRD=initrd.img FNAME_PROFILE=.profile FNAME_VMLINUZ=vmlinuz -NAME_DEV=dev -PATH_DEV="/${NAME_DEV}" +PATH_DEV="/${DIRNAME_DEV}" PATH_MNT=/mnt -TO_RBIND="${NAME_DEV} proc sys" +TO_RBIND="${DIRNAME_DEV} proc sys" # constants we might want to change at some point +IDX_PARTITION_EFI=1 +IDX_PARTITION_LUKSVG=3 +NAME_BOOT_DEVICE=nvme0n1 NAME_DATA=data NAME_LUKSVG=cryptolvm NAME_SWAP=swap @@ -21,7 +24,10 @@ PATH_MNT_ROOT="${PATH_MNT}/root" USERNAME=plom # constants derived from changeables +PATH_BOOT_DEVICE="${PATH_DEV}/${NAME_BOOT_DEVICE}" PATH_MY_SSH="${HOME}/${DIRNAME_SSH}" +PATH_PARTITION_EFI="${PATH_BOOT_DEVICE}p${IDX_PARTITION_EFI}" +PATH_PARTITION_LUKSVG="${PATH_BOOT_DEVICE}p${IDX_PARTITION_LUKSVG}" PATH_PROFILE="${HOME}/${FNAME_PROFILE}" PATH_REPO=$(cd .. && pwd) NAME_REPO_DIR=$(basename "${PATH_REPO}") @@ -63,7 +69,7 @@ check_tools() { || error "required tool not found: ${CMD}" done } -check_input_partition_mountable() { +check_partition_mountable() { local PARTITION=$1 [ -b "${PARTITION}" ]\ || error "${PARTITION} is not a block device" @@ -80,18 +86,16 @@ check_new_luksvg() { && error "${PATH_LUKS_MAPPER} already exists" true } -check_input_openable_luksvg() { - local PARTITION=$1 +check_openable_luksvg() { check_new_luksvg - try_quiet cryptsetup isLuks "${PARTITION}"\ - || error "${PARTITION} not a LUKS container" + try_quiet cryptsetup isLuks "${PATH_PARTITION_LUKSVG}"\ + || error "${PATH_PARTITION_LUKSVG} not a LUKS container" } # helpers: luks open/close open_luksvg() { - local PARTITION=$1 msg 'Opening LUKS container as "%s" …' "${NAME_LUKSVG}" - cryptsetup luksOpen "${PARTITION}" "${NAME_LUKSVG}" + cryptsetup luksOpen "${PATH_PARTITION_LUKSVG}" "${NAME_LUKSVG}" } close_luksvg() { msg 'Deactivating volume group and closing LUKS container …' diff --git a/setup_scripts/chrooted_command.sh b/setup_scripts/chrooted_command.sh index 26a987a..cc3927b 100755 --- a/setup_scripts/chrooted_command.sh +++ b/setup_scripts/chrooted_command.sh @@ -2,21 +2,20 @@ . "$(dirname "$0")/_lib.sh" # inputs to confirm -usage $# "partition" "root-name" "command" -PARTITION=$1 -NAME_ROOT=$2 -COMMAND=$3 +usage $# "root-name" "command" +NAME_ROOT=$1 +COMMAND=$2 # constants derived from changeables PATH_VG_ROOT=$(path_vg "${NAME_LUKSVG}")/${NAME_ROOT} # sanity checks check_tools cryptsetup vgchange vgs -check_input_partition_mountable "${PARTITION}" -check_input_openable_luksvg "${PARTITION}" +check_partition_mountable "${PATH_PARTITION_LUKSVG}" +check_openable_luksvg # mount -open_luksvg "${PARTITION}" +open_luksvg await_path "${PATH_VG_ROOT}" mount_privately "${PATH_VG_ROOT}" "${PATH_MNT_ROOT}" rbind_mnt @@ -28,5 +27,5 @@ chroot_sh "${COMMAND}" || RETURN_CODE=$? # clean up mounts unmount_unrbind close_luksvg -msg 'Finished! (command exit status: %s)' "${RETURN_CODe}" +msg 'Finished! (command exit status: %s)' "${RETURN_CODE}" exit "${RETURN_CODE}" diff --git a/setup_scripts/install_debian.sh b/setup_scripts/install_debian.sh index 9a5bb36..e2e560a 100755 --- a/setup_scripts/install_debian.sh +++ b/setup_scripts/install_debian.sh @@ -6,7 +6,6 @@ FNAME_NM_CONN=wifi.nmconnection PATH_CRYPTTAB=/etc/crypttab PATH_EFI=/boot/efi PATH_FSTAB=/etc/fstab -PATH_HOOK_UPDATE_EFI=/etc/initramfs/post-update.d/update-efi PATH_HOSTNAME=/etc/hostname PATH_HOSTS=/etc/hosts PATH_INTERFACES=/etc/network/interfaces @@ -14,27 +13,21 @@ PATH_NM_CONNECTIONS=/etc/NetworkManager/system-connections # constants we might want to change at some point DEB_SUITE=trixie -IDX_BOOT_PARTITION=1 -PATH_BOOT_DEVICE="${PATH_DEV}/nvme0n1" # inputs -usage $# "partition" "boot-name" -PARTITION=$1 -NAME_BOOT=$2 +usage $# "boot-name" +NAME_BOOT=$1 NAME_ROOT="${NAME_BOOT}" # constants derived from changeables -PARTITION_EFI="${PATH_BOOT_DEVICE}p${IDX_BOOT_PARTITION}" PATH_EFI_NAME_BOOT="${PATH_EFI}/${NAME_BOOT}" PATH_MNT_APT_SOURCES="${PATH_MNT_ROOT}/etc/apt/sources.list" PATH_MNT_CRYPTTAB="${PATH_MNT_ROOT}${PATH_CRYPTTAB}" PATH_MNT_FSTAB="${PATH_MNT_ROOT}${PATH_FSTAB}" -PATH_MNT_HOOK_UPDATE_EFI="${PATH_MNT_ROOT}${PATH_HOOK_UPDATE_EFI}" PATH_MNT_HOSTNAME="${PATH_MNT_ROOT}${PATH_HOSTNAME}" PATH_MNT_HOSTS="${PATH_MNT_ROOT}${PATH_HOSTS}" PATH_MNT_NM_CONN="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}/${FNAME_NM_CONN}" PATH_MNT_NM_CONNECTIONS="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}" -PATH_UPDATE_EFI="/${NAME_DATA}/${NAME_REPO_DIR}/setup_scripts/update_efi.sh" PATH_VG=$(path_vg "${NAME_LUKSVG}") PATH_VG_DATA=${PATH_VG}/${NAME_DATA} PATH_VG_ROOT=${PATH_VG}/${NAME_ROOT} @@ -42,8 +35,8 @@ PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP} # sanity checks check_tools cryptsetup debootstrap efibootmgr lvcreate mkfs.ext4 vgchange vgs -check_input_partition_mountable "${PARTITION}" -check_input_openable_luksvg "${PARTITION}" +check_partition_mountable "${PATH_PARTITION_LUKSVG}" +check_openable_luksvg case "${NAME_BOOT}" in *[!A-Za-z0-9_.-]*|"") error "illegal characters in boot label '${NAME_BOOT}'" ;; esac @@ -56,11 +49,11 @@ efibootmgr \ && error "an EFI boot entry named '${NAME_BOOT}' already exists" msg 'Your installation choices:' -msg '- target partition: [ %s ]' "${PARTITION}" +msg '- target partition: [ %s ]' "${PATH_PARTITION_LUKSVG}" msg '- name for new boot option: [ %s ]' "${NAME_BOOT}" -# set up logival volume and filesystem -open_luksvg "${PARTITION}" +# set up logical volume and filesystem +open_luksvg create_lv "${NAME_LUKSVG}" "${NAME_ROOT}" 10G await_path "${PATH_VG_ROOT}" msg 'Creating EXT4 filesystem …' @@ -80,8 +73,7 @@ ${PATH_VG_SWAP} none swap sw 0 0 EOF msg 'Setting up crypttab …' -printf '%s UUID=%s none luks\n' \ - "${NAME_LUKSVG}" "$(cryptsetup luksUUID "${PARTITION}")" \ +printf '%s %s none luks\n' "${NAME_LUKSVG}" "${PATH_PARTITION_LUKSVG}" \ >| "${PATH_MNT_CRYPTTAB}" msg 'Setting up hostname …' @@ -101,15 +93,6 @@ chroot_sh \ cryptsetup cryptsetup-initramfs lvm2 \ firmware-iwlwifi network-manager wpasupplicant" -msg 'Installing initramfs hook to refresh EFI boot files on kernel updates …' -# (only after previous apt-get calls, easier to do its work below on our own) -mkdir -p "$(dirname "${PATH_MNT_HOOK_UPDATE_EFI}")" -cat <| "${PATH_MNT_HOOK_UPDATE_EFI}" -#!/bin/sh -exec "${PATH_UPDATE_EFI}" "${PARTITION_EFI}" -EOF -chmod +x "${PATH_MNT_HOOK_UPDATE_EFI}" - # pre-seed known wifi network into NetworkManager msg 'Extracting wifi credentials from %s …' "${PATH_INTERFACES}" NAME_WIFI_SSID=$(sed -n 's/^[[:space:]]*wpa-ssid[[:space:]]*//p' \ @@ -152,7 +135,7 @@ efibootmgr \ --create \ --quiet \ --disk "${PATH_BOOT_DEVICE}" \ - --part "${IDX_BOOT_PARTITION}" \ + --part "${IDX_PARTITION_EFI}" \ --label "${NAME_BOOT}" \ --loader "${NAME_BOOT}/${FNAME_VMLINUZ}" \ --unicode "root=${PATH_VG_ROOT} ro initrd=${NAME_BOOT}\\${FNAME_INITRD}" diff --git a/setup_scripts/setup_luksvg.sh b/setup_scripts/setup_luksvg.sh index 8127571..0781a1d 100755 --- a/setup_scripts/setup_luksvg.sh +++ b/setup_scripts/setup_luksvg.sh @@ -2,8 +2,7 @@ . "$(dirname "$0")/_lib.sh" # inputs to confirm -usage $# "partition" -PARTITION=$1 +usage $# # constants derived from changeables PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}") @@ -14,20 +13,20 @@ PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP} # sanity checks check_tools cryptsetup lvcreate mkfs.ext4 mkswap vgchange vgcreate vgs -check_input_partition_mountable "${PARTITION}" +check_partition_mountable "${PATH_PARTITION_LUKSVG}" check_new_luksvg -try_quiet cryptsetup isLuks "${PARTITION}"\ - && error "${PARTITION} is already a LUKS container" +try_quiet cryptsetup isLuks "${PATH_PARTITION_LUKSVG}"\ + && error "${PATH_PARTITION_LUKSVG} is already a LUKS container" # run inputs by user and ask for confirmation -msg 'Your target partition (WILL BE ERASED!): [ %s ]' "${PARTITION}" +msg 'Target partition TO BE ERASED (!): [ %s ]' "${PATH_PARTITION_LUKSVG}" msg_nonl 'To continue, type "YES!" (all caps, exclamation mark, no quotes): ' read -r CONFIRM; [ "${CONFIRM}" = 'YES!' ]\ || die 'ABORTED: expected confirmation not given.' -msg 'Encrypting %s as LUKS container …' "${PARTITION}" -cryptsetup luksFormat --batch-mode "${PARTITION}" -open_luksvg "${PARTITION}" +msg 'Encrypting %s as LUKS container …' "${PATH_PARTITION_LUKSVG}" +cryptsetup luksFormat --batch-mode "${PATH_PARTITION_LUKSVG}" +open_luksvg # set up LVM and filesystems msg 'Creating volume group "%s" inside LUKS container …' "${NAME_LUKSVG}" diff --git a/setup_scripts/start_root_t490s.sh b/setup_scripts/start_root_t490s.sh index 37f0f37..ab2244e 100755 --- a/setup_scripts/start_root_t490s.sh +++ b/setup_scripts/start_root_t490s.sh @@ -3,6 +3,7 @@ # constants unlikely to change PATH_DEFAULT_LOCALE=/etc/default/locale +PATH_HOOK_UPDATE_EFI=/etc/initramfs/post-update.d/update-efi PATH_SYSCTL_PRINTK=/etc/sysctl.d/60-printk-console.conf PATH_TLP_THRESH_CONF=/etc/tlp.conf.d/60-thresholds.conf PATH_UDEV_RULES=/etc/udev/rules.d @@ -16,6 +17,16 @@ TLP_THRESH_STOP=80 # constants derived from changeables PATH_TO_COPY="${PATH_REPO}/to_copy" +PATH_UPDATE_EFI_SCRIPT="${PATH_REPO}/setup_scripts/update_efi.sh" + +# before any apt-get call gets a chance to pull in a kernel update of its own … +msg 'Installing initramfs hook to refresh EFI boot files on kernel updates …' +mkdir -p "$(dirname "${PATH_HOOK_UPDATE_EFI}")" +cat <| "${PATH_HOOK_UPDATE_EFI}" +#!/bin/sh +exec "${PATH_UPDATE_EFI_SCRIPT}" +EOF +chmod +x "${PATH_HOOK_UPDATE_EFI}" start_root t490s diff --git a/setup_scripts/update_efi.sh b/setup_scripts/update_efi.sh index 92cd91a..a2183de 100755 --- a/setup_scripts/update_efi.sh +++ b/setup_scripts/update_efi.sh @@ -1,14 +1,13 @@ #!/bin/sh . "$(dirname "$0")/_lib.sh" -usage $# "efi-partition" -PARTITION_EFI=$1 +usage $# PATH_TEMP=$(mktemp --directory) PATH_EFI_NAME_BOOT="${PATH_TEMP}/$(hostname)" -msg 'Mounting EFI partition %s at %s …' "${PARTITION_EFI}" "${PATH_TEMP}" -mount "${PARTITION_EFI}" "${PATH_TEMP}" +msg 'Mounting EFI partition %s at %s …' "${PATH_PARTITION_EFI}" "${PATH_TEMP}" +mount "${PATH_PARTITION_EFI}" "${PATH_TEMP}" efi_copy_kernel_vmlinuz "${PATH_EFI_NAME_BOOT}"