Subject: Way to tell parted to resize partition to max size?

From: Petter Reinholdtsen <[email-masked]>
Date: Sat, 06 Aug 2016 08:58:07 +0200

Hi.

I checked the manual page, texinfo documentation and the source, but
were unable to find a way to do this.

Is there a way to tell parted to resize a partition to the maximum
possible.  In other words, to the end of the disk or until it meet a new
partition on the disk geometry?

With btrfs I can do like this to extend to the end of the partition:

  btrfs filesystem resize max /

Could parted be changed to allow something similar?  Perhaps

  resizepart 1 max

I had a look at the code, and suspect something like this might work,
but I do not know the parted inner workings enough to figure out where
to get the max_end value.

--- parted-3.2.orig/parted/parted.c
+++ parted-3.2/parted/parted.c
@@ -1522,6 +1522,7 @@ do_resizepart (PedDevice** dev, PedDisk*
         PedSector               start, end, oldend;
         PedGeometry             *range_end = NULL;
         PedConstraint*          constraint;
+        char                    *end_raw;
         int rc = 0;
 
         if (!disk) {
@@ -1543,8 +1544,12 @@ do_resizepart (PedDevice** dev, PedDisk*
 
         start = part->geom.start;
         end = oldend = part->geom.end;
-        if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, NULL))
-                goto error;
+        if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, &end_raw))
+                if (0 == strcmp('max', end_raw) {
+                        end = max_end;
+                } else {
+                        goto error;
+                }
         /* Do not move start of the partition */
         constraint = constraint_from_start_end_fixed_start (*dev, start, range_end);
         if (!ped_disk_set_partition_geom (disk, part, constraint,

-- 
Happy hacking
Petter Reinholdtsen