Message ID | 20240502093240.364093-4-Quirin.Gylstorff@siemens.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add option to encrypt the rootfs | expand |
On Thu, 2024-05-02 at 11:31 +0200, Quirin Gylstorff wrote: > From: Quirin Gylstorff <quirin.gylstorff@siemens.com> > > squashfs or empty partition cannot be resized with resize2fs. > > Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com> > --- > .../files/encrypt_partition.script | 20 +++++++++++++++-- > -- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/recipes-initramfs/initramfs-crypt- > hook/files/encrypt_partition.script b/recipes-initramfs/initramfs- > crypt-hook/files/encrypt_partition.script > index 8f6cbf6..51c81f3 100644 > --- a/recipes-initramfs/initramfs-crypt- > hook/files/encrypt_partition.script > +++ b/recipes-initramfs/initramfs-crypt- > hook/files/encrypt_partition.script > @@ -64,14 +64,26 @@ service_watchdog() { > reencrypt_existing_partition() { > part_size_blocks="$(cat /sys/class/block/"$(awk -v dev="$1" > 'BEGIN{split(dev,a,"/"); print a[3]}' )"/size)" > # reduce the filesystem and partition by 32M to fit the LUKS > header > + partition_fstype=$(get_fstype "${1}") > reduce_device_size=32768 > reduced_size="$(expr "$part_size_blocks" - 65536 )" > reduced_size_in_byte="$(expr "$reduced_size" \* 512)" > reduced_size_in_kb="$(expr "$reduced_size_in_byte" / 1024)K" > - e2fsck -f "$1" > - if ! resize2fs "$1" "${reduced_size_in_kb}"; then > - panic "reencryption of filesystem $1 cannot > continue!" > - fi > + case $partition_fstype in > + ext*) > + # reduce the filesystem and partition by 32M to fit > the LUKS header > + e2fsck -f "$1" > + if ! resize2fs "$1" "${reduced_size_in_kb}"; then > + panic "reencryption of filesystem $1 cannot > continue!" > + fi > + ;; > + squashfs|"") > + echo "skip disk resize as it not support or ---------------------------------------------^ it is not supported Felix > unnecessary for fstype: '$partition_fstype'" > + ;; > + *) > + panic "cannot resize parition. unsupport fstype: > $partition_fstype" > + ;; > + esac > if [ -x /usr/sbin/cryptsetup-reencrypt ]; then > /usr/sbin/cryptsetup-reencrypt --new --reduce-device- > size "$reduce_device_size"k "$1" < "$2" > else
diff --git a/recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script b/recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script index 8f6cbf6..51c81f3 100644 --- a/recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script +++ b/recipes-initramfs/initramfs-crypt-hook/files/encrypt_partition.script @@ -64,14 +64,26 @@ service_watchdog() { reencrypt_existing_partition() { part_size_blocks="$(cat /sys/class/block/"$(awk -v dev="$1" 'BEGIN{split(dev,a,"/"); print a[3]}' )"/size)" # reduce the filesystem and partition by 32M to fit the LUKS header + partition_fstype=$(get_fstype "${1}") reduce_device_size=32768 reduced_size="$(expr "$part_size_blocks" - 65536 )" reduced_size_in_byte="$(expr "$reduced_size" \* 512)" reduced_size_in_kb="$(expr "$reduced_size_in_byte" / 1024)K" - e2fsck -f "$1" - if ! resize2fs "$1" "${reduced_size_in_kb}"; then - panic "reencryption of filesystem $1 cannot continue!" - fi + case $partition_fstype in + ext*) + # reduce the filesystem and partition by 32M to fit the LUKS header + e2fsck -f "$1" + if ! resize2fs "$1" "${reduced_size_in_kb}"; then + panic "reencryption of filesystem $1 cannot continue!" + fi + ;; + squashfs|"") + echo "skip disk resize as it not support or unnecessary for fstype: '$partition_fstype'" + ;; + *) + panic "cannot resize parition. unsupport fstype: $partition_fstype" + ;; + esac if [ -x /usr/sbin/cryptsetup-reencrypt ]; then /usr/sbin/cryptsetup-reencrypt --new --reduce-device-size "$reduce_device_size"k "$1" < "$2" else