Parted -s emits a warning when shrinking a partition

I have a feeling that this is a long standing issue with the parted command but I would be very grateful if someone could verify on their Manjaro too?

I am also having this bug reported in 2017.

$ 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?

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

My question is not so much “how” do I make this work but can you please try this on your system and does it also not work for you in which case it must be a bug I guess?

To try this out on your Manjaro machine, make a .img file and use parted to put a partition on it and then try to shrink that partition with parted in non-interactive mode:

dd if=/dev/zero of=myfs.img count=204800
sudo parted myfs.img mktable gpt
sudo parted myfs.img mkpart primary ext4 2048s 100%
sudo parted myfs.img align-check optimal 1
sudo parted myfs.img

You will see that partition 1 has an end sector of 204766.

Try using parted in script mode (non-interactive mode) to shrink the partition by just one sector (204765s)
sudo parted -s -a opt myfs.img "resizepart 1 204765s"

Did you get the user prompt: “Warning: Shrinking a partition can cause data loss, are you sure you want to continue?” and the command just exits back to the command line prompt?

If so, I guess this is a bug or any ideas what I’m doing wrong?

Any help much appreciated,

Flex

This seems to be long-standing as you have indicated.

In any case, this would also seem to have nothing to do with Manjaro. A further bug report (or query) to Debian seems the most likely to generate a satisfactory response.

A workaround:

Instead, use the GParted GUI from a Manjaro Live Installer DVD/ISO/USB, which will successfully shrink a partition.

Note that a recent forum thread has highlighted that GParted is not available in every Manjaro ISO for use in the Live Environment. If you discover this is the case for whichever Manjaro flavour you use, there is an easy workaround: GParted can be installed (into memory) within the Live Environment as easily as if it were your own User account:

sudo pacman -S gparted

I hope this helps. Cheers.

2 Likes

@soundofthunder thanks for the suggestion.

I have read so many threads and posts and comments about this that I was uncertain if the issue was with my version of parted (v3.6) or if parted behaves differently on different linux distros. That’s why I asked if anyone would run those commands above to help me debug this.

I posted a bug report and one of the maintainers got back to say that parted -s will always default to safe options. In other words it will still warn the user if there is a chance they might lose data such as when shrinking a partition as I was trying to do.

This seems reasonable but all the parted man page says about the -s --script option is “Never prompts for user intervention” and this has led to some confusion amongst many users given the large number of threads and posts about this. Many might expect that parted -s will really never prompt you no matter what you are doing.

There are a few other bug reports about parted -s and this one, maybe posted by a proper geek, contains almost nothing at all but a patch which can make parted -s behave the way many people probably expect it to.

Following instructions from the GNU Parted Homepage and this helpful site I downloaded the parted source code, added in that patch and compiled it locally. Finally parted -s does what I expected! If I loose data that’s my problem!

Flex

1 Like

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.