From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6836626675367673856 X-Received: by 2002:a1c:60d6:: with SMTP id u205mr12993286wmb.163.1592215838836; Mon, 15 Jun 2020 03:10:38 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1c:2885:: with SMTP id o127ls6405956wmo.0.canary-gmail; Mon, 15 Jun 2020 03:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy2/FlNS6BjzUj5o6xFId3wAMZ+mk7qLOUD+oPX//2YfEZpNaX4/wbLidZ/nQxos8nijS4 X-Received: by 2002:a7b:cbce:: with SMTP id n14mr12777154wmi.66.1592215838351; Mon, 15 Jun 2020 03:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592215838; cv=none; d=google.com; s=arc-20160816; b=nTnKzqmXtw3xhCRCUfl2wIYd1rwUqLhzzgfSAnci9sYDmdcJI1v7rq4G1olrDCOhu8 Kh3HINsl09s/85KxDULjxMEiqMNuXApiWK30o1IDuCtYfvtQnqge968DzcN2YHyYFfC9 huFhg1KewA5t241URRoUCRc28QrKNVoIvC8bt+zIMHHYgtWyKCwBR3YR4tcZyk40W2D4 5VwuUPX/FVLqI0glpUASRWsI8MnTb758Y69KhztCJVuEMCwjNn0n1djMA/X/MvUw0G8P qOXpGliiFSPI6ujP1KDo7s/MwDjDoTs509y1orc1VfiGn8YzTkDBU71TDojIETenk7Ci sZ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=z58UejjiOWHJg/Hk/6mykjs6AZobDOtQo660kDDlBxg=; b=D8//R+os4NtUDofUrM0MJd5rV8P31OOASMkBwRf3y/3otraMAQvgeNF8bnR6njtDzJ DIpRV7nhxZ/hZl0iXI0zuRf2svDV89c8QTMFVySE2Nohnk5yGXTq4alDrXyPiygygL5S IixiZxNfRseUgmFj/zAUkCXLCSSU+h+zPyUsxoHD3aipzqdG2re9QywZFUzbv6PL92Ou c5SXUz/pKbbZprvJ5ifHmBD3AFcJbMWEQGLPsU4JvGBoPAM1vJ+y83FQfBP2uPAuhTiM lAuCuOzpX2vBaXl1gTaO1T6pxQHqJrSdkxRagbll/qzyZKirM5H5f0bUTDS55vtmqyN5 Gdig== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of hws@denx.de) smtp.mailfrom=hws@denx.de Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10]) by gmr-mx.google.com with ESMTPS id m16si1448145wmg.2.2020.06.15.03.10.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jun 2020 03:10:38 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of hws@denx.de) client-ip=212.18.0.10; Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of hws@denx.de) smtp.mailfrom=hws@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 49lnCL0mMFz1rwDY; Mon, 15 Jun 2020 12:10:38 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 49lnCL0WTsz1sPN6; Mon, 15 Jun 2020 12:10:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id earwCWCoPN76; Mon, 15 Jun 2020 12:10:37 +0200 (CEST) X-Auth-Info: G6rwYLSIBeV0HWD3OHhn8dGee1O7o411nYbOpB1xEe8= Received: from maia.denx.de (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 15 Jun 2020 12:10:37 +0200 (CEST) From: Harald Seiler To: isar-users Cc: Harald Seiler , Jan Kiszka Subject: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions Date: Mon, 15 Jun 2020 12:10:25 +0200 Message-Id: <20200615101025.902895-1-hws@denx.de> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: J8ehojXWaJvt 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. .../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. +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 -- 2.25.4