挂载
查看SD卡挂挂载点:
df -T
# (-h可以查看单位为M的大小)
卸载SD卡:
sudo umount /dev/sdb1 /dev/sdb2
使用fdisk工具删除分区、添加分区:
sudo fdisk /dev/sdb
输入m 帮助:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
输入p查看当前sd卡的分区(partition)信息:
Command (m for help): p
Disk /dev/sdb: 7948 MB, 7948206080 bytes
245 heads, 62 sectors/track, 1021 cylinders, total 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 * 2048 1048576 523264+ c W95 FAT32 (LBA)
/dev/sdb2 1048577 15523839 7237631+ 83 Linux
删除分区
输入d删除(delete)所有sd卡分区。因为有2个分区,需要删除2次
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
建立分区
输入n新建(new)一个分区
输入p选择新建一个主分区
输入1创建分区1
输入分区1的‘First sector’和‘Last sector’
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-15523839, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-15523839, default 15523839):
Using default value 15523839
输入w将建立完成对分区表写入sd卡,并退出
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.
格式化分区
格式化 fat 分区(windows下可见):
sudo mkfs.vfat -F 32 -n boot /dev/sdb1
格式化 ext3 分区:
sudo mkfs.ext3 -L rootfs /dev/sdb2
fat分区存放内核、设备树等。ext3分区存放根文件系统。