|
Thanks to Graeme Gregory (also known as XorA), you can now use a script to automate the tedious process of creating a bootable SD/microSD card:
#! /bin/sh # (c) 2009 Graeme Gregory # modified by Steve Sakoman # This script is GPLv3 licensed!
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
umount ${DRIVE}1 mkfs.vfat -F 32 -n boot ${DRIVE}1
umount ${DRIVE}2 mke2fs -j -L rootfs ${DRIVE}2
You can download a copy of this script here.
To use the script you will need to know what device your SD/microSD card appears as when you insert it into your development machine's card slot.
WARNING: It is very important that you determine the proper device! Do not proceed if you are not certain, since accidentally specifying your development system's root device would destroy your linux installation.
On my Ubuntu 9.04 machine, the newly inserted card shows up as /dev/sde and that is the device name that will be used in the example below. You should substitute the proper device name for your machine. You can use the mount or dfcommand to see where the card mounts on your machine.
$ sudo mkcard.sh /dev/sde 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB) copied, 0.766167 s, 1.4 MB/s Disk /dev/sde doesn't contain a valid partition table DISK SIZE – 2032664576 bytes CYLINDERS – 247 Checking that no-one is using this disk right now ... OK
Disk /dev/sde: 247 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature /dev/sde: unrecognized partition table type Old situation: No partitions found New situation: Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System /dev/sde1 * 0+ 8 9- 72261 c W95 FAT32 (LBA) /dev/sde2 9 246 238 1911735 83 Linux /dev/sde3 0 - 0 0 0 Empty /dev/sde4 0 - 0 0 0 Empty Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1) to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1 (See fdisk(8).) umount: /dev/sde1: not mounted mkfs.vfat 3.0.1 (23 Nov 2008) mke2fs 1.41.4 (27-Jan-2009) Filesystem label=rootfs OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 119520 inodes, 477933 blocks 23896 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=490733568 15 block groups 32768 blocks per group, 32768 fragments per group 7968 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. $
|
TrujilloVivian makes this comment
Friday, 23 July 2010