GNU bug report logs - #71790
parted -s emits a warning when shrinking a partition

Previous Next

Package: parted;

Reported by: Sean Warner <plica2006 <at> gmail.com>

Date: Thu, 27 Jun 2024 04:30:03 UTC

Severity: normal

To reply to this bug, email your comments to 71790 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-parted <at> gnu.org:
bug#71790; Package parted. (Thu, 27 Jun 2024 04:30:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sean Warner <plica2006 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-parted <at> gnu.org. (Thu, 27 Jun 2024 04:30:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sean Warner <plica2006 <at> gmail.com>
To: bug-parted <at> gnu.org
Subject: parted -s emits a warning when shrinking a partition
Date: Wed, 26 Jun 2024 23:51:38 +0100
[Message part 1 (text/plain, inline)]
I am also having this bug reported in 2017:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=879555

$ parted -v
parted (GNU parted) 3.6
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+
Written by
<http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.

$ cat /etc/lsb-release 
DISTRIB_ID="ManjaroLinux"
DISTRIB_RELEASE="24.0.2"
DISTRIB_CODENAME="Wynsdey"

-- If increasing the size of a partition the following command works
but if shrinking a partition it gives a warning "Warning: Shrinking a
partition can cause data loss, are you sure you want to continue?" and
the command just exits back to the command prompt and no changes are
made to the partition.

sudo parted -s /dev/loop0 resizepart 1 46280703s

I assumed that parted -s would automatically supply a default value of
'Yes' in this instance?

According to the Parted Man page:
-s, --script
never prompts for user intervention

Is this a bug or am I misunderstanding something?

From researching the interweb this might be a bug that for many years
has never been addressed.

Previous parted versions apparently allowed for something like:

sudo parted -s /dev/loop0 resizepart 1 yes 46280703s
or
sudo parted -s /dev/loop0 resizepart 1 46280703s yes

But in parted 3.6 there appears to be no way to make this work with
parted -s. The only option is to resort to the undocumented ---pretend-
input-tty <-- But is this safe to keep using if not documented? Any
plans to make ---pretend-input-tty an official "thing" in Parted?

Example that will work whether increasing or reducing the partition
size:

echo -e "resizepart 1 46280703s\nyes\nunit s\nprint\nquit" | sudo
parted /dev/loop0 ---pretend-input-tty

Any help much appreciated,

Flex
[Message part 2 (text/html, inline)]

Information forwarded to bug-parted <at> gnu.org:
bug#71790; Package parted. (Thu, 27 Jun 2024 15:30:02 GMT) Full text and rfc822 format available.

Message #8 received at 71790 <at> debbugs.gnu.org (full text, mbox):

From: "Brian C. Lane" <bcl <at> redhat.com>
To: Sean Warner <plica2006 <at> gmail.com>
Cc: 71790 <at> debbugs.gnu.org
Subject: Re: bug#71790: parted -s emits a warning when shrinking a partition
Date: Thu, 27 Jun 2024 08:28:55 -0700
On Wed, Jun 26, 2024 at 11:51:38PM +0100, Sean Warner wrote:
> I am also having this bug reported in 2017:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=879555
> 
> $ parted -v
> parted (GNU parted) 3.6
> Copyright (C) 2023 Free Software Foundation, Inc.
> License GPLv3+
> Written by
> <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.
> 
> $ cat /etc/lsb-release 
> DISTRIB_ID="ManjaroLinux"
> DISTRIB_RELEASE="24.0.2"
> DISTRIB_CODENAME="Wynsdey"
> 
> -- If increasing the size of a partition the following command works
> but if shrinking a partition it gives a warning "Warning: Shrinking a
> partition can cause data loss, are you sure you want to continue?" and
> the command just exits back to the command prompt and no changes are
> made to the partition.
> 
> sudo parted -s /dev/loop0 resizepart 1 46280703s
> 
> I assumed that parted -s would automatically supply a default value of
> 'Yes' in this instance?

No, in script mode parted defaults to the safe option. Automatically
saying yes will lead to data loss so it defaults to know. I admit the
message is misleading, this is because of how parted handles warnings
like this and it could use some improvement.

I don't really have any suggestion for working around this other than
doing it in interactive mode.

> input-tty <-- But is this safe to keep using if not documented? Any
> plans to make ---pretend-input-tty an official "thing" in Parted?

No, it's there for the tests. But there's no plan to remove it since the
tests depend on it. But I really don't recommend automating things that
could lose data.

Brian

-- 
Brian C. Lane (PST8PDT) - weldr.io - lorax - parted - pykickstart





Information forwarded to bug-parted <at> gnu.org:
bug#71790; Package parted. (Thu, 27 Jun 2024 21:56:02 GMT) Full text and rfc822 format available.

Message #11 received at 71790 <at> debbugs.gnu.org (full text, mbox):

From: Sean Warner <plica2006 <at> gmail.com>
To: 71790 <at> debbugs.gnu.org
Subject: Re: bug#71790: parted -s emits a warning when shrinking a partition
Date: Thu, 27 Jun 2024 22:54:08 +0100
[Message part 1 (text/plain, inline)]
Hello Brian,

Thank you for your helpful reply.

There are many threads on various sites where people, like me, have
incorrectly assumed that parted -s will let you do whatever you want
and are left confused. It makes sense to apply the philosophy of do-no-
harm with the parted --script option but perhaps the man page needs to
clarify the intended behavior.

Currently it simply says: "-s --script never prompts for user
intervention" instead maybe something like: "Will default safe answers
to user prompts such as 'No' when parted checks if it is OK to shrink a
partition." OK that sounds wordy but I think better to have verbose man
pages that don't leave any doubt as to what the intended functionality
is.

This bug
report https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27204 (Norman
Shulman) proposes a patch to really make parted -s "never prompt for
user intervention" even if shrinking a partition. I tried it out and it
works, at least I have the option now!

--- a/parted/parted.c	2014-06-15 15:16:33.000000000 -0400
+++ b/parted/parted.c	2017-05-24 17:27:02.093371079 -0400
@@ -1551,7 +1551,7 @@ do_resizepart (PedDevice** dev, PedDisk*
                                           start, end))
                 goto error_destroy_constraint;
         /* warn when shrinking partition - might lose data */
-        if (part->geom.end < oldend)
+        if (part->geom.end < oldend && !opt_script_mode)
                 if (ped_exception_throw (
                             PED_EXCEPTION_WARNING,
                             PED_EXCEPTION_YES_NO,

Cheers,

Sean 

-----Original Message-----
From: Brian C. Lane <bcl <at> redhat.com>
To: Sean Warner <plica2006 <at> gmail.com>
Cc: 71790 <at> debbugs.gnu.org
Subject: Re: bug#71790: parted -s emits a warning when shrinking a
partition
Date: 27/06/24 16:28:55

On Wed, Jun 26, 2024 at 11:51:38PM +0100, Sean Warner wrote:
> I am also having this bug reported in 2017:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=879555
> 
> $ parted -v
> parted (GNU parted) 3.6
> Copyright (C) 2023 Free Software Foundation, Inc.
> License GPLv3+
> Written by
> <http://git.debian.org/?p=parted/parted.git;a=blob_plain;f=AUTHORS>.
> 
> $ cat /etc/lsb-release 
> DISTRIB_ID="ManjaroLinux"
> DISTRIB_RELEASE="24.0.2"
> DISTRIB_CODENAME="Wynsdey"
> 
> -- If increasing the size of a partition the following command works
> but if shrinking a partition it gives a warning "Warning: Shrinking a
> partition can cause data loss, are you sure you want to continue?"
> and
> the command just exits back to the command prompt and no changes are
> made to the partition.
> 
> sudo parted -s /dev/loop0 resizepart 1 46280703s
> 
> I assumed that parted -s would automatically supply a default value
> of
> 'Yes' in this instance?

No, in script mode parted defaults to the safe option. Automatically
saying yes will lead to data loss so it defaults to know. I admit the
message is misleading, this is because of how parted handles warnings
like this and it could use some improvement.

I don't really have any suggestion for working around this other than
doing it in interactive mode.

> input-tty <-- But is this safe to keep using if not documented? Any
> plans to make ---pretend-input-tty an official "thing" in Parted?

No, it's there for the tests. But there's no plan to remove it since
the
tests depend on it. But I really don't recommend automating things that
could lose data.

Brian

[Message part 2 (text/html, inline)]

This bug report was last modified 72 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.