#!/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. # It depends on tools such as sfdisk, which is part of core utilities # of Linux. If working with the JFS filesystem, jfsutils is another # dependency. 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 for input before # the script proceeds. # # 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 or support of any kind. 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' is right for you. # # This script was tested by writing a factory 512MB SD image for the TS-7350 # to both a 2GB and 16GB SD card in both JFS and EXT3 filesystem formats. # CHECK FOR ROOT ACCESS if [ `id -u` -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=`ls -l ${DISK}* | tail -n 1 | awk '{print $NF}' | sed "s,$DISK,,g"` NUMBER=`fdisk -l $DISK | grep 83 | tail -1 | awk '{print $1}' | sed "s,$DISK,,g"` if [ ! -e ${DISK}$NUMBER ]; then echo "Valid T.S. partition not found!" echo "The script attempted to find the last partition with id of 0x83 but couldn't find it." echo "Verify with \"fdisk -l\" as root." echo "Exiting" exit 1 fi mount | grep $DISK > /dev/null if [ $? -eq 0 ]; then echo "Please unmount $DISK and re-run $0." exit 1 fi mount | grep "/mnt/tmp" > /dev/null if [ $? -eq 0 ]; then echo "This script plans on using /mnt/tmp as mount point for SD card," echo "but /mnt/tmp is a mount point for something else currently." echo "Please unmount it and re-run $0." exit 1 fi mkdir /mnt/tmp mount ${DISK}$NUMBER /mnt/tmp 2> /dev/null TYPE=`df -T /mnt/tmp | tail -n 1 | awk '{print $2}'` umount ${DISK}$NUMBER 2> /dev/null rmdir /mnt/tmp 2> /dev/null else echo "No disk found at ${1}!" echo "Exiting" exit 1 fi ######################################### # Final Check and Messages ######################################### goodbye(){ echo -n "Running filesystem check on ${DISK}$NUMBER..." fsck -f ${DISK}$NUMBER >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1