public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] expand-on-first-boot: Expand crypto_LUKS partition
@ 2024-01-19 18:08 Quirin Gylstorff
  2024-01-26  7:38 ` Uladzimir Bely
  0 siblings, 1 reply; 2+ messages in thread
From: Quirin Gylstorff @ 2024-01-19 18:08 UTC (permalink / raw)
  To: isar-users

From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

Add the option to expand a encrypted LUKS partition.
A passphrase is required to resize the partition.

If cryptsetup is not installed the service still fails with
an error message.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 .../files/expand-last-partition.sh            | 22 +++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 7d658864..94962e40 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -65,14 +65,28 @@ fi
 # some filesystems need to be mounted i.e. btrfs, but mounting also helps
 # detect the filesystem type without having to wait for udev
 # mount $LAST_PART out of tree, so we won't conflict with other mounts
-MOUNT_POINT=$(mktemp -d -p "" "$(basename "$0").XXXXXXXXXX")
-mount "${LAST_PART}" "${MOUNT_POINT}"
-
 ret=0
 # Determine the filesystem type and perform the appropriate resize function
-FS_TYPE=$(findmnt -fno FSTYPE "${MOUNT_POINT}" )
+FS_TYPE=$(blkid --output value --match-tag TYPE "${LAST_PART}" )
+MOUNT_POINT=$(mktemp -d -p "" "$(basename "$0").XXXXXXXXXX")
+if [ "$FS_TYPE" = "crypto_LUKS" ]; then
+	if [ ! -x /usr/sbin/cryptsetup ]; then
+		echo "'cryptsetup' is missing cannot resize last partition as it is from type 'crypto_LUKS'"
+		exit 1
+	fi
+	last_part_device_name=${LAST_PART#\/dev/}
+
+	mapping_name=$(cat /sys/class/block/"$last_part_device_name"/holders/*/dm/name)
+	cryptsetup resize "$mapping_name"
+	mount /dev/mapper/"$mapping_name" "${MOUNT_POINT}"
+	FS_TYPE=$(findmnt -fno FSTYPE "${MOUNT_POINT}" )
+	LAST_PART=/dev/mapper/"$mapping_name"
+else
+	mount "${LAST_PART}" "${MOUNT_POINT}"
+fi
 case ${FS_TYPE} in
 ext*)
+
 	# Do not fail resize2fs if no mtab entry is found, e.g.,
 	# when using systemd mount units.
 	export EXT2FS_NO_MTAB_OK=1
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] expand-on-first-boot: Expand crypto_LUKS partition
  2024-01-19 18:08 [PATCH] expand-on-first-boot: Expand crypto_LUKS partition Quirin Gylstorff
@ 2024-01-26  7:38 ` Uladzimir Bely
  0 siblings, 0 replies; 2+ messages in thread
From: Uladzimir Bely @ 2024-01-26  7:38 UTC (permalink / raw)
  To: Quirin Gylstorff, isar-users

On Fri, 2024-01-19 at 19:08 +0100, 'Quirin Gylstorff' via isar-users
wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> Add the option to expand a encrypted LUKS partition.
> A passphrase is required to resize the partition.
> 
> If cryptsetup is not installed the service still fails with
> an error message.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  .../files/expand-last-partition.sh            | 22 +++++++++++++++--
> --
>  1 file changed, 18 insertions(+), 4 deletions(-)

Applied to next, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-26  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19 18:08 [PATCH] expand-on-first-boot: Expand crypto_LUKS partition Quirin Gylstorff
2024-01-26  7:38 ` Uladzimir Bely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox