Test if Luks is available and try to open it

This commit is contained in:
gardouille 2020-10-21 09:19:55 +02:00
parent 5344598918
commit 2e43d4f855
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 22 additions and 0 deletions

22
debian/chroot.mount vendored
View File

@ -20,6 +20,28 @@ new_hostname=""
vgname=$(vgdisplay --short | tail -n 1 | sed 's/.*"\(.*\)" .*/\1/')
## If the script should create extra volume (eg. backup, virt, Proxmox,…)
manage_extra_lv=0
## Is LUKS {{{
if blkid | grep "${hdd}.*crypto_LUKS"; then
manage_luks=0
## You need to set a new passphrase after the installation or at least change this one
luks_passphrase="generic key"
luks_key_file="/tmp/luks.keyfile.temp"
luks_pv_name=$(basename "${hdd}"2_crypt)
else
manage_luks=1
fi
## }}}
## Open LUKS system {{{
if [ "${manage_luks}" -eq 0 ]; then
### Put passphrase in a keyfile for multiple usage
rm -f -- "${luks_key_file}" && printf '%b\n' "${luks_passphrase}" > "${luks_key_file}"
### If the volume is not already opened
if [ ! -h /dev/mapper/"${luks_pv_name}" ]; then
### Open LUKS system
cryptsetup luksOpen "${hdd}"2 "${luks_pv_name}" --key-file "${luks_key_file}" || exit 2
fi
fi
## }}}
## Is BTRFS {{{
root_fs_type=$(lsblk -f /dev/mapper/"${vgname}"-root | awk '/root/ { print $2 }')
if [ "${root_fs_type}" = "btrfs" ]; then