fix(lvm,cryptroot extensions): introduce another variable to keep track of the physical partition/uuid and rootdevice/uuid seperately

This commit is contained in:
M.Schmidt
2024-11-29 23:05:49 +01:00
committed by Igor
parent 43166a8354
commit 3ec24d40e8
2 changed files with 12 additions and 11 deletions

View File

@@ -72,12 +72,6 @@ function post_create_partitions__setup_lvm() {
function prepare_root_device__create_volume_group() {
LOOP=$(losetup -f)
[[ -z $LOOP ]] && exit_with_error "Unable to find free loop device"
check_loop_device "$LOOP"
losetup $LOOP ${SDCARD}.raw
partprobe $LOOP
display_alert "Using LVM root" "${EXTENSION}" "info"
vgscan
vgchange -a y ${LVM_VG_NAME}
@@ -97,4 +91,4 @@ function post_umount_final_image__close_lvm() {
# Deactivat the Volume Group
vgchange -a n ${LVM_VG_NAME}
display_alert "LVM deactivated volume group" "${EXTENSION}" "info"
}
}

View File

@@ -244,6 +244,8 @@ function prepare_partitions() {
display_alert "Partitioning with the following options" "$partition_script_output" "debug"
echo "${partition_script_output}" | run_host_command_logged sfdisk "${SDCARD}".raw || exit_with_error "Partitioning failed!"
fi
declare -g LOOP
call_extension_method "post_create_partitions" <<- 'POST_CREATE_PARTITIONS'
*called after all partitions are created, but not yet formatted*
@@ -254,7 +256,7 @@ function prepare_partitions() {
exec {FD}> /var/lock/armbian-debootstrap-losetup
flock -x $FD
declare -g LOOP
#--partscan is using to force the kernel for scaning partition table in preventing of partprobe errors
LOOP=$(losetup --show --partscan --find "${SDCARD}".raw) || exit_with_error "Unable to find free loop device"
display_alert "Allocated loop device" "LOOP=${LOOP}"
@@ -277,6 +279,7 @@ function prepare_partitions() {
## ROOT PARTITION
##
if [[ -n $rootpart ]]; then
local physical_rootdevice="${LOOP}p${rootpart}"
local rootdevice="${LOOP}p${rootpart}"
call_extension_method "prepare_root_device" <<- 'PREPARE_ROOT_DEVICE'
@@ -303,6 +306,10 @@ function prepare_partitions() {
root_part_uuid="$(blkid -s UUID -o value ${LOOP}p${rootpart})"
declare -g -r ROOT_PART_UUID="${root_part_uuid}"
physical_root_part_uuid="$(blkid -s UUID -o value $physical_rootdevice)"
declare -g -r PHYSICAL_ROOT_PART_UUID="${physical_root_part_uuid}"
display_alert "Physical root device" "$physical_rootdevice (UUID=${PHYSICAL_ROOT_PART_UUID})" "debug"
display_alert "Mounting rootfs" "$rootdevice (UUID=${ROOT_PART_UUID})"
run_host_command_logged mount ${fscreateopt} $rootdevice $MOUNT/
@@ -310,7 +317,7 @@ function prepare_partitions() {
local rootfs
if [[ $CRYPTROOT_ENABLE == yes ]]; then
# map the LUKS container partition via its UUID to be the 'cryptroot' device
echo "$CRYPTROOT_MAPPER UUID=${root_part_uuid} none luks" >> $SDCARD/etc/crypttab
echo "$CRYPTROOT_MAPPER UUID=${physical_root_part_uuid} none luks" >> $SDCARD/etc/crypttab
rootfs=$rootdevice # used in fstab
else
rootfs="UUID=$(blkid -s UUID -o value $rootdevice)"
@@ -369,7 +376,7 @@ function prepare_partitions() {
if [[ -f $SDCARD/boot/armbianEnv.txt ]]; then
display_alert "Found armbianEnv.txt" "${SDCARD}/boot/armbianEnv.txt" "debug"
if [[ $CRYPTROOT_ENABLE == yes ]]; then
echo "rootdev=$rootdevice cryptdevice=UUID=${root_part_uuid}:$CRYPTROOT_MAPPER" >> "${SDCARD}/boot/armbianEnv.txt"
echo "rootdev=$rootdevice cryptdevice=UUID=${physical_root_part_uuid}:$CRYPTROOT_MAPPER" >> "${SDCARD}/boot/armbianEnv.txt"
else
echo "rootdev=$rootfs" >> "${SDCARD}/boot/armbianEnv.txt"
fi
@@ -388,7 +395,7 @@ function prepare_partitions() {
display_alert "Found boot.ini" "${SDCARD}/boot/boot.ini" "debug"
sed -i -e "s/rootfstype \"ext4\"/rootfstype \"$ROOTFS_TYPE\"/" $SDCARD/boot/boot.ini
if [[ $CRYPTROOT_ENABLE == yes ]]; then
rootpart="UUID=${root_part_uuid}"
rootpart="UUID=${physical_root_part_uuid}"
sed -i 's/^setenv rootdev .*/setenv rootdev "\/dev\/mapper\/'$CRYPTROOT_MAPPER' cryptdevice='$rootpart':'$CRYPTROOT_MAPPER'"/' $SDCARD/boot/boot.ini
else
sed -i 's/^setenv rootdev .*/setenv rootdev "'$rootfs'"/' $SDCARD/boot/boot.ini