原文链接地址:http://omappedia.org/wiki/Minimal-FS_SD_Configuration
有两种方法格式化sd卡:
一:使用脚本:
1:找到主机上你的SD卡设备名
sudo fdisk -ls
2:以下是脚本源码:链接地址:http://git.openembedded.org/openembedded/tree/contrib/angstrom/omap3-mkcard.sh
#! /bin/sh
# mkcard.sh v0.5
# (c) Copyright 2009 Graeme Gregory <dp@xora.org.uk>
# Licensed under terms of GPLv2
#
# Parts of the procudure base on the work of Denys Dmytriyenko
# http://wiki.omap.com/index.php/MMC_Boot_Format
export LC_ALL=C
if [ $# -ne 1 ]; then
echo "Usage: $0 <drive>"
exit 1;
fi
DRIVE=$1
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | 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
sleep 1
if [ -x `which kpartx` ]; then
kpartx -a ${DRIVE}
fi
# handle various device names.
# note something like fdisk -l /dev/loop0 | egrep -E '^/dev' | cut -d' ' -f1
# won't work due to https://bugzilla.redhat.com/show_bug.cgi?id=649572
PARTITION1=${DRIVE}1
if [ ! -b ${PARTITION1} ]; then
PARTITION1=${DRIVE}p1
fi
DRIVE_NAME=`basename $DRIVE`
DEV_DIR=`dirname $DRIVE`
if [ ! -b ${PARTITION1} ]; then
PARTITION1=$DEV_DIR/mapper/${DRIVE_NAME}p1
fi
PARTITION2=${DRIVE}2
if [ ! -b ${PARTITION2} ]; then
PARTITION2=${DRIVE}p2
fi
if [ ! -b ${PARTITION2} ]; then
PARTITION2=$DEV_DIR/mapper/${DRIVE_NAME}p2
fi
# now make partitions.
if [ -b ${PARTITION1} ]; then
umount ${PARTITION1}
mkfs.vfat -F 32 -n "boot" ${PARTITION1}
else
echo "Cant find boot partition in /dev"
fi
if [ -b ${PARITION2} ]; then
umount ${PARTITION2}
mke2fs -j -L "Angstrom" ${PARTITION2}
else
echo "Cant find rootfs partition in /dev"
fi
3:格式化SD卡分区
sudo ./omap3-mkcard.sh /dev/sd<x>
4:为SD卡分区之后挂载SD分区到主机:
mkdir /tmp/mmc1
mkdir /tmp/mmc2
sudo mount /dev/sdx1 /tmp/mmc1
sudo mount /dev/sdx2 /tmp/mmc2
二 :一步一步命令格式SD卡分区,假如/dev/sdc是我们的设备名:
1:查sd卡分区
sudo fdisk /dev/sdc
Command (m for help): p
Disk /dev/sdc: 1018 MB, 993001472 bytes
...<more>...
2:删除存在的分区:
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Partition number (1-4): 2
3:配置SD卡:
Command (m for help): x
Expert command (m for help): h
Number of heads (1-256, default 30): 255
Expert command (m for help): s
Number of sectors (1-63, default 29): 63
Warning: setting sector offset for DOS compatiblity
Expert command (m for help): c
Number of cylinders (1-1048576, default 2286): <new_cylinders calculated from above>
4:配置SD卡分区:
Expert command (m for help): r
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-123, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-123, default 123): +64M (see note above)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (10-123, default 10):
Using default value 10
Last cylinder or +size or +sizeM or +sizeK (10-123, default 123):
Using default value 123
5: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))
* You have to format 1st partitions with vfat32 filesystem.
Command (m for help): a
Partition number (1-4): 1
6:检查分区表
Command (m for help): p
Disk /dev/sdc: 993 MB, 993001472 bytes
255 heads, 63 sectors/track, 120 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdc1 * 1 9 72261 c W95 FAT32 (LBA)
/dev/sdc2 10 120 891607+ 83 Linux
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.
7:指定分区的文件系统:
# sudo mkfs.vfat -F 32 -n boot /dev/sdc1
# sudo mkfs.ext3 -L rootfs /dev/sdc2
8:挂载分区:
mkdir /tmp/mmc1
mkdir /tmp/mmc2
sudo mount /dev/sdc1 /tmp/mmc1
sudo mount /dev/sdc2 /tmp/mmc2
9:擦除分区第一个扇区信息
sudo dd if=/dev/zero of=/dev/<sdb> bs=1024 count=1