1.1 --- a/makesd-partition-table Thu May 23 22:30:49 2019 +0200
1.2 +++ b/makesd-partition-table Fri May 24 01:05:24 2019 +0200
1.3 @@ -10,6 +10,12 @@
1.4
1.5
1.6
1.7 +# Cylinder size in sectors for alignment purposes.
1.8 +
1.9 +HEADS=255
1.10 +SECTORS=63
1.11 +CYLINDER_SIZE=$(($HEADS * $SECTORS))
1.12 +
1.13 # Global partition number and previous partition details.
1.14
1.15 PARTNUM=1
1.16 @@ -32,10 +38,20 @@
1.17
1.18 emit_partition_fields()
1.19 {
1.20 - if [ "$PREVSTART" ] ; then
1.21 - echo -n " start=${PREVSTART}${SFDISK_UNIT_SUFFIX}"
1.22 + if [ "$PREVSTART" = '0' ] ; then
1.23 + FIRSTPART=yes
1.24 + else
1.25 + FIRSTPART=
1.26 fi
1.27
1.28 + PREVSTART=`align_cylinder $PREVSTART`
1.29 +
1.30 + if [ "$PREVSTART" = '0' ] ; then
1.31 + PREVSTART=1
1.32 + fi
1.33 +
1.34 + echo -n " start=${PREVSTART}${SFDISK_UNIT_SUFFIX}"
1.35 +
1.36 # Obtain any explicitly stated size.
1.37 # Without a size, use start details to calculate a size.
1.38 # Without start details, claim the rest of the device.
1.39 @@ -43,9 +59,15 @@
1.40 REMAINING=$(($DEVSIZE - $PREVSTART))
1.41
1.42 if [ "$PREVSIZE" ] ; then
1.43 - PREVSIZE=$(($PREVSIZE * $DEVSIZE / 100))
1.44 + PREVSIZE=$((($PREVSIZE * $DEVSIZE) / 100))
1.45 + PREVSIZE=`align_cylinder $PREVSIZE`
1.46 +
1.47 + if [ "$FIRSTPART" ] ; then
1.48 + PREVSIZE=$(($PREVSIZE - 1))
1.49 + fi
1.50 +
1.51 elif [ "$START" ] ; then
1.52 - PREVSIZE=$(($START - $PREVSTART))
1.53 + PREVSIZE=$((`align_cylinder $START` - $PREVSTART))
1.54 else
1.55 PREVSIZE=$REMAINING
1.56 fi
1.57 @@ -59,6 +81,7 @@
1.58 if [ "$PREVTYPE" ] ; then
1.59 echo -n " Id=`partition_type $PREVTYPE`"
1.60 fi
1.61 +
1.62 echo
1.63 }
1.64
1.65 @@ -70,6 +93,7 @@
1.66 PREVSTART=$START
1.67 elif [ "$PREVSTART" ] && [ "$PREVSIZE" ] ; then
1.68 PREVSIZE=$(($PREVSIZE * $DEVSIZE / 100))
1.69 + PREVSIZE=`align_cylinder $PREVSIZE`
1.70 PREVSTART=$(($PREVSTART + $PREVSIZE))
1.71 else
1.72 PREVSTART=0
1.73 @@ -122,19 +146,33 @@
1.74 "$SFDISK" -s "$1"
1.75 }
1.76
1.77 +# Align to cylinders.
1.78 +
1.79 +align_cylinder()
1.80 +{
1.81 + # Round up to the nearest cylinder.
1.82 +
1.83 + CYLINDER=$((($1 + $CYLINDER_SIZE - 1) / $CYLINDER_SIZE))
1.84 +
1.85 + # Emit the number of sectors.
1.86 +
1.87 + echo $(($CYLINDER * $CYLINDER_SIZE))
1.88 +}
1.89 +
1.90 # Test sfdisk behaviour and obtain useful information.
1.91
1.92 init_sfdisk()
1.93 {
1.94 - if "$SFDISK" -uB -s "$1" > /dev/null 2>&1 ; then
1.95 - SFDISK_UNIT_SUFFIX=
1.96 - else
1.97 - SFDISK_UNIT_SUFFIX="K"
1.98 - fi
1.99 + SFDISK_UNIT_SUFFIX=
1.100 +
1.101 + # Obtain the device size in 512-byte sectors.
1.102
1.103 - # Obtain the device size in blocks.
1.104 + DEVSIZE=$((`device_size "$1"` * 2))
1.105
1.106 - DEVSIZE=`device_size "$1"`
1.107 + # Find the cylinder-addressable size.
1.108 +
1.109 + CYLINDERS=$(($DEVSIZE / $CYLINDER_SIZE))
1.110 + DEVSIZE=$(($CYLINDERS * $CYLINDER_SIZE))
1.111 }
1.112
1.113
1.114 @@ -149,7 +187,7 @@
1.115 size for each partition. Each occurrence of the -f option starts a new partition
1.116 description.
1.117
1.118 -Start positions are indicated as numbers of 1024-byte blocks.
1.119 +Start positions are indicated as numbers of 512-byte sectors.
1.120
1.121 Sizes are indicated as percentages of the entire device; if omitted, the
1.122 remainder of the device will be used.