ECE597 Notes on Using an 8G SD Card

From eLinux.org
Jump to: navigation, search

I'm retiring this page.

Here's what I did to format an 8G SD card with a boot partition and a 2G ext3 partition and a 5G FAT partition for holding a virtual machine.

First, use 255 heads and 63 sectors.

host $ sudo fdisk /dev/sdb
Command (m for help): o
Building a new DOS disklabel with disk identifier 0xa3e2c074.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.


The number of cylinders for this disk is set to 3521.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 7969 MB, 7969177600 bytes
221 heads, 20 sectors/track, 3521 cylinders
Units = cylinders of 4420 * 512 = 2263040 bytes
Disk identifier: 0xa3e2c074

   Device Boot      Start         End      Blocks   Id  System
Command (m for help): x

Expert command (m for help): h
Number of heads (1-256, default 221): 255

Expert command (m for help): s
Number of sectors (1-63, default 20): 63
Warning: setting sector offset for DOS compatibility

NOTE: Be especially careful in the next step. First calculate the number of cylinders as follows:

B = Card size in bytes (you got it before, in the second step when you printed the info out)

C = Number of cylinders

C=B/255/63/512

Round down to the nearest integer.

Expert command (m for help): c
Number of cylinders (1-1048576, default 3521): 968

Expert command (m for help): r

Next set up the 3 partitions. The first is the boot partition and is 50 cylinders.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-968, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-968, default 968): +50

Set it's type to FAT32 and make it bootable.

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): c
Changed system type of partition 1 to c (W95 FAT32 (LBA))

Command (m for help): a
Partition number (1-4): 1

Now, the second partition is 2G and will be formatted ext3 (the default).

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (52-968, default 52): 
Using default value 52
Last cylinder, +cylinders or +size{K,M,G} (52-968, default 968): +2G  

Then do the third partition. It gets the rest of the card and is formatted FAT32.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (314-968, default 314): 
Using default value 314
Last cylinder, +cylinders or +size{K,M,G} (314-968, default 968): 
Using default value 968

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))

Let's see what we have so far.

Command (m for help): p

Disk /dev/sdb: 7969 MB, 7969177600 bytes
255 heads, 63 sectors/track, 968 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa3e2c074

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          51      409626    c  W95 FAT32 (LBA)
/dev/sdb2              52         313     2104515   83  Linux
/dev/sdb3             314         968     5261287+   c  W95 FAT32 (LBA)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

At this point I unplugged that card and plugged it in again. This will make Linux find the new partitions.

Now let's format the partitions.

host $ sudo mkfs.msdos -F 32 /dev/sdb1 -n boot
mkfs.msdos 3.0.3 (18 May 2009)
host $ sudo mkfs.msdos -F 32 /dev/sdb3 -n vm
mkfs.msdos 3.0.3 (18 May 2009)
host $ sudo mkfs.ext3 /dev/sdb2 -L rootfs
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=rootfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
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 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Unplug and replug and you should see all three partitions.