no way to use resizepart non-interactively on busy partition

Bug #1270203 reported by Scott Moser
42
This bug affects 9 people
Affects Status Importance Assigned to Milestone
parted (Ubuntu)
Confirmed
Low
Unassigned

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.

Example:
$ 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 $?
1

# 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?
1

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

Revision history for this message
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
yes
EOF

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.

Revision history for this message
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.

Revision history for this message
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

 However:
 | $ 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.

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

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

Revision history for this message
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.

Revision history for this message
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

Revision history for this message
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?

https://lists.gnu.org/archive/html/bug-parted/2020-01/msg00005.html

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%

Revision history for this message
Jure Sah (dustwolfy) wrote :

The `---pretend-input-tty` parameter doesn't work for me on parted 3.3-4 in Ubuntu 20.

I ended up having to use fdisk to delete and then re-create the partition:
```
printf "d\nn\np\n1\n\n\nn\np\nw\n" | fdisk -B /dev/sda
```

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.