Scripting Partition Creation In Linux

I knew I could use fdisk in Linux to create partitions for me from a script. This can come in handy during kickstart for (re)deployment of a server and you don't want to let anaconda handle partitions for you. Or you simply want to be absolutely sure things go as you want, instead of relying on software with unknown bugs or quirks.

I knew you can use something like:
fdisk /dev/sda << EOF
n
p
1


t
8e
q
EOF
to partition /dev/sda for you with one large partitions and give it type 8e (LVM). (The 'q' is so that those who simply copy this, don't immediately wipe some disk.) But I was looking for somewhat cleaner, more intuitive style. James Stephens pointed out the use of sfdisk from scripts. While I don't know if sfdisk is less reliable than fdisk or parted, or how to handle byte-aligning disks [1] [2] [3] from these scripts, it's a good place to start and I wanted to document it here.

No comments: