linux下通过命令格式化SD卡

步骤一:

查看系统中是否有

步骤二:

sudo fdisk /dev/sdb
  • 1
  • 2

输入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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

输入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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

其中,需要记住的是他的容量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

建立分区


输入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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

在新建分区时可以根据实际情况设置分区大小,如果不设置,直接进行回车,会使用默认值。

输入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 mkfs.ext3 /dev/sdb2 -L LABEL2

/dev/sdb2后面的参数根据情况进行设定 mkfs.ext3表示将分区格式化成ext3类型



说明:如果在ARM上进行格式化操作,则mkfs.ext3需要为交叉编译

猜你喜欢

转载自blog.csdn.net/houxiaoliwang/article/details/80337085