1 #!/bin/sh 2 3 # Support partitioning of a device using sfdisk. 4 # 5 # Important tasks: 6 # 7 # Erase bootloader blocks. 8 # Perform partitioning using sfdisk. 9 10 PROGNAME=`basename "$0"` 11 THISDIR=`dirname "$0"` 12 13 EXPAND="$THISDIR/makesd-expand-def" 14 PARTSUMMARY="$THISDIR/makesd-partition-summary" 15 PARTTABLE="$THISDIR/makesd-partition-table" 16 SFDISK="/sbin/sfdisk" 17 18 19 20 # Test sfdisk behaviour and obtain useful information. 21 22 init_sfdisk() 23 { 24 if "$SFDISK" -uS -s "$1" > /dev/null 2>&1 ; then 25 SFDISK_OPTIONS="-uS -L" 26 else 27 SFDISK_OPTIONS= 28 fi 29 } 30 31 32 33 # Obtain details of the selected device. 34 35 if [ ! "$DEV" ] ; then 36 cat 1>&2 <<EOF 37 No device specified. Use the DEV environment variable to indicate a device. 38 EOF 39 exit 1 40 fi 41 42 if [ ! -e "$DEV" ] ; then 43 cat 1>&2 <<EOF 44 Device not found: $DEV 45 EOF 46 exit 1 47 fi 48 49 # Test for the cylinder alignment option. 50 51 if [ "$1" = '--align' ] ; then 52 ALIGN_CYLINDER="$1" 53 shift 1 54 else 55 ALIGN_CYLINDER= 56 fi 57 58 DEF="$1" 59 60 if [ ! "$DEF" ] ; then 61 cat 1>&2 <<EOF 62 No definition specified. 63 EOF 64 exit 1 65 fi 66 67 # Initialise sfdisk usage. 68 69 init_sfdisk "$DEV" 70 71 # Expand the definition to partitioning options. 72 # Use the options to generate a partition summary. 73 # Convert the summary into a table. 74 # Present the table to sfdisk. 75 76 "$EXPAND" "$DEF" \ 77 | xargs "$PARTSUMMARY" \ 78 | "$PARTTABLE" $ALIGN_CYLINDER \ 79 | "$SFDISK" $SFDISK_OPTIONS "$DEV"