1 #!/bin/sh 2 3 # Support partitioning of a device using sfdisk. This program accepts a 4 # partitioning summary on standard input. 5 # 6 # Important tasks: 7 # 8 # Erase bootloader blocks. 9 # Perform partitioning using sfdisk. 10 # 11 # Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> 12 # 13 # This program is free software; you can redistribute it and/or modify it under 14 # the terms of the GNU General Public License as published by the Free Software 15 # Foundation; either version 3 of the License, or (at your option) any later 16 # version. 17 # 18 # This program is distributed in the hope that it will be useful, but WITHOUT 19 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21 # details. 22 # 23 # You should have received a copy of the GNU General Public License along with 24 # this program. If not, see <http://www.gnu.org/licenses/>. 25 26 PROGNAME=`basename "$0"` 27 THISDIR=`dirname "$0"` 28 29 COMMON="$THISDIR/makesd-common" 30 PARTTABLE="$THISDIR/makesd-partition-table" 31 SFDISK="/sbin/sfdisk" 32 33 . "$COMMON" 34 35 36 37 # Test sfdisk behaviour and obtain useful information. 38 39 init_sfdisk() 40 { 41 if "$SFDISK" -uS -s "$1" > /dev/null 2>&1 ; then 42 SFDISK_OPTIONS="-uS -L" 43 else 44 SFDISK_OPTIONS= 45 fi 46 } 47 48 49 50 # Emit the help message if requested. 51 52 if [ "$1" = '--help' ] ; then 53 cat 1>&2 <<EOF 54 Usage: $PROGNAME [ --align ] 55 56 Partition a device according to a partitioning summary supplied via standard 57 input. This summary is passed on to the partition table generator: 58 59 $PARTTABLE 60 61 $(align_cylinder_description) 62 EOF 63 exit 0 64 fi 65 66 # Obtain details of the selected device. 67 68 check_device 69 70 # Test for the cylinder alignment option. 71 72 if test_align_cylinder $* ; then shift 1 ; fi 73 74 # Initialise sfdisk usage. 75 76 init_sfdisk "$DEV" 77 78 # Convert the partitioning summary into a partition table description. 79 # Present the table to sfdisk. 80 81 "$PARTTABLE" $ALIGN_CYLINDER \ 82 | "$SFDISK" $SFDISK_OPTIONS "$DEV"