From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6599936908158042112 X-Received: by 2002:a19:631c:: with SMTP id x28-v6mr261518lfb.3.1536844634512; Thu, 13 Sep 2018 06:17:14 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a19:d207:: with SMTP id j7-v6ls501534lfg.4.gmail; Thu, 13 Sep 2018 06:17:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZffgFVWpLUIgtTB57u+gwfzfRXwqT8zGHM0zTqO/nKgKhhJ8oAWmirtamU+FG7MVqBSCiT X-Received: by 2002:a19:c311:: with SMTP id t17-v6mr260875lff.27.1536844633871; Thu, 13 Sep 2018 06:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536844633; cv=none; d=google.com; s=arc-20160816; b=MIUlgI3nZTvDHuhJpu5rIQDmenHNFrm4Q+8ok1Ru4QNirzlRvE4+SokdfhGdSq/njD EAA4aWT4Y/TKb2bVKAkwKaef2G+6c1QPjw5bJiqjc50p5wAVEdk6/3ITGTEzFtt+rsxT ekDEuLvZsUzrdXQPKPQyu74ROijObn+GhZov3uIxF3oU3wCNkPRZY5vuOCwWxKQxlojH GJb2Eq/xNn5bu74aSNp1FZWM9SzVsWdpBCrlWh8jhUXj+KfEdh2XpRv3JC6kyI+biEIZ ySPfnu4rI3wsGM8LGAcckHg34LiBOdcGDlvxrAcXmsmTSNco5sFm6g40ON8UvX+64DRF qXfg== 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=ohEomrXgZfA+y28IvQPYKJC/pH0jb0XSanmmQwdOz30=; b=UwYdwpSnwRDp4zEShdEAZAIgrTJj8BRs6o8cPL3f3zgiEcL1ayplAEj0xvrNFSZu+2 NpfhYsPEdtIMYuTPq83yTK3xdA2EL1o4nu9+OFacHIi+1jSdLwgPoGeReIK7xs95cIh6 VcwZXRRh4XL8wi5cnF2mbgBCjZ3MyylTJuLEhCbda8QmTS8fRKX8stNAWM+NO/hxcFA+ aCkuEI8OOQF5tXNh8USp3PhQk75NgrER9SK7b8ztw/5/vEcyLd1bJ3/6m2KthVTiTAHk mrOuaMBr/snwwIISwqCJI8ZWxnrygXUEIXh7RK1kT928L0v9RtKAmzUhhfrCxcmWafR+ lpXQ== 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 v16-v6si95108ljg.3.2018.09.13.06.17.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Sep 2018 06:17:13 -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 w8DDHCkn000661 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 13 Sep 2018 15:17:12 +0200 Received: from [139.22.36.75] ([139.22.36.75]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id w8DDHBTo015558; Thu, 13 Sep 2018 15:17:12 +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> <140f8df3-b0b8-8fe8-7ef3-a15bf1331330@siemens.com> <20180913113023.2591edc7@md1pvb1c.ad001.siemens.net> From: Jan Kiszka Message-ID: <433e3271-23b5-c307-9140-1f94f5f9bf3b@siemens.com> Date: Thu, 13 Sep 2018 15:17:11 +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: <20180913113023.2591edc7@md1pvb1c.ad001.siemens.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: lIbGP1mAHvnn On 13.09.18 11:30, Henning Schild wrote: > Am Thu, 13 Sep 2018 10:33:59 +0200 > schrieb Jan Kiszka : > >> 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. > > I would suggest leaving a mark with "touch" from within the script and > using "ConditionPathExists=!", calling systemd from systemd sounds like > a bad idea. Unless that is the officialy documented way of doing such > things. I picked it up from the grub2-once service of my distro. Works without problems, so I don't see a need to fall back to that inferior PathExists method. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux