script to gdisk to create a new partition

I’m trying to script to gdisk to create a new partition of LVM type (for pvcreate) so I typed this but I does not work :

diskModelName=yourDiskModel
diskSerialNumber=yourDiskSerialNumber
lvmPartitionNumber=2
cat<<-EOF | sudo gdisk $disk
p
n


8E00
c
$lvmPartitionNumber
$diskModelName-$diskSerialNumber
p
w
y
EOF

Can you help me ?

Asked By: SebMa

||

You can use sgdisk (it should be available from the same package as gdisk and it’s the same tool just non-interactive). For your case you should be able to use something similar to

sgdisk -n $lvmPartitionNumber:0:0 -t $lvmPartitionNumber:8E $disk

(the 0:0 part is start and end of the partition and zero is for automatic).

Answered By: Vojtech Trefny
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.