Formatting SD Card on Ubuntu

This is a post just to remind me about the steps needed to format an SD Card on Ubuntu 9.10. I just got a class 4 8GB Kingston SD Card to replace the 1GB Stock SD Card on my G1. Since I’m using a rooted ROM (this one to be precise), I need an ext+fat+swap partition setup on my SD Card. I needed to format the new card identical to the old one and copy the old data onto the new card.

First of all, Ubuntu has a very weird delayed write mechanism that writes data to plugged in devices only when you eject or unmount them. So, if you write something to the card and pull it out, there’s a very good chance that it doesn’t show up. I haven’t seen this anywhere before, especially when using gentoo earlier.

GParted doesn’t display my card which is /dev/sdb. (Update in comments below) So, I decide to use the command line for this. There are three command line utilities for formatting, i.e. fdisk, cfdisk, sfdisk.

cfdisk gives you a UI so that you can select everything using arrow keys. But for some reason, when creating the partitions, it kept creating them as /dev/sdb1p1, /dev/sdb1p2 and /dev/sdb1p3 instead of /dev/sdb1, /dev/sdb2, /dev/sdb3. This kept the disk from showing up when listing the partition table with sudo fdisk -l. Didn’t really investigate why it was doing that. Checked out sfdisk, but the commands are different and looked like I’d need to learn a bit more before I could use it.

So, finally came down to fdisk which is quite handy once you get used to it. Important commands are ‘m’ which displays all the commands and ‘p’ which prints the partition table. So, first created the partitions using ‘n’ and setting them up as 7.4GB win95 fat32 (code ‘b’), 500MB ext3 (code ’83’), remaining 30+MB swap (code ’82’). The file system type can be set using ‘t’ and the codes obtained using ‘L’. The partition table is written using ‘w’.

Now, we need to format the different partitions with the corresponding file systems. This is done as follows:

  • Fat32: sudo mkfs.vfat /dev/sdb1
  • Ext3: sudo mke2fs -j /dev/sdb2 (the -j is required for ext3. Omit it for ext2)
  • Swap: sudo mkswap /dev/sdb3

Once this is done, you should immediately be able to see the different partitions in Nautilus.

Advertisements

5 thoughts on “Formatting SD Card on Ubuntu

  1. GParted doesn’t display my card which is /dev/sdb.

    Are you absolutely certain?

    I thought for a while that GParted wasn’t recognizing certain drives until I realized that top-right display of the drive is a drop-down menu you can use to select other drives.

  2. Sorry for the late reply. Funny, GParted didn’t work when I tried it initially and it didn’t show anything in the drop down as well. But after your comment, I tried it again and now it seems to be working. Perhaps when I tried it earlier, I might’ve unmounted the card. Thanks for pointing it out!

  3. “Formatting SD Card on Ubuntu | Emptiness in void”
    ended up being a excellent posting. If perhaps it possessed a lot
    more pictures it would definitely be quite possibly better.
    Take care ,Maude

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s