Monday, July 09, 2012

Scripting fdisk

As part of a larger script that installs a linux distro on SD card, I was trying automate the partitioning of the card, fortunately, that can easily be done with sfdisk(8) the format of each line fed to sfdisk is:
<start> <size> <id> <bootable> <c,h,s> <c,h,s>
Some fields are optional, like start or size, if left out sfdisk will use the defaults, i.e. the first cylinder or the remainder of the disk etc...  The following script creates two partitions a 16-cylinder/id(53) partition and the remaining of the disk in a partition of type 83:
echo "umounting device ${dev}..."
umount ${dev}*

echo "creating partitions on ${dev}..."
sfdisk ${dev} << EOF
,16,53,
,,83
EOF

No comments:

Post a Comment