15

I tried to use parted for scripted partitionning like so :

parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 -1

But it complains about -1 not being a recognized option. Still the same sub-command works in the parted prompt. So my question is how to use the same options in a script ?

Nicolas Barbey
  • 6,639
  • 4
  • 28
  • 34

3 Answers3

30

Finally found a solution :

parted -s -a optimal /dev/sda mklabel gpt -- mkpart primary ext4 1 -1s

-- is very important for it to work here.

Note the use of ‘--’, to prevent the following ‘-1s’ last-sector indicator from being interpreted as an invalid command-line option.

Community
  • 1
  • 1
Nicolas Barbey
  • 6,639
  • 4
  • 28
  • 34
  • If the intention is to allocate all remaining space then `-0` will achieve that (instead of `-1` which would leave the last megabyte unallocated). – starfry Sep 19 '17 at 13:23
  • 3
    I got this error: `The closest location we can manage is 1000kB to 537GB (sectors 1953..1048575966).` replace `1 -1s` with `0% 100%` works – ospider Nov 02 '18 at 03:57
  • @ospider No, `0% 100%` is even worse: *You requested a partition from 0,00B to xxxGB (sectors 0..xxxx)*, which means the entire disk — including MBR and partition table itself. – Anton Samsonov Nov 26 '19 at 14:27
1

You can also use --script option. In this case you should put your script part in single quotes.

Example:

parted --script /dev/sda 'mkpart primary ext4 1 -1'   
ᐅdevrimbaris
  • 718
  • 9
  • 20
0

I guess it's parted's argument parser's fault.

Try parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \-1 or parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 \\-1

shkschneider
  • 17,833
  • 13
  • 59
  • 112