GNU parted resizepart in script

In my case, I was using Parted 3.2 from within a tty-less SSH session. The "Yes" command hack didn't work, as the parted code has the following test:

    /* script-mode: don't handle the exception */
    if (opt_script_mode || (!isatty (0) && !pretend_input_tty))
            return PED_EXCEPTION_UNHANDLED;

Note that 'isatty' test, which will fail. The 'pretend_input_tty' is an undocumented command line option, which can be switched on via ---pretend-input-tty.

So, if you want to use parted from a script, my answer is the following:

/sbin/parted -a optimal /dev/loop1 ---pretend-input-tty resizepart 4 Yes 522239s

Note the three dashes in front of pretend-input-tty. I think this is supposed to scare us away. Not sure though.


If resizepart does not work, you might have to resort to rm and mkpart to achieve the same thing.

Of course, this would require you to parse the partition table first in order to determine partition type and start offset. Unless you already know the necessary values. After all you had to get the 166016512B from somewhere too.

parted has the --machine option to produce easily parseable output. On the other hand, examples of actually parsing it are not easily found. ;)


This bug is noted here: https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203

As noted in the thread, there are two work arounds. The simplest is to simply append "Yes" to the command list:

parted --script /dev/sda unit B resizepart 2 1166016512B Yes