1

With this line:

(echo o; echo n; echo p; echo 1; echo ; echo +24G; echo a; echo t; echo 7; echo w) | fdisk /dev/sda

I can create a new active primary partition for NTFS, 24 Giga large. The syntax is ugly but effective.

How can I do the same with parted or sfdisk?

2 Answers 2

3

This is easy using parted. The -s option is used for scripting. The following produces the same results as your fdisk line:

parted -s /dev/sda mkpart primary NTFS 1 24G
3
  • okay, but add mklabel msdos before the mkpart (what used to be echo o in the fdisk command above). Commented Oct 26, 2013 at 20:42
  • @frostschutz: do you know if I can specify the "size" rather than the "end", like "+24G" in fdisk ? Commented Oct 27, 2013 at 19:18
  • 2
    @antonio parted does not support the +24G syntax. Closest you can get is using shell arithmetic instead so you can use something along the lines of parted ... $start $(($start+$size)). Commented Oct 27, 2013 at 19:33
1

With sfdisk:

sudo sfdisk --label dos /dev/sda <<EOF
device: /dev/sda
unit: sectors
sector-size: 512

size= $((24 * 2097152)), type=7, bootable
EOF

Note that sfdisk deals with starting position and alignment of partitions automatically if the values are not specified. The header might not even be necessary but I usually include those values just to be sure.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.