diff --git a/0001-parted-add-fix-to-fix-in-script-mode.patch b/0001-parted-add-fix-to-fix-in-script-mode.patch new file mode 100644 index 0000000..be907eb --- /dev/null +++ b/0001-parted-add-fix-to-fix-in-script-mode.patch @@ -0,0 +1,123 @@ +From 7c9a96209af2b84e1eec98ad3527f82ddd966cdf Mon Sep 17 00:00:00 2001 +From: Cristian Klein +Date: Fri, 11 Dec 2020 22:19:22 +0100 +Subject: [PATCH 1/5] parted: add --fix to "fix" in script mode + +Use-case: VMs are booted from images that are smaller than their virtual +disk. This means that -- almost by definition -- the secondary GPT +header will be "misplaced", i.e., not at the end of the virtual disk. + +Without this patch, parted cannot be used for custom/exotic partitioning +when the VM boots (e.g., in cloud-init's `bootcmd`). Specifically, it +will fail as follows: + +``` +$ sudo parted --script /dev/vda "mkpart 2 10GB -1" +Warning: Not all of the space available to /dev/vda appears to be used, +you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? +Error: Unable to satisfy all constraints on the partition. +``` + +This happens because, in script mode, exceptions are usually not +resolved. + +This patch adds `--fix`. This allows exceptions to be automatically +resolved with Fix. As a result, the following command will work: + +``` +$ sudo parted --fix --script /dev/vda "mkpart 2 10GB -1" +``` + +Signed-off-by: Brian C. Lane +--- + parted/parted.c | 8 ++++++-- + parted/ui.c | 7 +++++++ + parted/ui.h | 1 + + 3 files changed, 14 insertions(+), 2 deletions(-) + +diff --git a/parted/parted.c b/parted/parted.c +index e84e66d..41edb7f 100644 +--- a/parted/parted.c ++++ b/parted/parted.c +@@ -116,6 +116,7 @@ static struct option const options[] = { + {"list", 0, NULL, 'l'}, + {"machine", 0, NULL, 'm'}, + {"script", 0, NULL, 's'}, ++ {"fix", 0, NULL, 'f'}, + {"version", 0, NULL, 'v'}, + {"align", required_argument, NULL, 'a'}, + {"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY}, +@@ -127,12 +128,14 @@ static const char *const options_help [][2] = { + {"list", N_("lists partition layout on all block devices")}, + {"machine", N_("displays machine parseable output")}, + {"script", N_("never prompts for user intervention")}, ++ {"fix", N_("in script mode, fix instead of abort when asked")}, + {"version", N_("displays the version")}, + {"align=[none|cyl|min|opt]", N_("alignment for new partitions")}, + {NULL, NULL} + }; + + int opt_script_mode = 0; ++int opt_fix_mode = 0; + int pretend_input_tty = 0; + int opt_machine_mode = 0; + int disk_is_modified = 0; +@@ -2191,7 +2194,7 @@ int opt, help = 0, list = 0, version = 0, wrong = 0; + + while (1) + { +- opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsva:", ++ opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsfva:", + options, NULL); + if (opt == -1) + break; +@@ -2201,6 +2204,7 @@ while (1) + case 'l': list = 1; break; + case 'm': opt_machine_mode = 1; break; + case 's': opt_script_mode = 1; break; ++ case 'f': opt_fix_mode = 1; break; + case 'v': version = 1; break; + case 'a': + alignment = XARGMATCH ("--align", optarg, +@@ -2217,7 +2221,7 @@ while (1) + + if (wrong == 1) { + fprintf (stderr, +- _("Usage: %s [-hlmsv] [-a] [DEVICE [COMMAND [PARAMETERS]]...]\n"), ++ _("Usage: %s [-hlmsfv] [-a] [DEVICE [COMMAND [PARAMETERS]]...]\n"), + program_name); + return 0; + } +diff --git a/parted/ui.c b/parted/ui.c +index 973bd26..b5948d3 100644 +--- a/parted/ui.c ++++ b/parted/ui.c +@@ -644,6 +644,13 @@ exception_handler (PedException* ex) + if (!option_get_next (ex->options, opt)) + return opt; + ++ /* script-mode and fix? */ ++ int fix_is_an_option = (ex->options & PED_EXCEPTION_FIX); ++ if (opt_script_mode && opt_fix_mode && fix_is_an_option) { ++ printf ("Fixing, due to --fix\n"); ++ return PED_EXCEPTION_FIX; ++ } ++ + /* script-mode: don't handle the exception */ + if (opt_script_mode || (!isatty (0) && !pretend_input_tty)) + return PED_EXCEPTION_UNHANDLED; +diff --git a/parted/ui.h b/parted/ui.h +index 3b07782..e4e88b6 100644 +--- a/parted/ui.h ++++ b/parted/ui.h +@@ -89,6 +89,7 @@ extern void print_using_dev (PedDevice* dev); + + /* in parted.c */ + extern int opt_script_mode; ++extern int opt_fix_mode; + extern int pretend_input_tty; + + extern void print_options_help (); +-- +2.26.2 + diff --git a/0002-doc-Document-fix-flag.patch b/0002-doc-Document-fix-flag.patch new file mode 100644 index 0000000..0961dda --- /dev/null +++ b/0002-doc-Document-fix-flag.patch @@ -0,0 +1,47 @@ +From 8aa569aa60c37526a8c37b06e88a833745a7a6ef Mon Sep 17 00:00:00 2001 +From: Cristian Klein +Date: Fri, 11 Dec 2020 22:19:23 +0100 +Subject: [PATCH 2/5] doc: Document --fix flag + +Also fix copyright year, to please `make syntax-check`. + +Signed-off-by: Brian C. Lane +--- + doc/C/parted.8 | 3 +++ + doc/parted.texi | 6 ++++++ + 2 files changed, 9 insertions(+) + +diff --git a/doc/C/parted.8 b/doc/C/parted.8 +index 297c39a..d8e556e 100644 +--- a/doc/C/parted.8 ++++ b/doc/C/parted.8 +@@ -27,6 +27,9 @@ displays machine parseable output + .B -s, --script + never prompts for user intervention + .TP ++.B -f, --fix ++automatically answer "fix" to exceptions in script mode ++.TP + .B -v, --version + displays the version + .TP +diff --git a/doc/parted.texi b/doc/parted.texi +index d89d74d..33212f0 100644 +--- a/doc/parted.texi ++++ b/doc/parted.texi +@@ -406,6 +406,12 @@ display a help message + @itemx --script + never prompt the user + ++@item -f ++@itemx --fix ++automatically answer exceptions with "fix" in script mode, whcih is useful for: ++GPT header not including full disk size; moving the backup GPT table to the end of the disk; ++MAC fix missing partition map entry; etc. ++ + @item -a alignment-type + @itemx --align alignment-type + Set alignment for newly created partitions, valid alignment types are: +-- +2.26.2 + diff --git a/0003-tests-Add-tests-for-fix.patch b/0003-tests-Add-tests-for-fix.patch new file mode 100644 index 0000000..4fe4ef9 --- /dev/null +++ b/0003-tests-Add-tests-for-fix.patch @@ -0,0 +1,135 @@ +From 6b2c8806b42a7214d726cc2b3dac6b96013a6cce Mon Sep 17 00:00:00 2001 +From: Cristian Klein +Date: Fri, 11 Dec 2020 22:19:24 +0100 +Subject: [PATCH 3/5] tests: Add tests for --fix + +Signed-off-by: Brian C. Lane +--- + tests/Makefile.am | 3 +- + tests/t9060-gpt-grow-script-fix.sh | 100 +++++++++++++++++++++++++++++ + 2 files changed, 102 insertions(+), 1 deletion(-) + create mode 100755 tests/t9060-gpt-grow-script-fix.sh + +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 0d7c022..3473e6b 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -89,7 +89,8 @@ TESTS = \ + t9040-many-partitions.sh \ + t9041-undetected-in-use-16th-partition.sh \ + t9042-dos-partition-limit.sh \ +- t9050-partition-table-types.sh ++ t9050-partition-table-types.sh \ ++ t9060-gpt-grow-script-fix.sh + + EXTRA_DIST = \ + $(TESTS) t-local.sh t-lvm.sh \ +diff --git a/tests/t9060-gpt-grow-script-fix.sh b/tests/t9060-gpt-grow-script-fix.sh +new file mode 100755 +index 0000000..4a3a8a9 +--- /dev/null ++++ b/tests/t9060-gpt-grow-script-fix.sh +@@ -0,0 +1,100 @@ ++#!/bin/sh ++# grow a gpt disk, ensure that parted offers to update the gpt size ++# do this in script mode with fix ++ ++# Copyright (C) 2009-2012, 2014, 2019 Free Software Foundation, Inc. ++ ++# This program is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3 of the License, or ++# (at your option) any later version. ++ ++# This program is distributed in the hope that it will be useful, ++# but WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++ ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../parted ++require_512_byte_sector_size_ ++dev=loop-file ++ ++ss=$sector_size_ ++n_sectors=5000 ++ ++dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1 ++ ++# create gpt label ++parted -s $dev mklabel gpt > empty 2>&1 || fail=1 ++compare /dev/null empty || fail=1 ++ ++# print the empty table ++parted -m -s $dev unit s print > t 2>&1 || fail=1 ++sed "s,.*/$dev:,$dev:," t > out || fail=1 ++ ++# check for expected output ++printf "BYT;\n$dev:${n_sectors}s:file:$sector_size_:$sector_size_:gpt::;\n" \ ++ > exp || fail=1 ++compare exp out || fail=1 ++ ++# grow disk ++n_sectors=5500 ++dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1 ++ ++# printing must warn, but not fix in script mode ++parted -s $dev print > out 2>&1 || fail=1 ++ ++# Transform the actual output, to avoid spurious differences when ++# $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity. ++# normalize the actual output ++mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s, * ,,g;s, $,," \ ++ -e "s,^.*/lt-parted: ,parted: ," o2 > out ++ ++# check for expected diagnostic ++cat < exp || fail=1 ++Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? ++Model: (file) ++Disk DEVICE: 2816kB ++Sector size (logical/physical): 512B/512B ++Partition Table: gpt ++Disk Flags: ++ ++Number Start End Size File system Name Flags ++ ++EOF ++compare exp out || fail=1 ++ ++# now we fix ++parted --script --fix $dev print > out 2>&1 || fail=1 ++ ++# Transform the actual output, to avoid spurious differences when ++# $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity. ++# normalize the actual output ++mv out o2 && sed -e "s,/.*/$dev,DEVICE,;s, * ,,g;s, $,," \ ++ -e "s,^.*/lt-parted: ,parted: ," o2 > out ++ ++# check for expected diagnostic ++cat < exp || fail=1 ++Warning: Not all of the space available to DEVICE appears to be used, you can fix the GPT to use all of the space (an extra 500 blocks) or continue with the current setting? ++Fixing, due to --fix ++Model: (file) ++Disk DEVICE: 2816kB ++Sector size (logical/physical): 512B/512B ++Partition Table: gpt ++Disk Flags: ++ ++Number Start End Size File system Name Flags ++ ++EOF ++compare exp out || fail=1 ++ ++ ++# Now should not warn ++ ++parted -s $dev print > err 2>&1 || fail=1 ++grep Warning: err > k ; mv k err ++compare /dev/null err || fail=1 ++ ++Exit $fail +-- +2.26.2 + diff --git a/0004-tests-Fix-test-t1700-probe-fs.patch b/0004-tests-Fix-test-t1700-probe-fs.patch new file mode 100644 index 0000000..d96b771 --- /dev/null +++ b/0004-tests-Fix-test-t1700-probe-fs.patch @@ -0,0 +1,35 @@ +From 9bb4afe61426419c8bb83a25aa9822e00611c8f3 Mon Sep 17 00:00:00 2001 +From: Cristian Klein +Date: Fri, 11 Dec 2020 22:19:25 +0100 +Subject: [PATCH 4/5] tests: Fix test t1700-probe-fs + +mkfs.ext3 (see version below) was complaining that the filesystem is too small +for a journal, which made the test fail. + +``` +$ mkfs.ext3 -V +mke2fs 1.45.5 (07-Jan-2020) + Using EXT2FS Library version 1.45.5 +``` + +Signed-off-by: Brian C. Lane +--- + tests/t1700-probe-fs.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tests/t1700-probe-fs.sh b/tests/t1700-probe-fs.sh +index 848d3e3..5c08e97 100755 +--- a/tests/t1700-probe-fs.sh ++++ b/tests/t1700-probe-fs.sh +@@ -57,7 +57,7 @@ done + # Some features should indicate ext4 by themselves. + for feature in uninit_bg flex_bg; do + # create an ext3 file system +- dd if=/dev/null of=$dev bs=1024 seek=4096 >/dev/null || skip_ "dd failed" ++ dd if=/dev/null of=$dev bs=1024 seek=8192 >/dev/null || skip_ "dd failed" + mkfs.ext3 -F $dev >/dev/null || skip_ "mkfs.ext3 failed" + + # set the feature +-- +2.26.2 + diff --git a/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch b/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch new file mode 100644 index 0000000..a998543 --- /dev/null +++ b/0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch @@ -0,0 +1,33 @@ +From 6ed9c9e82ea6cfbee93a47e82e92a90abdb82343 Mon Sep 17 00:00:00 2001 +From: Cristian Klein +Date: Fri, 11 Dec 2020 22:19:26 +0100 +Subject: [PATCH 5/5] tests: Fix t9041-undetected-in-use-16th-partition + +Sometimes fails with: +``` ++ mkfs.ext3 /dev/sda15 +mke2fs 1.45.5 (07-Jan-2020) +/dev/sda15: Not enough space to build proposed filesystem while setting up superblock +``` + +Signed-off-by: Brian C. Lane +--- + tests/t9041-undetected-in-use-16th-partition.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh +index a4a3020..129bf15 100644 +--- a/tests/t9041-undetected-in-use-16th-partition.sh ++++ b/tests/t9041-undetected-in-use-16th-partition.sh +@@ -25,7 +25,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null || + skip_ 'this system lacks a new-enough libblkid' + + ss=$sector_size_ +-partition_sectors=256 # sectors per partition ++partition_sectors=512 # sectors per partition + n_partitions=17 # how many partitions to create + start=2048 # start sector for the first partition + gpt_slop=34 # sectors at end of disk reserved for GPT +-- +2.26.2 + diff --git a/parted.spec b/parted.spec index f980b0e..8d352fe 100644 --- a/parted.spec +++ b/parted.spec @@ -4,7 +4,7 @@ Summary: The GNU disk partition manipulation program Name: parted Version: 3.4 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv3+ URL: http://www.gnu.org/software/parted @@ -13,6 +13,13 @@ Source1: https://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz.sig Source2: pubkey.phillip.susi Source3: pubkey.brian.lane +# Upstream patches since v3.4 release +Patch0001: 0001-parted-add-fix-to-fix-in-script-mode.patch +Patch0002: 0002-doc-Document-fix-flag.patch +Patch0003: 0003-tests-Add-tests-for-fix.patch +Patch0004: 0004-tests-Fix-test-t1700-probe-fs.patch +Patch0005: 0005-tests-Fix-t9041-undetected-in-use-16th-partition.patch + BuildRequires: gcc BuildRequires: e2fsprogs-devel BuildRequires: readline-devel @@ -115,6 +122,9 @@ make check %changelog +* Wed Feb 03 2021 Brian C. Lane - 3.4-2 +- Add --fix support from upstream + * Wed Jan 27 2021 Brian C. Lane - 3.4-1 - New stable upstream release v3.4