# constants we might want to change at some point
NAME_DATA=data
+NAME_LUKSVG=cryptolvm
NAME_SWAP=swap
PATH_MNT_ROOT="${PATH_MNT}/root"
&& error "${PARTITION} is already mounted"
true
}
-check_input_new_luksvg() {
- local NAME_LUKSVG=$1
+check_new_luksvg() {
local PATH_LUKS_MAPPER
PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}")
check_chars_legality "${NAME_LUKSVG}" "volume group name"
}
check_input_openable_luksvg() {
local PARTITION=$1
- local NAME_LUKSVG=$2
- check_input_new_luksvg "${NAME_LUKSVG}"
+ check_input_new_luksvg
try_quiet cryptsetup isLuks "${PARTITION}"\
|| error "${PARTITION} not a LUKS container"
}
# helpers: luks open/close
open_luksvg () {
local PARTITION=$1
- local LUKSVG=$2
- msg 'Opening LUKS container as "%s" …' "${LUKSVG}"
- cryptsetup luksOpen "${PARTITION}" "${LUKSVG}"
+ msg 'Opening LUKS container as "%s" …' "${NAME_LUKSVG}"
+ cryptsetup luksOpen "${PARTITION}" "${NAME_LUKSVG}"
}
close_luksvg () {
- local LUKSVG=$1
msg 'Deactivating volume group and closing LUKS container …'
- vgchange -an "${LUKSVG}"
- cryptsetup luksClose "${LUKSVG}"
+ vgchange -an "${NAME_LUKSVG}"
+ cryptsetup luksClose "${NAME_LUKSVG}"
}
# helpers: mount/unmount root
# inputs to confirm
usage $# "partition" "volume-group-name" "root-name" "command"
PARTITION=$1
-NAME_LUKSVG=$2
NAME_ROOT=$3
COMMAND=$4
# sanity checks
check_tools cryptsetup vgs
check_input_partition_mountable "${PARTITION}"
-check_input_openable_luksvg "${PARTITION}" "${NAME_LUKSVG}"
+check_input_openable_luksvg "${PARTITION}"
# mount
-open_luksvg "${PARTITION}" "${NAME_LUKSVG}"
+open_luksvg "${PARTITION}"
await_path "${PATH_VG_ROOT}"
mount_privately "${PATH_VG_ROOT}" "${PATH_MNT_ROOT}"
rbind_mnt
# clean up mounts
unmount_unrbind
-close_luksvg "${NAME_LUKSVG}"
+close_luksvg
msg 'Finished! (command exit status: %s)' "${RC}"
exit "${RC}"
# inputs to confirm
usage $# "partition" "volume-group-name" "boot-name"
PARTITION=$1
-NAME_LUKSVG=$2
-NAME_BOOT=$3
+NAME_BOOT=$2
NAME_ROOT="${NAME_BOOT}"
# constants derived from changeables
# sanity checks
check_tools cryptsetup debootstrap efibootmgr lvcreate mkfs.ext4 vgs
check_input_partition_mountable "${PARTITION}"
-check_input_openable_luksvg "${PARTITION}" "${NAME_LUKSVG}"
+check_input_openable_luksvg "${PARTITION}"
check_chars_legality "${NAME_BOOT}" "boot label"
[ -e "${PATH_EFI}/${NAME_BOOT}" ]\
&& error "${PATH_EFI}/${NAME_BOOT} already exists"
# run inputs by user and ask for confirmation
msg 'Your installation choices:'
msg '- target partition: [ %s ]' "${PARTITION}"
-msg '- target volume group: [ %s ]' "${NAME_LUKSVG}"
msg '- name for new boot option: [ %s ]' "${NAME_BOOT}"
# set up logival volume and filesystem
-open_luksvg "${PARTITION}" "${NAME_LUKSVG}"
+open_luksvg "${PARTITION}"
create_lv "${NAME_LUKSVG}" "${NAME_ROOT}" 10G
await_path "${PATH_VG_ROOT}"
msg 'Creating EXT4 filesystem …'
# clean up mounts
unmount_unrbind
-close_luksvg "${NAME_LUKSVG}"
+close_luksvg
msg 'Finished!'
# inputs to confirm
usage $# "partition" "volume-group-name"
PARTITION=$1
-NAME_LUKSVG=$2
# constants we might want to change at some point
CONFIG_FILES_TO_COPY="start_root.sh start_home.sh _lib.sh"
# sanity checks
check_tools cryptsetup lvcreate mkfs.ext4 mkswap pvcreate vgcreate vgs
check_input_partition_mountable "${PARTITION}"
-check_input_new_luksvg "${NAME_LUKSVG}"
+check_new_luksvg
try_quiet cryptsetup isLuks "${PARTITION}"\
&& error "${PARTITION} is already a LUKS container"
# run inputs by user and ask for confirmation
-msg 'Your formatting choices:'
-msg '- target partition (WILL BE ERASED!): [ %s ]' "${PARTITION}"
-msg '- name for new volume group and its LUKS mapper: [ %s ]' "${NAME_LUKSVG}"
+msg 'Your target partition (WILL BE ERASED!): [ %s ]' "${PARTITION}"
msg_nonl 'To continue, type "YES!" (all caps, exclamation mark, no quotes): '
read -r CONFIRM; [ "${CONFIRM}" = 'YES!' ]\
|| die 'ABORTED: expected confirmation not given.'
# encrypt partition
msg 'Formatting %s as LUKS container …' "${PARTITION}"
cryptsetup luksFormat --batch-mode "${PARTITION}"
-open_luksvg "${PARTITION}" "${NAME_LUKSVG}"
+open_luksvg "${PARTITION}"
# set up LVM and filesystems
msg 'Creating volume group "%s" inside LUKS container …' "${NAME_LUKSVG}"
umount "${PATH_MNT_DATA}"
# clean-up
-close_luksvg "${NAME_LUKSVG}"
+close_luksvg
msg 'Finished!'