public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH v2 0/1] expand-on-first-boot: Check size before resizing
@ 2022-07-11  8:16 Tobias Schmidl
  2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
  2022-07-20 12:38 ` [PATCH v2 0/1] " Schmidl, Tobias
  0 siblings, 2 replies; 8+ messages in thread
From: Tobias Schmidl @ 2022-07-11  8:16 UTC (permalink / raw)
  To: isar-users
  Cc: Florian Bezdeka, Jan Kiszka, Henning Schild,
	Felix Mößbauer, Tobias Schmidl

Diff to v1:
- Reduced console output

Tobias Schmidl (1):
  expand-on-first-boot: Check size before resizing

 .../files/expand-last-partition.sh               | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

-- 
2.36.1


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

* [PATCH v2 1/1] expand-on-first-boot: Check size before resizing
  2022-07-11  8:16 [PATCH v2 0/1] expand-on-first-boot: Check size before resizing Tobias Schmidl
@ 2022-07-11  8:16 ` Tobias Schmidl
  2022-07-11  8:52   ` Henning Schild
                     ` (2 more replies)
  2022-07-20 12:38 ` [PATCH v2 0/1] " Schmidl, Tobias
  1 sibling, 3 replies; 8+ messages in thread
From: Tobias Schmidl @ 2022-07-11  8:16 UTC (permalink / raw)
  To: isar-users
  Cc: Florian Bezdeka, Jan Kiszka, Henning Schild,
	Felix Mößbauer, Tobias Schmidl

If the disk is too small, resizing might have detrimental effects.
Because of aligning issues, it could happen the the final partition is
_smaller_ than desired, which might lead to an unusable last partition.

Signed-off-by: Tobias Schmidl <tobiasschmidl@siemens.com>
---
 .../files/expand-last-partition.sh               | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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 c0edde7..0aa1063 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
@@ -22,6 +22,22 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
 	exit 1
 fi
 
+# this value is in blocks. Normally a block has 512 bytes.
+BUFFER_SIZE=32768
+BOOT_DEV_NAME=${BOOT_DEV##*/}
+DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
+ALL_PARTS_SIZE=0
+for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do
+	PART_SIZE=$(cat "${PARTITION}"/size)
+	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
+done
+
+MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
+if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
+	echo "Disk is practically already full, doing nothing." >&2
+	exit 0
+fi
+
 LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
 
 # Transform the partition table as follows:
-- 
2.36.1


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

* Re: [PATCH v2 1/1] expand-on-first-boot: Check size before resizing
  2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
@ 2022-07-11  8:52   ` Henning Schild
  2022-07-13  7:03   ` Uladzimir Bely
  2022-07-13  8:00   ` Uladzimir Bely
  2 siblings, 0 replies; 8+ messages in thread
From: Henning Schild @ 2022-07-11  8:52 UTC (permalink / raw)
  To: Tobias Schmidl
  Cc: isar-users, Florian Bezdeka, Jan Kiszka, Felix Mößbauer

LGTM, i also like the idea of asking whether it is worth growing instead
of asking the more complicated question whether we would potentially
shrink trying to grow.

Henning

Am Mon, 11 Jul 2022 10:16:02 +0200
schrieb Tobias Schmidl <tobiasschmidl@siemens.com>:

> If the disk is too small, resizing might have detrimental effects.
> Because of aligning issues, it could happen the the final partition is
> _smaller_ than desired, which might lead to an unusable last
> partition.
> 
> Signed-off-by: Tobias Schmidl <tobiasschmidl@siemens.com>
> ---
>  .../files/expand-last-partition.sh               | 16
> ++++++++++++++++ 1 file changed, 16 insertions(+)
> 
> 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 c0edde7..0aa1063 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
> @@ -22,6 +22,22 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then exit 1
> fi +# this value is in blocks. Normally a block has 512 bytes.
> +BUFFER_SIZE=32768
> +BOOT_DEV_NAME=${BOOT_DEV##*/}
> +DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
> +ALL_PARTS_SIZE=0
> +for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do
> +	PART_SIZE=$(cat "${PARTITION}"/size)
> +	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
> +done
> +
> +MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
> +if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
> +	echo "Disk is practically already full, doing nothing." >&2
> +	exit 0
> +fi
> +
>  LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d
> ' ' -f 1)" 
>  # Transform the partition table as follows:


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

* Re: [PATCH v2 1/1] expand-on-first-boot: Check size before resizing
  2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
  2022-07-11  8:52   ` Henning Schild
@ 2022-07-13  7:03   ` Uladzimir Bely
  2022-07-13  8:00   ` Uladzimir Bely
  2 siblings, 0 replies; 8+ messages in thread
From: Uladzimir Bely @ 2022-07-13  7:03 UTC (permalink / raw)
  To: isar-users, Tobias Schmidl

[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]

In the email from Monday, 11 July 2022 11:16:02 +03 user Tobias Schmidl wrote:
> If the disk is too small, resizing might have detrimental effects.
> Because of aligning issues, it could happen the the final partition is
> _smaller_ than desired, which might lead to an unusable last partition.
> 
> Signed-off-by: Tobias Schmidl <tobiasschmidl@siemens.com>
> ---
>  .../files/expand-last-partition.sh               | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> 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 c0edde7..0aa1063 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
> @@ -22,6 +22,22 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
>  	exit 1
>  fi
> 
> +# this value is in blocks. Normally a block has 512 bytes.
> +BUFFER_SIZE=32768
> +BOOT_DEV_NAME=${BOOT_DEV##*/}
> +DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
> +ALL_PARTS_SIZE=0
> +for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do

It seems to be working only for something like 'sda' => 'sda1'.

For RPi I have  
root@isar:~# ls /sys/class/block/ | grep mmc 
mmcblk0 
mmcblk0p1 
mmcblk0p2
So, "p" suffix is required.

Some other devices (like nvme) also need some prefix.

> +	PART_SIZE=$(cat "${PARTITION}"/size)
> +	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
> +done
> +
> +MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
> +if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
> +	echo "Disk is practically already full, doing nothing." >&2
> +	exit 0
> +fi
> +
>  LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f
> 1)"
> 
>  # Transform the partition table as follows:


-- 
Uladzimir Bely


[-- Attachment #2: Type: text/html, Size: 6249 bytes --]

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

* Re: [PATCH v2 1/1] expand-on-first-boot: Check size before resizing
  2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
  2022-07-11  8:52   ` Henning Schild
  2022-07-13  7:03   ` Uladzimir Bely
@ 2022-07-13  8:00   ` Uladzimir Bely
  2022-07-13  8:05     ` Schmidl, Tobias
  2 siblings, 1 reply; 8+ messages in thread
From: Uladzimir Bely @ 2022-07-13  8:00 UTC (permalink / raw)
  To: isar-users, Tobias Schmidl

In the email from Monday, 11 July 2022 11:16:02 +03 user Tobias Schmidl wrote:
> If the disk is too small, resizing might have detrimental effects.
> Because of aligning issues, it could happen the the final partition is
> _smaller_ than desired, which might lead to an unusable last partition.
> 
> Signed-off-by: Tobias Schmidl <tobiasschmidl@siemens.com>
> ---
>  .../files/expand-last-partition.sh               | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> 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 c0edde7..0aa1063 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
> @@ -22,6 +22,22 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
>  	exit 1
>  fi
> 
> +# this value is in blocks. Normally a block has 512 bytes.
> +BUFFER_SIZE=32768
> +BOOT_DEV_NAME=${BOOT_DEV##*/}
> +DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
> +ALL_PARTS_SIZE=0
> +for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do

While whole device directory in 'sys/class/block' includes all partitions as 
subfolders, I would change it to

+for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"/"${BOOT_DEV_NAME}"*; do

It should cover all cases like 'sda/sdaX', 'mmcblk0/mmcblk0pX', 'nvme0/
nvme0pX' and similar.

> +	PART_SIZE=$(cat "${PARTITION}"/size)
> +	ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
> +done
> +
> +MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
> +if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
> +	echo "Disk is practically already full, doing nothing." >&2
> +	exit 0
> +fi
> +
>  LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f
> 1)"
> 
>  # Transform the partition table as follows:


-- 
Uladzimir Bely




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

* Re: [PATCH v2 1/1] expand-on-first-boot: Check size before resizing
  2022-07-13  8:00   ` Uladzimir Bely
@ 2022-07-13  8:05     ` Schmidl, Tobias
  0 siblings, 0 replies; 8+ messages in thread
From: Schmidl, Tobias @ 2022-07-13  8:05 UTC (permalink / raw)
  To: ubely, isar-users

Hi Uladzimir,

Am Mittwoch, dem 13.07.2022 um 11:00 +0300 schrieb Uladzimir Bely:
> 
> While whole device directory in 'sys/class/block' includes all
> partitions as 
> subfolders, I would change it to
> 
> +for PARTITION in
> /sys/class/block/"${BOOT_DEV_NAME}"/"${BOOT_DEV_NAME}"*; do
> 
> It should cover all cases like 'sda/sdaX', 'mmcblk0/mmcblk0pX', 'nvme0/
> nvme0pX' and similar.
> 
> 

thanks for the suggestion, will post the corrected past right after
testing.

Kinds regards,


Tobias

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

* Re: [PATCH v2 0/1] expand-on-first-boot: Check size before resizing
  2022-07-11  8:16 [PATCH v2 0/1] expand-on-first-boot: Check size before resizing Tobias Schmidl
  2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
@ 2022-07-20 12:38 ` Schmidl, Tobias
  2022-07-20 12:44   ` Anton Mikanovich
  1 sibling, 1 reply; 8+ messages in thread
From: Schmidl, Tobias @ 2022-07-20 12:38 UTC (permalink / raw)
  To: isar-users
  Cc: Bezdeka, Florian, jan.kiszka, Moessbauer, Felix, Schild, Henning

Hi all,

Am Montag, dem 11.07.2022 um 10:16 +0200 schrieb Tobias Schmidl:
> Diff to v1:
> - Reduced console output
> 
> Tobias Schmidl (1):
>   expand-on-first-boot: Check size before resizing
> 
>  .../files/expand-last-partition.sh               | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 

What is the status of this patch? Are there any impediments?

Kind regards,

Tobias


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

* Re: [PATCH v2 0/1] expand-on-first-boot: Check size before resizing
  2022-07-20 12:38 ` [PATCH v2 0/1] " Schmidl, Tobias
@ 2022-07-20 12:44   ` Anton Mikanovich
  0 siblings, 0 replies; 8+ messages in thread
From: Anton Mikanovich @ 2022-07-20 12:44 UTC (permalink / raw)
  To: Schmidl, Tobias, isar-users
  Cc: Bezdeka, Florian, jan.kiszka, Moessbauer, Felix, Schild, Henning

20.07.2022 15:38, Schmidl, Tobias wrote:
> Hi all,
>
> Am Montag, dem 11.07.2022 um 10:16 +0200 schrieb Tobias Schmidl:
>> Diff to v1:
>> - Reduced console output
>>
>> Tobias Schmidl (1):
>>    expand-on-first-boot: Check size before resizing
>>
>>   .../files/expand-last-partition.sh               | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
> What is the status of this patch? Are there any impediments?
>
> Kind regards,
>
> Tobias
>
Hello Tobias,
This one is superseded. V3 planned to be merged to next tomorrow.


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

end of thread, other threads:[~2022-07-20 12:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11  8:16 [PATCH v2 0/1] expand-on-first-boot: Check size before resizing Tobias Schmidl
2022-07-11  8:16 ` [PATCH v2 1/1] " Tobias Schmidl
2022-07-11  8:52   ` Henning Schild
2022-07-13  7:03   ` Uladzimir Bely
2022-07-13  8:00   ` Uladzimir Bely
2022-07-13  8:05     ` Schmidl, Tobias
2022-07-20 12:38 ` [PATCH v2 0/1] " Schmidl, Tobias
2022-07-20 12:44   ` Anton Mikanovich

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