From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7117959015048413184 X-Received: by 2002:a2e:b165:0:b0:25b:df29:562a with SMTP id a5-20020a2eb165000000b0025bdf29562amr873246ljm.183.1657695784832; Wed, 13 Jul 2022 00:03:04 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:651c:2102:b0:25d:5f70:6f64 with SMTP id a2-20020a05651c210200b0025d5f706f64ls913002ljq.1.gmail; Wed, 13 Jul 2022 00:03:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1svapuTYnbOkd6sG4ZVTjWKJSgtIaH6flV3umrjZof8lXVyIRKoKZvNdms3U45ndtLkZmB2 X-Received: by 2002:a05:651c:1502:b0:25a:8c33:5935 with SMTP id e2-20020a05651c150200b0025a8c335935mr973402ljf.246.1657695783292; Wed, 13 Jul 2022 00:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657695783; cv=none; d=google.com; s=arc-20160816; b=uvRy7dNo83p9tGnN8IQrhl3FXpKTHEJDBnw+AoYYY+2sp8GkSpVJ0l0YBdi7AACsfh kBqKwphuzT8RwaPiq0vWw4DIbdP/6st8XgVNTzPWPQRq90e8tHjs2PXkcil59e74Bjp8 m/Q4b4igM4vEolAgvY8cm3ZKJ/rNaXO+Hs38/Ji29EcATgwaK7C8/TXOFkzIrxOxiWyn 1EBaZRz7jwQ+76JLYBD9txNRvrcFHBlNM+HijTXUitAdnzejYDnCX/iCFMW13pmtnfdT POiAd6z58Vo7Lf2YKkROSFaQs1wnzbXyVSfiaLoejTKKJ9EME1KuJAd/w6X/PU8H93B6 sixA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from; bh=yT39O+0nBvi0gTckXOkP+nFcuYmnUm+Uf9z3Sk907vc=; b=bjT3X4Hrdzh673yfYllFruvrCs9R8Am60NxHzs+aQsDxWd+66ErK7LmIcYcxhhj4Ty pTZ+sgZiYxIk+H/bTR1ZpaqmnaQyrEKrSRnCsp60B5h8C5tNZZucy7aaQi8fiimnMtlM oyXZ2wcUawII2YX2Q7+LnOkQpioiEKtKz9b2UxJKpV/zbdNjKYttSMaixAuNBK+5ErLO nv7aMonR8KgzPr+tndBWzFagMRkeWpEpK6rbBpzYpKneu3so2LCR69vz0PZ3Kj9b1M+k d2iWpg9YX24Cak28zZFrqGH+Wfa5GO+2VZXkenWCzmG01XpjWRmXjbtYbUt4MqbRF4Ek KdBA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id 13-20020ac25f4d000000b00482b3534361si406705lfz.6.2022.07.13.00.03.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jul 2022 00:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Received: from home.localnet (44-208-124-178-static.mgts.by [178.124.208.44] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 26D731EF015716 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Jul 2022 09:03:02 +0200 From: Uladzimir Bely To: isar-users@googlegroups.com, Tobias Schmidl Subject: Re: [PATCH v2 1/1] expand-on-first-boot: Check size before resizing Date: Wed, 13 Jul 2022 10:03:00 +0300 Message-ID: <3438679.dWV9SEqChM@home> In-Reply-To: <20220711081602.81904-2-tobiasschmidl@siemens.com> References: <20220711081602.81904-1-tobiasschmidl@siemens.com> <20220711081602.81904-2-tobiasschmidl@siemens.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="nextPart5388726.rdbgypaU67" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,HTML_MESSAGE autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: W5vLkLMP6B6o This is a multi-part message in MIME format. --nextPart5388726.rdbgypaU67 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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 > --- > .../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 --nextPart5388726.rdbgypaU67 Content-Transfer-Encoding: 7Bit Content-Type: text/html; charset="us-ascii"

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


--nextPart5388726.rdbgypaU67--