no way to use resizepart non-interactively on busy partition

Bug #1270203 reported by Scott Moser on 2014-01-17
This bug affects 8 people
Affects Status Importance Assigned to Milestone
parted (Ubuntu)

Bug Description

I can't see a way to really use resizepart usefully on a mounted partition (which is kind of the point of the functionality).

There are a few issues:
a.) it seems that the size provided is in MB when realistically I'd like to provide the number in sectors or blocks, something more fine-grained than that.
b.) no way to say 'grow as big as you can'
c.) no way to use 'force' or use non-interactively outside of undocumented flag.

$ echo "1,1000,L" | sudo sfdisk /dev/vdb
$ grep "vdb" /proc/partitions
 253 16 20971520 vdb
 253 17 504000 vdb1
$ sudo mkfs /dev/vdb1
$ sudo mount /dev/vdb1 /mnt

## now /dev/vdb is busy (mounted) try to resizepart on it.

$ sudo parted /dev/vdb resizepart 1 </dev/null
Warning: Partition /dev/vdb1 is being used. Are you sure you want to continue?
$ echo $?

# so that didn't resize (reading from /dev/null). Not surprising.
# try with 'Yes' to stdin.
echo "Yes" | sudo parted /dev/vdb resizepart 1; echo $?
Warning: Partition /dev/vdb1 is being used. Are you sure you want to continue?

I've also tried the undocumented '---pretend-input-tty' without success.
It seems it can be used for some operations, but not for others.
For example, this worked on an unmounted partition:
 echo "Yes" | sudo parted ---pretend-input-tty /dev/vdb resizepart 1 500

But this doesn't seem to work on a mounted partition which is really my goal:
echo "Yes" | sudo parted ---pretend-input-tty /dev/vdb resizepart 1 1000
Warning: Partition /dev/vdb1 is being used. Are you sure you want to continue?
parted: invalid token: 1000
Yes/No? Yes
End? [500MB]?

Related bugs:
 * bug 1212492: cloud-init cc_growpart broken if parted resizefs found

Phillip Susi (psusi) wrote :

echo "Yes" | sudo parted ---pretend-input-tty /dev/vdb resizepart 1 1000 fails because of another bug I had noticed recently but not gotten around to fixing yet... when looking for an answer to the exception question, like regular input, parted first looks for the next word given on the command line before trying to read from stdin. It should skip the command line and go straight to stdin for exceptions. You can work around this by not mixing stdin with command line arguments, and just echo everything. In other words:

cat <<EOF | sudo parted ---pretend-input-tty /dev/vdb
resizepart 1 1000

You can also use whatever units you like; you just need to either change the default unit with the unit command, or append the unit suffix to the numbers, such as 2048s for sector 2048.

Jesse Szwedko (jesse-szwedko) wrote :

Looks like it actually expects the 'yes' before the partition end. i.e.:

sudo parted /dev/vdb 1 yes 1000

appears to work.

Scott Moser (smoser) wrote :

ok. i gave Jesse's suggestion a try.
It does seem to work, but some things are a bit annoying
a.) if the partition is not mounted, then passing 'yes' as shown results in error.
 | $ sudo mount /dev/vdb1 /mnt
 | $ sudo parted /dev/vdb resizepart 1 yes 1024
 | Warning: Partition /dev/vdb1 is being used. Are you sure you want to continue?
 | Information: You may need to update /etc/fstab.
 | $ echo $?
 | 0

 | $ sudo umount /mnt
 | $ sudo parted /dev/vdb resizepart 1 yes 1024
 | Error: Invalid number.
 | $ echo $?
 | 1

b.) I have to know the target size. I'd like to just say "make it as big as possible".

I could work around both, but both are annoying.

Phillip Susi (psusi) wrote :

"100%" is "as big as possible" ;)

David Lechner (dlech) wrote :

My workaround is:

parted --script /dev/mmcblk0 unit % resizepart 2 100% || parted /dev/mmcblk0 unit % resizepart 2 Yes 100%

This tries tries the "correct" version first and if it fails (because the partition is mounted) then uses the workaround.

Sunil Mohan Adapa (f-su7il-g) wrote :

With the release of parted 3.3 the above listed workarounds no longer work. The work around that worked for me was something like this:

echo -e "yes\n100%" | parted /dev/mmcblk0 ---pretend-input-tty unit % resizepart 2

walterav (walterav) wrote :

It still affects me on Ubuntu Focal Fossa 20.04 using parted 3.3, using @Sunil Mohan Adapa (f-su7il-g)#6 workaround does work however the upstream bug report seems to suggest its intentional?

In Ubuntu 19.10 using parted 3.2 this command used to work without interaction and without the -s/--script arguments:
parted /dev/sdX resizepart 2 y 100%

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers