expand-on-first-boot: search until no device mapper is used

Message ID 20240417065534.1678488-1-Quirin.Gylstorff@siemens.com
State Accepted, archived
Headers show
Series expand-on-first-boot: search until no device mapper is used | expand

Commit Message

Quirin Gylstorff April 17, 2024, 6:55 a.m. UTC
From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

Device mapper block devices can be stacked e.g.
in case a hard disk is encrypted and uses lvm:
sda
+-sda1                  259:3    0 2G  0 part
  +-sda1_crypt          253:0    0 2G  0 crypt
    +-debian--vg-root   253:1    0 1G  0 lvm

So we should traverse the `slaves` until we reach the endpoint.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 .../expand-on-first-boot/files/expand-last-partition.sh        | 3 +++
 1 file changed, 3 insertions(+)

Comments

Uladzimir Bely April 26, 2024, 6:07 a.m. UTC | #1
On Wed, 2024-04-17 at 08:55 +0200, 'Quirin Gylstorff' via isar-users
wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> Device mapper block devices can be stacked e.g.
> in case a hard disk is encrypted and uses lvm:
> sda
> +-sda1                  259:3    0 2G  0 part
>   +-sda1_crypt          253:0    0 2G  0 crypt
>     +-debian--vg-root   253:1    0 1G  0 lvm
> 
> So we should traverse the `slaves` until we reach the endpoint.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>  .../expand-on-first-boot/files/expand-last-partition.sh        | 3
> +++
>  1 file changed, 3 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 84f1219f..0cb2ee21 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
> @@ -12,6 +12,9 @@ set -e
>  ROOT_DEV="$(findmnt / -o source -n)"
>  ROOT_DEV_NAME=${ROOT_DEV##*/}
>  ROOT_DEV_SLAVE=$(find /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth
> 1 -print -quit 2>/dev/null || true)
> +while [ -d "${ROOT_DEV_SLAVE}/slaves" ]; do
> +	ROOT_DEV_SLAVE=$(find "${ROOT_DEV_SLAVE}"/slaves -mindepth 1
> -print -quit 2>/dev/null || true)
> +done
>  if [ -n "${ROOT_DEV_SLAVE}" ]; then
>  	ROOT_DEV=/dev/${ROOT_DEV_SLAVE##*/}
>  fi
> -- 
> 2.43.0
> 

Applied to next, thanks.

Patch

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 84f1219f..0cb2ee21 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
@@ -12,6 +12,9 @@  set -e
 ROOT_DEV="$(findmnt / -o source -n)"
 ROOT_DEV_NAME=${ROOT_DEV##*/}
 ROOT_DEV_SLAVE=$(find /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth 1 -print -quit 2>/dev/null || true)
+while [ -d "${ROOT_DEV_SLAVE}/slaves" ]; do
+	ROOT_DEV_SLAVE=$(find "${ROOT_DEV_SLAVE}"/slaves -mindepth 1 -print -quit 2>/dev/null || true)
+done
 if [ -n "${ROOT_DEV_SLAVE}" ]; then
 	ROOT_DEV=/dev/${ROOT_DEV_SLAVE##*/}
 fi