remakesd

Annotated makesd-partition

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