parted allows to fix broken GPT only interactively

Bug #1490608 reported by Oliver Grawert
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
parted (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

when physically resizing a disk (i.e. because it is a kvm image where you dd zeros to the end or because you dd'ed an image from a smaller disk to a bigger one) the GPT backup at the end of the device sits in the wrong sectors ...

while parted offers you a yes/no question in interactive mode to fix this, there is no way to make use of this feature when using "parted -s" (scripted mode). parted should get an option to fix the GPT even when using it non-interactively i.e. from a "grow rootfs at first boot to full disk size" script.

Revision history for this message
Michael Vogt (mvo) wrote :

What exactly is the message you get in interactive mode? this would help track down the relevant code.

Revision history for this message
Oliver Grawert (ogra) wrote :

it is in libparted/labels/gpt.c:

1033 q = ped_exception_throw
1034 (PED_EXCEPTION_WARNING,
1035 PED_EXCEPTION_FIX | PED_EXCEPTION_IGNORE,
1036 _("Not all of the space available to %s appears "
1037 "to be used, you can fix the GPT to use all of the "
1038 "space (an extra %llu blocks) or continue with the "
1039 "current setting? "), disk->dev->path,
1040 (uint64_t) (last_usable_if_grown - last_usable));

that gets me a "Fix/Ignore" prompt.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in parted (Ubuntu):
status: New → Confirmed
Revision history for this message
Phillip Susi (psusi) wrote :

I've been aware of this for a few years now since I first added the feature and sebner wanted to use it in the cloud-init-tools to do just that. The problem is that the exception handler only gets a text description, so you would need to do a loose string comparison to identify the particular exception you want to auto accept. You then need a way to specify this with a command line switch. I'm not liking the idea of parted --force-not_all_of_the_space_available....

Also the exact text is subject to change between releases, and changes depending on your locale, so it gets really tricky.

Changed in parted (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → Low
Revision history for this message
Oliver Grawert (ogra) wrote :

ugh, indeed i didnt mean to have the cmdline option hooked to the text handler but simply have it run whatever gets executed to fix the gpt without interaction or anything ...
we currently need to use an awfully hackish workaround to do the auto-resize on snappy images (store original table, create a brand new gpt and restore the old table) and i would like to somehow fix this before the next stable snappy release (in 4-8 weeks). i could indeed switch to gdisk but i'd really rather like to use parted as it is the traditionally used partitioning tool in ubuntu.

Revision history for this message
Oliver Grawert (ogra) wrote :

oh, and note that i know beforehand that there is a GPT and that i want to resize (and i even know the GPT backup wont sit at the end), i have all that info before attempting to run parted, so in my specific case i wouldn't need the exception handler at all.

Revision history for this message
Phillip Susi (psusi) wrote :

The fix code gets run based on the response the exception handler gives. The exception handler returns the default answer for all exceptions when in script mode, and the default for that one is not to fix it. Thus, to get it to say yes, fix it, you need the exception handler to recognize the specific exception and return the fix it response.

There is another way of accomplishing what you want though and that is to fake interactive mode. If you pass, I believe it was ---pretend-input-tty, you can run parted in interactive mode even though you have redirected it from a file. You can then script the commands to do the resize, and then answer fix it. Of course, this relies on knowing in advance the exact responses you will get from parted, and they must not deviate from that.

I suppose the other option is to change the default for that error to fix. I didn't do that originally because there are times when that might be the wrong thing to do and it could cause data loss, so didn't seem appropriate to do without user consent.

Revision history for this message
Oliver Grawert (ogra) wrote :

oh, thats awesome, i'll play with --pretend-input-tty, didnt know about that before ...
i think it already prints the error for the print command so i can run that first and separated from the actual actions (locales wont be an issue inside the initrd)

Revision history for this message
Phillip Susi (psusi) wrote :

Also I *think* that if you just don't use -s, you can put the "fix" command right on the command line following the print command and that will do it, but that behavior is really a bug in itself that I was planning on fixing at some point.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package parted - 3.5-1

---------------
parted (3.5-1) unstable; urgency=medium

  * Simplify some debhelper overrides slightly.
  * New upstream release:
    - Add --fix to --script mode to automatically fix problems like the
      backup GPT header not being at the end of a disk (LP: #1490608).

 -- Colin Watson <email address hidden> Tue, 19 Apr 2022 17:05:20 +0100

Changed in parted (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.