Preparing a Micro-SD Memory Card for use with Gumstix COM

This document describes how to partition, format, and copy files to a 4GB Micro-SD memory card for use in a Gumstix for the Belcarra Overo TestDrive project

General note:  User input is shown in bold face non-italic type.

Required equipment:

Insert the Micro-SD card into the reader/writer - you may have to use the SD card adapter.  There are Micro-SD card readers/writers available.  Use one of those if you have access to one.

Insert the SD/Micro-SD card reader/writer into a USB port on the PC.

If your Linux machine mounts partitions automatically (as on an Ubuntu system) any partition(s) on the Micro-SD card will be mounted.  Use the “mount” command to show what’s mounted.  You don’t need to have root permissions to perform this step.

$ mount

/dev/sda1 on / type ext4 (rw,errors=remount-ro)

(Some items deleted for brevity)

/dev/sdb1 on /media/FAT type vfat (rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,flush)

/dev/sdb3 on /media/FAT2 type vfat (rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,flush)

/dev/sdb2 on /media/f0c88758-5676-40ee-ad41-945e14000787 type ext3 (rw,nosuid,nodev,uhelper=udisks)

There is only one hard disk installed in the example system, it shows up as /dev/sda1. Otherwise the letter shown in red above will differ

Note that, in this example, there are 3 partitions showing on /dev/sdb (which is the Micro-SD card).  A new card will only have 1 partition mounted - it would be /dev/sdb1.  In any case these/this partition(s) need to be unmounted.  You need to either be the “root” user (dangerous!) or use “sudo” to obtain proper permissions.

$ sudo umount /dev/sdb[123]

Now, create the partitions on the Micro-SD card.  You need root permissions from here on.

$ sudo fdisk /dev/sdb

Create a new DOS disklabel (disregard the warning):

Command (m for help): o

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Look at the information for this memory card.  Depending on the make of the card the number of available bytes may be slightly different (this example is for a Kingston 4G Micro-SD card):

Command (m for help): p

Disk /dev/sdb: 3951 MB, 3951034368 bytes  This is the number we need

122 heads, 62 sectors/track, 1020 cylinders

Units = cylinders of 7564 * 512 = 3872768 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x99f67ef8

   Device Boot          Start             End          Blocks   Id  System

IMPORTANT: Remember (write down) the total number of bytes available (italicized above).  We will need this number to calculate the total of “cylinders” we need to specify.

To calculate the number of cylinders, divide the total number of bytes (3951034368 in this example) by 8225280 - this gives a result of  480.352.  Round down to the nearest integer (480 in this case) - that will be the number of cylinders.

Switch to “expert” mode:

Command (m for help): x

Specify the number of “heads” (255):

Expert command (m for help): h

Number of heads (1-256, default 122): 255

Specify the number of “sectors” (63):

Expert command (m for help): s

Number of sectors (1-63, default 62): 63

Specify the number of “cylinders” (480 from above calculation):

Expert command (m for help): c

Number of cylinders (1-1048576, default 1020): 480

Return to “normal” mode:

Expert command (m for help): r

Create 3 partitions, first and third will be FAT32, second will be Linux ext3:

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

First partition will be 200 megabytes in size:

Partition number (1-4): 1

First cylinder (1-480, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-480, default 480): +200M

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

The first partition is large enough to hold the active kernel and five backup versions.

Second partition will be 2 gigabytes in size:

Partition number (1-4): 2

First cylinder (27-480, default 27):

Using default value 27

Last cylinder, +cylinders or +size{K,M,G} (27-480, default 480): +2G

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

The second partition will hold the root filesystem, containing the standard (gadget) USB modules and Belcarra’s own USB modules, and several test files in the document root of the Apache subsystem.

Third partition will take up the remainder of the SD card:

Partition number (1-4): 3

First cylinder (289-480, default 289):

Using default value 289

Last cylinder, +cylinders or +size{K,M,G} (289-480, default 480):

Using default value 480

The third partition is used for running mass storage tests.

Change the first partition type to FAT32:

Command (m for help): t

Partition number (1-4): 1

Hex code (type L to list codes): c

Changed system type of partition 1 to c (W95 FAT32 (LBA))

Change the second partition type to Linux (it’s the default):

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 83

Change the third partition type to FAT32:

Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): c

Changed system type of partition 3 to c (W95 FAT32 (LBA))

Make the first partition “active” (bootable):

Command (m for help): a

Partition number (1-4): 1

Make sure everything is correct:

Command (m for help): p

Disk /dev/sdb: 3951 MB, 3951034368 bytes

255 heads, 63 sectors/track, 480 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x99f67ef8

   Device Boot          Start             End          Blocks     Id  System

/dev/sdb1   *               1              26          208813+   c  W95 FAT32 (LBA)

/dev/sdb2                  27             288         2104515   83 Linux

/dev/sdb3                 289             480         1542240   c  W95 FAT32 (LBA)

Now commit the new partition information and exit fdisk:

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x

partitions, please see the fdisk manual page for additional

information.

Syncing disks.

Format the first partition.  The “-F” option forces 32-bit (FAT32) - this is necessary.

The “-n” option goves the partition a name (BOOT):

$ sudo mkfs.vfat -F32 /dev/sdb1 -n BOOT

mkfs.vfat 3.0.7 (24 Dec 2009)

Format the second partition as EXT3.  The “-L” option assigns a name (ROOTFS in this case) to the partition:

$ sudo mkfs.ext3 -L ROOTFS /dev/sdb2

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

131648 inodes, 526128 blocks

26306 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=541065216

17 block groups

32768 blocks per group, 32768 fragments per group

7744 inodes per group

Superblock backups stored on blocks:

    32768, 98304, 163840, 229376, 294912

Writing inode tables:  done                                

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

Format the third partition.  The “-F” option forces 32-bit (FAT32) - this is necessary.

The “-n” option gives the partition a name (MSC):

$ sudo mkfs.vfat -F32 /dev/sdb3 -n MSC

mkfs.vfat 3.0.7 (24 Dec 2009)

Now we have to copy certain files over to the Micro-SD card in order to build a working system.

Let’s start with the boot partition (/dev/sdb1) first:

Search your system to locate the following 3 files: MLO, u-boot.bin and uImage - the last 2 may have somewhat different names (like u-boot-overo.bin and uImage-overo.bin if BitBake was used to create the system) - don’t worry about that, this will be taken care of in the following steps.

First, mount the first partition of the card onto your system.  Depending on your system you will find directories with names like “/mnt” (RedHat) or “/media” (Ubuntu).  /media will be used in this example.  Look in there and see if there if there is a directory called “sdcard”.  If not, create it.

$ sudo mkdir /media/sdcard

Now mount the card’s first partition:

$ sudo mount -t vfat /dev/sdb1 /media/sdcard

The first file to be copied is MLO.  It is EXTREMELY important that this be the first file copied as this gets loaded into the Overo at boot time, and there is limited space in the Overo for this:

$ sudo cp (path-to-MLO)/MLO /media/sdcard/MLO

The next file is u-boot.bin.  Whatever the name of the u-boot.bin you found it MUST be called u-boot.bin on the card:

$ sudo cp (path-to-u-boot.bin)/(name of u-boot.bin file) /media/sdcard/u-boot.bin

The last file is uImage.  Again, if it’s a different name it MUST be renamed to uImage on the card:

$ sudo cp (path-to-u-boot.bin)/(name of uImage file) /media/sdcard/uImage

Verify that all those files are present on the card.  If so, unmount the card:

$ sudo umount /media/sdcard

The next step is to get the root filesystem onto the card’s second partition.  Mount the partition:

$ sudo mount /dev/sdb2 /media/sdcard

Find out where the omap-console-image file is on your system.  BitBake calls the file “omap3-console-image-overo.tar.bz2.  Note that it is a tar file which was compressed using bz2.

Go to the mountpoint for the card (root permission not necessary):

$ cd /media/sdcard

Extract the root filesystem file (root permission is necessary):

$ sudo tar xjvf (path to image file)/(name of image file)

A lot of filenames will scroll by rather quickly.  When done, go back to where you were before:

$ cd -

Now use the “sync” command to enable the card to be written fully - this may take a couple of minutes:

$ sudo sync

When completed you will get a command prompt.  When it appears unmount the card:

$ sudo umount /media/sdcard

You may now unplug the SD card reader/writer from the PC and extract the Micro-SD card.  With the power to the Overo disconnected, insert the Micro-SD card into the socket on the Overo.  Apply power to the Overo and it should boot.

Return to USB TestDrive Project

Additional  Documentation

Related sites

Copyright ©2005-2011 Belcarra Technologies (2005) Corp.    

info@belcarra.com