From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6599936908158042112 X-Received: by 2002:adf:9d1e:: with SMTP id k30-v6mr565010wre.20.1536827641683; Thu, 13 Sep 2018 01:34:01 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:23c4:: with SMTP id j187-v6ls1176149wmj.2.canary-gmail; Thu, 13 Sep 2018 01:34:01 -0700 (PDT) X-Google-Smtp-Source: ANB0VdanBLPqM0dZqoJEwOteILkpeXJ5fXeSn0CTt1Hin5eBcrGky+VadIBmNywM7PeuCvOO+V07 X-Received: by 2002:a1c:9955:: with SMTP id b82-v6mr633100wme.30.1536827641156; Thu, 13 Sep 2018 01:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536827641; cv=none; d=google.com; s=arc-20160816; b=d8/8TEM4ymjw5ijlmqoLDIY/le+HxTu8pOXjV4+RB3UVxRzgNqAOU3Hcw0HHuRAqBq fyO8PRr8plieB03EfaPpiPIrrpHqpXcU5S17P9KEpRKlCLzkiTZIdpbvHHZ32WCjrW1Q TO83nV3mS7aZiQDwPs14yZ9rKBtvJnI6QOmr+wDWWUnu+T1tJPVLAHtSU/VUtnbVL6/f BQt62RJPuj5T9YpUtuQukK5+nu2nL8VShbBn6eMYGIFlGv3plWYAIMQWTdNHU19XqoPs FOsKSRro7eB7C31g5tqpcDb3qpx0CqWOWzYVuUv1zz5HPZKxxAlEkK1A5HVVXXdDpbQz 05Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=04sSCbcd1YhZN2F8bbfXTuloVtsEQmuc1RtyaFw0TCg=; b=TM8f9eSCAFDQMmjRqev7imZzjcdbmN1MlD57nb+dozXOA9+VKVrDwyJanZ5+2J0yst aG1aIwPV4z1kSwDsBASTRcRj/O3w/8/eQ3swz4YwQWJhcGkiXJZwoS0ztBhfOVFPES4W 7y3nmL8ahCm4NgknIoCCOI9UPA30c30kE5j0+AXilfwR3PUPx4M2Th5IJKSwUBctrgEa C0kfGOKMqD/vuER4biIRiedjPWN3tGf9J+P/YgWypkUMEQD3m5x/4vUnam17xbROvur0 4AArFEr/NZtWXnSVkpMQZL7p9g+/5p1kGfgo4EcATlqD8JA9AMan2TaoSfMODICmLUm1 DRVQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Return-Path: Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id v18-v6si109292wmc.1.2018.09.13.01.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Sep 2018 01:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w8D8Y09P031305 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 13 Sep 2018 10:34:00 +0200 Received: from [139.22.119.149] ([139.22.119.149]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id w8D8Xxci011315; Thu, 13 Sep 2018 10:34:00 +0200 Subject: Re: [PATCH 12/16] meta: Add expand-on-first-boot support package To: Henning Schild Cc: isar-users References: <20180912154610.363a1bbb@md1pvb1c.ad001.siemens.net> From: Jan Kiszka Message-ID: <140f8df3-b0b8-8fe8-7ef3-a15bf1331330@siemens.com> Date: Thu, 13 Sep 2018 10:33:59 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: <20180912154610.363a1bbb@md1pvb1c.ad001.siemens.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: rLQ3jUJweMo8 On 12.09.18 15:46, Henning Schild wrote: > Am Tue, 11 Sep 2018 14:05:52 +0200 > schrieb "[ext] Jan Kiszka" : > >> From: Jan Kiszka >> >> When installed, this systemd service expands the last partition on a >> the boot medium to the full size of that medium. It then deactivates >> itself. >> >> Based on sysvinit version by Henning Schild. >> >> Signed-off-by: Jan Kiszka >> --- >> .../expand-on-first-boot/expand-on-first-boot.bb | 25 >> +++++++++++++++++ .../files/expand-last-partition.sh >> | 31 >> ++++++++++++++++++++++ .../files/expand-on-first-boot.service >> | 23 >> ++++++++++++++++ .../expand-on-first-boot/files/postinst >> | 3 +++ 4 files changed, 82 insertions(+) create mode 100644 >> meta/recipes-support/expand-on-first-boot/expand-on-first-boot.bb >> create mode 100644 >> meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh >> create mode 100644 >> meta/recipes-support/expand-on-first-boot/files/expand-on-first-boot.service >> create mode 100644 >> meta/recipes-support/expand-on-first-boot/files/postinst >> >> diff --git >> a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot.bb >> b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot.bb >> new file mode 100644 index 0000000..49d6c3b --- /dev/null >> +++ >> b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot.bb >> @@ -0,0 +1,25 @@ +# Resize last partition to full medium size on fist >> boot +# >> +# This software is a part of ISAR. >> +# Copyright (c) Siemens AG, 2018 >> +# >> +# SPDX-License-Identifier: MIT >> + >> +inherit dpkg-raw >> + >> +DESCRIPTION = "This service grows the last partition to the full >> medium during first boot" + >> +DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, >> util-linux" + >> +SRC_URI = " \ >> + file://expand-on-first-boot.service \ >> + file://expand-last-partition.sh \ >> + file://postinst" >> + >> +do_install() { >> + install -d -m 755 ${D}/lib/systemd/system >> + install -m 644 ${WORKDIR}/expand-on-first-boot.service >> ${D}/lib/systemd/system/ + >> + install -d -m 755 ${D}/usr/share/expand-on-first-boot >> + install -m 755 ${WORKDIR}/expand-last-partition.sh >> ${D}/usr/share/expand-on-first-boot/ +} >> 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 >> new file mode 100644 index 0000000..913e63b --- /dev/null >> +++ >> b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh >> @@ -0,0 +1,31 @@ +#!/bin/sh >> +# >> +# Resize last partition to full medium size >> +# >> +# This software is a part of ISAR. >> +# Copyright (c) Siemens AG, 2018 >> +# >> +# SPDX-License-Identifier: MIT >> + >> +set -e >> + >> +ROOT_DEV=$(findmnt / -o source -n) >> +BOOT_DEV=$(echo ${ROOT_DEV} | sed 's/p\?[0-9]*$//') >> + >> +if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then >> + echo "Boot device equals root device - no partitioning >> found" >&2 >> + exit 1 >> +fi >> + >> +LAST_PART=$(sfdisk -d ${BOOT_DEV} 2>/dev/null | tail -1 | cut -d ' ' >> -f 1) + >> +# Remove all hints to the current medium (last-lba) and last >> partition size, +# then ask sfdisk to recreate the partitioning >> +sfdisk -d ${BOOT_DEV} 2>/dev/null | grep -v last-lba | \ >> + sed 's|\('${LAST_PART}' .*, \)size=[^,]*, |\1|' | \ >> + sfdisk --force ${BOOT_DEV} >> + >> +# Inform the kernel about the partitioning change >> +partx -u ${LAST_PART} >> + >> +resize2fs ${LAST_PART} >> diff --git >> a/meta/recipes-support/expand-on-first-boot/files/expand-on-first-boot.service >> b/meta/recipes-support/expand-on-first-boot/files/expand-on-first-boot.service >> new file mode 100644 index 0000000..cbe3857 --- /dev/null >> +++ >> b/meta/recipes-support/expand-on-first-boot/files/expand-on-first-boot.service >> @@ -0,0 +1,23 @@ +# This software is a part of ISAR. >> +# Copyright (c) Siemens AG, 2018 >> +# >> +# SPDX-License-Identifier: MIT >> + >> +[Unit] >> +Description=Expand last partition >> +DefaultDependencies=no >> +Conflicts=shutdown.target >> +After=systemd-remount-fs.service >> +Before=sysinit.target shutdown.target >> +ConditionPathIsReadWrite=/etc >> + >> +[Service] >> +Type=oneshot >> +RemainAfterExit=yes >> +ExecStart=/usr/share/expand-on-first-boot/expand-last-partition.sh >> +ExecStartPost=-/bin/systemctl disable expand-on-first-boot.service > > Ok, this seems to be how you try to make sure this is done only once at > the first boot. Is this a hack or somehow documented in systemd? I just > read something about "ConditionFirstBoot=" in systemd. ConditionFirstBoot was my first try as well, but it does not work here because - my guess, didn't analyze deeply - the debootstrap run or the rootfs installation step count as such, and the condition is false on FirstRealBoot. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux