From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6599936908158042112 X-Received: by 2002:a1c:c90f:: with SMTP id f15-v6mr154494wmb.0.1536667559369; Tue, 11 Sep 2018 05:05:59 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:730c:: with SMTP id d12-v6ls657548wmb.0.canary-gmail; Tue, 11 Sep 2018 05:05:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaDDM/5+kIcVSloft93txEw3ONGA22fgLGTr9fP4NQGruh20pTFXfqoEQiwaBGTWNfO4BQD X-Received: by 2002:a1c:9e94:: with SMTP id h142-v6mr134574wme.13.1536667558989; Tue, 11 Sep 2018 05:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536667558; cv=none; d=google.com; s=arc-20160816; b=iJiT+zH8vSJja10bIdl16AGzzXm6IsegJw4cNnudkAkK4gs3YV3FSaC4+uV1j0Yn9p 3MVCnNXTekCpo0koWEA2u+b5V/2Gt1YMCwt7ZDnfVTfyC3FXxnwIdRG9FuBY0dmTVFiF iQj3MuTJNoTta0KLdjMbsTH5E5gcX5h4hZXjk2pbKBDmjthImvCv10gnppUoZfrMxFBx u69EN7VgsKa8Vb/54NHF/34ZsK5x/tIryhQiv24BQeH4pn/QPLpfAQ7ut3NLR7C6xh9z yaVM2Q2bU+CbE89F7B2FD3cg+5XLMZz0yYFA+ZiE3geSOR3/6ZqGmVhPKj9B/M2yra/C Vp9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:to:from; bh=IHJUsLYJgJ7LgJd4rVs7zRS16edW8OtkbnrxOmzCPsA=; b=rKv/uKQQ4WTygAqARE6Ey0V/dXlP8lDNjM7jSYx3ZK0CEI1CZoEstXoulM9XOVQVqn IiOYxDuYpIn4h+/6NNmh0TIm7busdhdMS2FfsHC9saTO+Il0k/AUooNO+yyYJJmbqexo DdwCmDbMOnDNiPdwlj8/sp6Y925jSkKuh+uHBbWYXV+Pbt087kyQ5ZKh0B3GfwyoXt3u LxHPeeocz5yFkB/jRs+z0m+FYfS3kar8DUnbKM2cxPs8uYoCYarTaFE4/Gd5SKYlwor3 YnYEypOUu3M9okHdexPXsvAk9uqKAHyEMUVYwUxJl0uf+0wdW3ETHVgI+7Y1XNCIC3ux 655Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id l15-v6si508089wre.2.2018.09.11.05.05.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 05:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id w8BC5w7a018019 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Sep 2018 14:05:58 +0200 Received: from md1f2u6c.ad001.siemens.net (md1q0hnc.ad001.siemens.net [139.25.68.37] (may be forged)) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id w8BC5vIW000884 for ; Tue, 11 Sep 2018 14:05:58 +0200 From: Jan Kiszka To: isar-users Subject: [PATCH 12/16] meta: Add expand-on-first-boot support package Date: Tue, 11 Sep 2018 14:05:52 +0200 Message-Id: X-Mailer: git-send-email 2.16.4 In-Reply-To: References: In-Reply-To: References: X-TUID: 1jZsDKs507XQ 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 +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=sysinit.target diff --git a/meta/recipes-support/expand-on-first-boot/files/postinst b/meta/recipes-support/expand-on-first-boot/files/postinst new file mode 100644 index 0000000..a190b01 --- /dev/null +++ b/meta/recipes-support/expand-on-first-boot/files/postinst @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl enable expand-on-first-boot.service -- 2.16.4