From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6836626675367673856 X-Received: by 2002:a2e:9a0e:: with SMTP id o14mr8464442lji.340.1602584342729; Tue, 13 Oct 2020 03:19:02 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a2e:b5b7:: with SMTP id f23ls235820ljn.2.gmail; Tue, 13 Oct 2020 03:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk15yVaY1YwTBCm7omfOQvO2FxGOx7WVIxdGCtEKRItj+T+vLsvIGKV5UrT5WEvyiStKy1 X-Received: by 2002:a05:651c:1a3:: with SMTP id c3mr3455940ljn.366.1602584341489; Tue, 13 Oct 2020 03:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602584341; cv=none; d=google.com; s=arc-20160816; b=JG2DyoeyqD2S4biyo/f0v7adcOptN9qIqFGy7mNlWq4ITfyCFag5jIffLSVATv6RT3 6VgycGFQ+YsEOszmDqL0OYlj5UVs/Tu/35Iw9NzxHgzfpuV0b+XNH5u/00/EJuop0pry 9uWlbvCI8U//a38LUJqDjgvHsNiW777J2MAam0XCEeQaU4/1RgWTPgXqbcQC+Jdngp12 0zUM75BhdmGFDKdyNWQliPMZ8Gj7aDxwUfwjQaUXJ7WncZj30RCJ1reD9oNRRDMJ1DSq 6GWXE19joh3uNxulhgXjeTFES5zmnAFJwdgyY4beZ/rG4FR9G6Ze6bvcABnK2+hbdhLp JRDA== 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:cc:references:to:from:subject; bh=T3lylwvenDXCb+iE+6Sa2RAuQaHdwDXKR4cF/K4Wjlk=; b=kDQQ76qVXZkftq4Ucjne830ndFNuDxoJxTGwbcNWJL2DFMhHDJVz7ldlt/eL05+71f CJVX2KJMS84GOOON/Whn8n7keuBZwYLmv07w85lQ6frz071CZ+WCTgJOtYyZ3rSe0EcN 3pjmY70j4VtGRIYRr/vynNQERK215gHCnxKq+jGa+Sl5ihShKsN5xQ4qEcI6SzxnKYut CrXTRZTocAuQ9y/UmLKgb9DiTKFQt7ApE/zbQSTWnOOgj63qg/3EJFv0Ddd4k2T41rXc pwRTsqVIyZU9eHDUmQ6L/70AQc/wAQTMQmz6siJDg9g1mENf6JXkvc+eNdMhM+oIYB+f URiA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 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 goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id i16si213699ljj.3.2020.10.13.03.19.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2020 03:19:01 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 192.35.17.28 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 goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id 09DAJ077001958 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Oct 2020 12:19:00 +0200 Received: from [139.25.68.37] ([139.25.68.37]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id 09DAIxkN018073; Tue, 13 Oct 2020 12:18:59 +0200 Subject: Re: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions From: Jan Kiszka To: Baurzhan Ismagulov References: <20200615101025.902895-1-hws@denx.de> Cc: Harald Seiler , isar-users Message-ID: Date: Tue, 13 Oct 2020 12:18:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: FL8KT3eATDx+ On 15.06.20 12:27, [ext] Jan Kiszka wrote: > 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 > Baurzhan, this is overdue. Jan -- Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux