[parted-devel] [PATCH 2/2] tests: Add test for partition table not at LBA 2
Brian C. Lane
bcl at redhat.com
Tue Nov 4 18:55:55 GMT 2025
Use sgdisk to create a disk image with the partition table relocated to
sector 16, and shrunk to 40 entries. Then test that parted in script
mode aborts making changes and outputs the error message.
---
tests/Makefile.am | 1 +
tests/t-lib-helpers.sh | 6 ++++++
tests/t0284-gpt-moved-pth.sh | 38 ++++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
create mode 100644 tests/t0284-gpt-moved-pth.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5eeab08..a37eb0e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,6 +31,7 @@ TESTS = \
t0281-gpt-grow.sh \
t0282-gpt-move-backup.sh \
t0283-overlap-partitions.sh \
+ t0284-gpt-moved-pth.sh \
t0290-gpt-name.sh \
t0300-dos-on-gpt.sh \
t0301-overwrite-gpt-pmbr.sh \
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index a1d3c30..06a1e4f 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -29,6 +29,12 @@ require_fat_()
|| skip_ "mkfs.vfat: command not found"
}
+require_sgdisk_()
+{
+ sgdisk -? 2>&1 | grep '^Usage:' \
+ || skip_ "sgdisk: command not found"
+}
+
# Skip this test if we're not in SELinux "enforcing" mode.
require_selinux_enforcing_()
{
diff --git a/tests/t0284-gpt-moved-pth.sh b/tests/t0284-gpt-moved-pth.sh
new file mode 100644
index 0000000..258a6ce
--- /dev/null
+++ b/tests/t0284-gpt-moved-pth.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Test parted behavior when partition table is not at LBA 2
+
+# Copyright (C) 2025 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 <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+
+require_512_byte_sector_size_
+require_sgdisk_
+
+dev=loop-file
+ss=$sector_size_
+n_sectors=5000
+
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
+
+# Use sgdisk to create a GPT disklabel with the partition table at sector 16
+# and limited to 40 entries.
+sgdisk --move-main-table=16 --resize-table=40 "$dev" || fail=1
+
+# Trying to create a partition should exit with a message and rc=1
+parted -s "$dev" mkpart root ext4 2048s 4900s > out 2>&1; test $? = 1 || fail=1
+grep "^Error: The Partition Entry Table is not at LBA 2" out || fail=1
+
+exit $fail
--
2.51.1
More information about the parted-devel
mailing list