1 #!/bin/sh 2 3 # Support formatting of partitions. 4 5 PROGNAME=`basename "$0"` 6 THISDIR=`dirname "$0"` 7 8 COMMON="$THISDIR/makesd-common" 9 FSCK="/sbin/fsck" 10 MKFS="/sbin/mkfs" 11 MKSWAP="/sbin/mkswap" 12 13 . "$COMMON" 14 15 16 17 # format <device> <type> 18 19 format() 20 { 21 DEVICE=$1 22 TYPE=$2 23 24 if [ ! -e "$DEVICE" ] ; then 25 echo "$DEVICE does not exist and therefore cannot be formatted." 1>&2 26 return 1 27 fi 28 29 case "$DEVICE" in 30 ( fat ) 31 "${MKFS}.vfat" -F 32 -n "boot" "$DEVICE" && "${FSCK}.vfat" -a -y "$DEVICE" 32 ;; 33 ( ext* ) 34 "${MKFS}.$TYPE" "$DEVICE" && "${FSCK}.$TYPE" -y "$DEVICE" 35 ;; 36 ( swap ) 37 "$MKSWAP" "$DEVICE" 38 ;; 39 esac 40 } 41 42 43 44 # Emit the help message if requested. 45 46 if [ "$1" = '--help' ] ; then 47 cat 1>&2 <<EOF 48 Usage: $PROGNAME 49 50 The input for this program is supplied via standard input as a partitioning 51 summary with each line providing a collection of tab-separated values. These 52 values appear in the following order: 53 54 <start> <size> <type> 55 56 Only the type value is employed by this program. Types recognised include ext, 57 ext2, ext3, ext4, fat and swap. 58 EOF 59 exit 0 60 fi 61 62 # Obtain details of the selected device. 63 64 check_device 65 66 PARTNUM=1 67 68 while read_fields ; do 69 DEVICE="${DEV}${PARTNUM}" 70 format "$DEVICE" "$TYPE" 71 PARTNUM=$(($PARTNUM + 1)) 72 done