表现:
1、插入SD卡时提示mmcblk0: unknown partition table
2、dev下只有mmcblk0,没有mmcblk0p1
3、偶尔识别了,并挂载了,ls查看会提示如图所示错误
解决办法:采用fdisk格式化SD卡,创建分区
在PC上,sudo fdisk -l看SD卡对应的分区,比如8G的卡会显示,对应的即为sdb
执行
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
其中,需要记住的是他的容量7948206080 bytes
之后会用到。
同时也留意他的heads和setcors/track
删除分区
输入d
删除(delete)所有sd卡分区。因为有2个分区,需要删除2次
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
建立扇区
如果SD卡不是255 heads, 63 sectors/track
,按照以下步骤建立扇区
输入x
进入扩展命令列表
Command (m for help): x
Expert command (m for help):
输入m
显示扩展命令列表
Command action
b move beginning of data in a partition
c change number of cylinders
d print the raw data in the partition table
e list extended partitions
f fix partition order
g create an IRIX (SGI) partition table
h change number of heads
i change the disk identifier
m print this menu
p print the partition table
q quit without saving changes
r return to main menu
s change number of sectors/track
v verify the partition table
w write table to disk and exit
输入h
设置heads = 255
Expert command (m for help): h
Number of heads (1-256, default 245): 255
输入s
设置sectors/track = 63
Expert command (m for help): s
Number of sectors (1-63, default 62): 63
输入c
设置cylinder = 966
Expert command (m for help): c
Number of cylinders (1-1048576, default 1021): 966
cylinder计算方法
cylinder = SD卡容量(bytes) / heads / sectors / 512(bytes)
cylinder = 7948206080 / 255 /63 / 512 = 966.3 = 966
输入r
返回(return)普通命令
Expert command (m for help): r
Command (m for help):
输入p
再次查看当前sd卡的分区信息。
此时你会看到heads, sectors/track, cylinder都已经更新了
Command (m for help): p
Disk /dev/sdb: 7948 MB, 7948206080 bytes
255 heads, 63 sectors/track, 966 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
建立分区
输入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
输入t
改变分区系统ID,
一般windows的用,则输入分区类型码c
FAT32,
而linux的为默认的分区类型码83
EXT3
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))
输入a
激活分区的bootable标志
Command (m for help): a
Partition number (1-4): 1
输入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.
格式化分区
重新运行sudo fdisk -l
会发现对应的是sdb1,进行格式化操作:
sudo mkfs.vfat /dev/sdb1
至此,SD卡又可以重新正常被使用了~