#!/bin/sh # This script will detect the last JFS or EXT3 partition of an SD card image # provided by Technologic Systems and expand it to the end of the disk, # leaving a small amount of padding. It depends on tools such as sfdisk, # which is part of core utilities of Linux, as well as and jfsutils if working # with JFS filesystem. # # In order to use the script, you will need to insert the SD card into the USB # SD card reader and then use the 'fdisk -l' command to find the device node. # The device node is typically enumerated as /dev/sdX, where X is what Linux # decided. Example usage is: './grow_sd /dev/sdb'. # # Since this deals with modifying the partition table of the SD card and data # may be lost, for this reason, you will be prompted if you want to proceed. # # Please understand that this script is only provided in the hopes that it will # be useful to Technologic Systems customers and does not have any guarantees # or warranties. If you require additional assistance, custom engineering is # available. Take care and understand what you are doing! If you're not # comfortable in running this script, then perhaps 'gparted' can be used. # # This script was tested by writing a factory 512MB SD image for the TS-7350 to # a 2GB SD card in both JFS and EXT3 filesystem formats. # CHECK FOR ROOT ACCESS if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi # CHECK FOR COMMAND LINE ARGUMENT if [ $# -lt 1 ]; then echo "Example Usage: $0 /dev/sdb" exit 1 fi # INITIALIZE VARIABLES TYPE=none # CHECK DISK AND PARTITIONS if [ -e $1 ]; then DISK=$1 NUMBER=`fdisk -l $DISK | grep 83 | awk '{print $1}' | sed "s,$DISK,,g"` if [ -e $NUMBER ]; then echo "Valid TS partition not found!" echo "Exiting" exit 1 fi else echo "No disk found at ${1}!" echo "Exiting" exit 1 fi expand_sd(){ mkdir /mnt/tmp 2> /dev/null mount ${DISK}$NUMBER /mnt/tmp 2> /dev/null TYPE=`df -T | grep ${DISK}$NUMBER | awk '{print $2}'` umount ${DISK}$NUMBER 2> /dev/null ORIG=`fdisk -l $DISK | grep ${DISK}$NUMBER | awk '{ print $3 }'` SIZE=`fdisk -l $DISK | grep Disk | awk '{print $5}'` UNITS=`fdisk -l $DISK | grep Units | awk '{print $9}'` END=`echo "($SIZE/$UNITS)-5" | bc` if [ $ORIG -gt $END ]; then echo "Original ($ORIG) is larger than end goal ($END)!" echo "Exiting" exit else echo -n "Expanding ${DISK}$NUMBER from $ORIG to $END... " ( { echo ,$END,0x83,- } | sfdisk -f $DISK -N$NUMBER ) >/dev/null 2>&1 ? \c" read WISH if [ $WISH = "n" ] ; then echo "Exiting" exit 1 fi echo "Proceeding..." expand_sd if [ $TYPE == "jfs" ]; then echo "JFS!" exit 1 # CHECK DEPENDENCIES which jfs_mkfs >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1