Prepare Script
Create a file on the Linux host named mk3PartSDCard. Copy the contents of the script (see below) to this file and save it. See the later section for the contents of the two partition script.
This script requires a single input parameter which must be the device which is connected to the USB card reader. DO NOT RUN THE SCRIPT IF YOU ARE NOT COMPLETELY SURE THAT YOU HAVE ENTERED THE CORRECT DEVICE TO USE. If you specify the device connect to the host machine hard drive instead of the SD card reader, you will destroy the hard drive of your host machine. The next section shows how to figure out which device is connected the SD card and which is connected to the hard drive.
#! /bin/sh # mk3PartSDCard.sh v0.3 # Licensed under terms of GPLv2 DRIVE=$1 dd if=/dev/zero of=$DRIVE bs=1024 count=1024 SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'` echo DISK SIZE - $SIZE bytes CYLINDERS=`echo $SIZE/255/63/512 | bc` sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF ,9,0x0C,* 10,115,,- 126,,,- EOF mkfs.vfat -F 32 -n "boot" ${DRIVE}1 umount ${DRIVE}1 mkfs.ext3 -L "rootfs" ${DRIVE}2 umount ${DRIVE}2 mkfs.ext3 -L "START_HERE" ${DRIVE}3
Make the script executable with the following command
user@UbuntuVbox1004:~$ chmod 755 mk3PartSDCard
Run Script
After verifying the correct device that you must send to the script, it is necessary to unmount any directory that is mounted to the device. In the example above, the directory /media/disk is mounted to /dev/sdb1. To unmount run the following command
user@Ubuntu1004:~$ umount /dev/sdb1
The script must be executed with supre-user permissions. In Ubuntu, this is done by pre-pending the command with "sudo". When prompted for a password by sudo, use the password of the user account.
user@Ubuntu1004:~$ sudo ./mk3PartSDCard /dev/sdb
On a successful execution the terminal will look something like the following. The error that may come from sfdisk (as shown below) can be safely ignired.
http://processors.wiki.ti.com/index.php/How_to_Make_3_Partition_SD_Card