From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6836626675367673856 X-Received: by 2002:a05:6402:3044:: with SMTP id bu4mr23170318edb.69.1592216881122; Mon, 15 Jun 2020 03:28:01 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:aa7:d04d:: with SMTP id n13ls12784793edo.2.gmail; Mon, 15 Jun 2020 03:28:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeEsLGaOeqNuUD++oLRNAB3s+QgWf2NM0dqtW8nWQjQlz4ymqz47OHPLy6Ow5FEarQqhJG X-Received: by 2002:aa7:d698:: with SMTP id d24mr23503391edr.56.1592216880432; Mon, 15 Jun 2020 03:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592216880; cv=none; d=google.com; s=arc-20160816; b=ylvNVF3CQGexGU7wUZaM0qfUaTNU2buabeQxSC+PldkXoTgNqwq8RER8c1iBxz9ZcO JmjMDnFMdImqVxaHUsURAKdzERI+n0zR8Qe1/wPPdfX09lANX85mSa66VNxM61xoA+gm 8vBOsQh+f7MO9bqULpNWcdWhlr1UKvWvs6meD7hmyEfym++YX/JkF5HohqvqFuESsi0b jPQH90IgRsFEsWiJXwItvR0wQ6qJu/k4bplcdx9OwP0RHBVyjWT7FN5/PQIiQjj80+mC heuI4bQwvKB/xmNoLUqLSvvAiXgoqjeZwzhCoNUxYLuVboV/cWL7nvgVa2tjqjJxfZFJ 2BaA== 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:to:subject; bh=ppW9pyFTSsPtL8HzkfmL8pzq/Y7cENLf2tONjaLEtXY=; b=oTpMDmV2f4Y58fUuGcHbPZRjboNbbsOOunQmuQw/mg2C+6H3apfBpTGFTZUccLzH45 q40+4mZrmaZz7eQUlgr39eqwtOnkvi0BWNCESd4NZZkMCwAL3n7X/IaKd9bPqO4E6JgL ImzHhOFdXoKF5yag90eLGxu9WHpqFLMK104O/7cZ/urOiWjSxNwN3SJq5FVyMKCdcE+U 2XerSJI9IarpumU06H3xtxSniowTlxTyyyD3k3fZdQOCQ1mXel4IXWMd+fBQ/2jiQThN roHbWLqif1bBDFTRRSrdfroxiBIv5sVP8E30KUDf3M7m+0hAMBQowSBbxsmAf5XJsct7 J9kQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id l10si785175edf.4.2020.06.15.03.28.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 03:28:00 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id 05FARxOU002502 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Jun 2020 12:27:59 +0200 Received: from [167.87.53.252] ([167.87.53.252]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id 05FARxx4012925; Mon, 15 Jun 2020 12:27:59 +0200 Subject: Re: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions To: Harald Seiler , isar-users References: <20200615101025.902895-1-hws@denx.de> From: Jan Kiszka Message-ID: Date: Mon, 15 Jun 2020 12:27:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200615101025.902895-1-hws@denx.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: Tb7Jd+7PXic8 On 15.06.20 12:10, Harald Seiler wrote: > Extended partitions cannot be resized like primary partitions because > both the last logical partition and the EBR primary partition containing > it need to be expanded. > > To do this, add a second SED directive for removing the parition size of > the EBR partition. This part is detected by having either type `f` (Win > 95 Ext') or `5` (Extended). > > Signed-off-by: Harald Seiler > --- > > Notes: > Changes in v2: > - Keep a type `f` EBR as type `f`. > - Update comment to better explain what is done. > > I've built myself a little test-suite to see how this script > behaves when given different layouts. It seems to work just fine > now for the following cases: > > - Expanding last partition of a GPT. > - Expanding last partition of an MBR without extended partitions. > - Expanding last (logical) partition of an MBR when the last > primary partition is the EBR. > > Having the EBR somewhere in the middle is *not* supported. The > script will fail with an error message, without accidentally > ruining the layout. I think such a case is too rare to be worth > supporting. Ack. > > .../files/expand-last-partition.sh | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > 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 08c69db30529..7175dfd38b7e 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 > @@ -17,12 +17,20 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then > exit 1 > fi > > -LAST_PART="$(sfdisk -d ${BOOT_DEV} 2>/dev/null | tail -1 | cut -d ' ' -f 1)" > +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|' | \ > +# Transform the partition table as follows: > +# > +# - Remove any 'last-lba' header so sfdisk uses the entire available space. > +# - If this partition table is MBR and an extended partition container (EBR) > +# exists, we assume this needs to be expanded as well; remove its size > +# field so sfdisk expands it. > +# - For the previously fetched last partition, also remove the size field so > +# sfdisk expands it. Very nice. > +sfdisk -d "${BOOT_DEV}" 2>/dev/null | \ > + grep -v last-lba | \ > + sed 's|^\(.*, \)size=[^,]*, \(type=[f5]\)$|\1\2|' | \ > + sed 's|^\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \ > sfdisk --force "${BOOT_DEV}" > > # Inform the kernel about the partitioning change > LGTM. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux