XO Laptop Shop
OLPC News Forum
USB Memory Sticks & SD Cards
SDcard formatting HOWTO
Get your own OLPC -
Buy an XO laptop on eBay
Topic: SDcard formatting HOWTO (Read 10643 times)
SDcard formatting HOWTO
OLPC News Forum Expert
April 17, 2011, 01:11:59 AM
SDcards are quite common on the XO-1 to expand its limited 1GB storage and provide some swap space for its limited 256MB of RAM.
I spend some time playing with my 4 SDcards and although there is sufficient info out there I thought to give my take and howto here.
Although there are frequent references to
, the howto is generally applicable.
We assume that you are using an XO-1.
If you have an XO-1.5 or just another computer with linux, find out where your card is mounted running “df -T” in the terminal before and after you insert the card.
Replace “/dev/mmcblk0“ below with the device of the card in your system.
It is possible that you damage your card, so NO WARANTIES and be careful
Unfortunately the SDcard industry although it has some standards, behind the facade is the wild-wild west. Even the same model from a given brand can have differences from one card to the next!
All cards perform the best when (factory) formated as vfat and write or read one file at a time, preferably a big one. This is good when when you use them unmodified for picture of videos in your camera or to store files in a computer, but useless when housing an OS, linux or other.
Except puppylinux of course in the “frugal” configuration that is using just 4 big files (initrd.gz, vmlinuz, puppy.sfs and puppysave.2/3fs) and runs fine from vfat media.
But what about if you want an ext2/3/4 file system and some swap?
There are 3 things that make a lot of difference in the performance of an SDcard in these conditions,
the numbers of erase blocks that can be open simultaneously and
the erase block size.
Of course you like a high random w/r speed (> 3MB/s)
You would like at least 5 open blocks (but not many cards have them).An ext2 file system needs to write 4 different entries for every little file you want to write and ext3, 5!
The erase block size is important to know so you can align the file system to the blocks. Given that the cards have to erase and write entire blocks, if a 1kb file span the block boundary the entire 2, 4 or 8MB block needs be erased and rewritten elsewhere. And for every file in this 2, 4 or 8MB block you still need 4 or 5 different entries in the file system!!!
Given that a linux OS has several 10ths of thousands small (and bigger) files you can see how misaligning the filesystem with the card erase blocks can become an issue fast...
There is nothing you can do about random r/w speed and the number of open blocks. Just hope for the best or test (below) so you know.
Regarding the filesystem alignment, the simplest thing is to just change the filesystem of partition 1 of a
card, from vfat to ext2/3, so at least you know is aligned correctly.
So, unmount the card (make sure you do it from the frame if you are in Sugar)
Open a terminal and
mkfs.ext2 -L XOcard /dev/mmcblk0p1
Change “mkfs.ext2“ with “mkfs.ext3“ if you want an ext3 file system and “XOcard” with the name you want to give on your card. (more details on partitioning and formatting below)
and the ugly
But you want more than one partition... Unfortunately manufacturers do not provide random speed, number of open blocks and erase block size info, so you have to find it yourself.
Flashbench is a nice little application that can do this thing for you. Has 2 problems though,
1) is not available as a compiled package for any distro or even as a source package. So you have to “git clone” it and then compile it.
In XOpup is fairly easy, load the xopup_devx_203.sfs and then
git clone git://git.linaro.org/people/arnd/flashbench.git
In Fedora/Sugar, Ubuntu etc you have to yum/apt-get install git and compiling tools (gcc etc) first and issue the same commands.
See PS at the bottom for the compiled application
likely to destroy the data
on your card and
the card will need reformatting
after you are done (but you want to that anyway if you come that far)
There is a little trick to preserve the integrity of the card (not your data)
dd if=/dev/mmcblk0 of=card.img bs=1M count=16
This will make a 16MB image file in your working directory. To restore your card later do the opposite
dd if=card.img of=/dev/mmcblk0 bs=1M count=16
So, after you compiled it, run flashbench (sudo ./flashbench --options) from within the directory according to the instructions of the README file, included in the folder (see
this post from the developer
for more). This will tell you the actual speed of the card and the erase block size, so now we can align our partitions to this erase block size . It is usually 4MB but anything from 1 to 16MB is possible.
Lets assume that you determined a 4MB erase block size from now on. Actually, a good percentage of SDcards have an 4MB erase block size, so you can try this even if you did not verify (with flashbench or otherwise) that your actual card has a 4MB erase block
If your card is still factory formatted run
fdisk -u -l /dev/mmcblk0
#you get something like this
Disk /dev/mmcblk0: 4025 MB, 4025483264 bytes
4 heads, 16 sectors/track, 122848 cylinders, total 7862272 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 7856127 3923968 b W95 FAT32
Write down the start and end sector numbers in case you need them.
There are 2 things to remember with fdisk,
The first sector is sector “0“ not “1“.
Both the start and the end sectors are included in your partition.
Partitioning your card, you want your partitions to start at the beginning of an erase block and to finish at the end of an erase block. With 512b sectors and 4MB erase blocks you want to start at sector: “N* 8192“ and to finish at sector “(N*8192)-1“, where N is a natural number. The size of your partition will be "(Nend-Nstart)*Eraze_block_size" in MB.
If flashbench says that you have a 2MB erase block, the numbers are N*4096, if it is 1MB, N*2048, etc
The second thing is that you want, is to leave at least the first erase block unused or at least 4MB if the erase block of your card is smaller than 4MB. So do not start at (the default) sector “0“.
After you do your homework on paper and you know the start and end sector number for each partition you intent to make, unmount your card (use the frame if you are in Sugar) and type:
fdisk -u /dev/mmcblk0
the -u option is important because gives the data in 512b sectors that our calculations are based on.
You are now out of the prompt and in fdisk.
Type “m” to see the available commands.
You basically need
d delete a partition
l list known partition types
n add a new partition
t change a partition's system id
p print the partition table
q quit without saving changes
w write table to disk and exit
to see what is in the card.
to delete the partitions (one at a time)
Now you are ready to make your own
for the new partition.
Will ask for primary or extended. Pick primary (p)
Now you enter the start and end sector numbers that you calculated on paper
to set the file system ID.
If there is only one partition will default to 1 but from the second on, you have to tell it which partition you are changing the filesystem id for.
Type ‘82“ for linux ext2/3/4, “83“ for swap and “b” for Windows/vfat.
When you finish your partitioning
again and check carefully that the partition table is exactly as you want it.
If not go back and correct it or
to quite fdisk without changing your card.
If you like your partition table type
to write the table in the card and quite.
You are done partitioning.
You now have to make the filesystem for each of your partitions.
This is much easier. Just type
“mkfs.ext2 -L XOcard /dev/mmcblk0p1“ to make an ext2 filesystem
“mkfs.ext3 -L XOcard /dev/mmcblk0p1“ to make an ext3 filesystem
“mkdosfs -n XOcard /dev/mmcblk0p1“ to make a vfat filesystem
"mkswap /dev/mmcblk0p1“ to make a swap filesystem
Change “p1“ with the number of the partition you are making the filesystem on and “XOcard” with the partition label you want
You are done!
Eject and re-insert your card and check that it mounts with all the partitions labeled properly.
Check your swap by issuing “swapon -a /dev/mmcblk0p1“ (or whatever number your swap partition has). Type “free” and verify that swap shows in the list and has the size that you calculated your swap partition to be.
Since I have flashbench for XOpup and Fedora14 OLPC11.2.0 builds, I thought I'll post them and save you the trouble.
Here they are
For Fedora 14:
Get them while they are hot (they do not stay up for long if not downloaded often)
Last Edit: April 18, 2011, 01:03:28 AM by mavrothal
XO-1: Is never going to run Flash, but is certainly flashy!
(If you want Flash, get an XO-1.5 running OLPC 11.2.0 or
Re: SDcard formatting HOWTO
Go linux or go home.
April 17, 2011, 08:05:01 AM
Very informative. Thanks Mavr!
Please select a destination:
OLPC G1G1 Information
=> G1G1 Introduction
===> First Impressions
===> G1G1 Europe
===> XO Shipping - USA
===> XO Shipping - Canada
===> XO Shipping - Problems
=> XO User Groups
===> OLPC Canada
===> OLPC Learning Club DC
===> XO Europe User Group
===> Assistive Technology Group
=> OLPC Publicity
=> XO Laptop Help
===> User Guide
===> Internet & Mesh Networking
===> Sugar & Linux
===> Battery & Power
===> T-Mobile HotSpot
=> XO 1.5 Laptop
=> XO Activities
===> Activities Development
===> Music & Radio
===> Jabber & Chat
=> XO Hacks
===> Hardware Modifications
===> Other Operating Systems
=> XO Accessories
===> USB Memory Sticks & SD Cards
===> USB Adapters & Attachments
=> XO Problemo
===> Hardware Trouble
=> XO MISC
=> Press & Blogs
=> Your Opinion
=> Promoting OLPC to Schools
=> Asus Eee PC
=> Classmate and 2go PC
=> Other 4P Computers
Total Members: 2403
Total Posts: 31943
Total Topics: 3843
Online Today: 18
Online Ever: 238
(April 18, 2011, 09:48:50 PM)
Powered by SMF 1.1.16
SMF © 2011, Simple Machines
| TinyPortal v0.9.8 ©