There is an updated and bugfixed version of this script now added to the OE git repository where all updates from now will be done.
Latest Version
Got some feedback from people on IRC so added some checks so people with builtin card readers can run the script without having to edit it.
Download
#! /bin/sh
# mkcard.sh v0.2
# (c) Copyright 2009 Graeme Gregory
# Licensed under terms of GPLv3
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`
echo CYLINDERS - $CYLINDERS
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
if [ -b ${DRIVE}1 ]; then
mkfs.vfat -F 32 -n "boot" ${DRIVE}1
else
if [ -b ${DRIVE}p1 ]; then
mkfs.vfat -F 32 -n "boot" ${DRIVE}p1
else
echo "Cant find boot partition in /dev"
fi
fi
if [ -b ${DRIVE}2 ]; then
mke2fs -j -L "rootfs" ${DRIVE}2
else
if [ -b ${DRIVE}p2 ]; then
mke2fs -j -L "rootfs" ${DRIVE}p2
else
echo "Cant find rootfs partition in /dev"
fi
fi
Thanks for your script. Simple but efficient… and exactly what I was searching for.
I made few customizations:
– Detect if drive has been given on command line. If fail, then usage is displayed.
– I had an issue with your script by having Nautilus file browser (I’m using Ubuntu Gnome) starting automatically after FAT32 part.
Don’t know why! May be because of my SD card that was containing some pictures before.
Therefore, I added some umount before each mkfs/mke2fs to solve that issue.
#! /bin/sh
# mkcard.sh v0.2
# (c) Copyright 2009 Graeme Gregory
# Licensed under terms of GPLv3
if [ -n "$1" ]; then
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`
echo CYLINDERS – $CYLINDERS
{
echo ,9,0×0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
if [ -b ${DRIVE}1 ]; then
umount -l ${DRIVE}1
mkfs.vfat -F 32 -n “boot” ${DRIVE}1
else
if [ -b ${DRIVE}p1 ]; then
umount -l ${DRIVE}p1
mkfs.vfat -F 32 -n “boot” ${DRIVE}p1
else
echo “Cant find boot partition in /dev”
fi
fi
if [ -b ${DRIVE}2 ]; then
umount -l ${DRIVE}2
mke2fs -j -L “rootfs” ${DRIVE}2
else
if [ -b ${DRIVE}p2 ]; then
umount -l ${DRIVE}p2
mke2fs -j -L “rootfs” ${DRIVE}p2
else
echo “Cant find rootfs partition in /dev”
fi
fi
else
echo “Usage: sudo mkcard.sh ”
echo ” Example: sudo mkcard.sh /dev/sdd>”
fi
Comment by Cyril — October 12, 2009 @ 2:58 pm
Hi Graeme, I can’t tell you how much time your little script has saved me. I have also posted a link to it in the Meld embedded Linux Texas Instruments discussion group at
http://meld.mvista.com
We’d be very happy if you joined the discussion.
thanks!
Jeff
Comment by Jeff — October 24, 2009 @ 7:02 am