如何在Linux上格式化并创建分区

在开发的时候经常会遇到系统使用 /dev/block/mmcblk0p1 而不是 /dev/block/mmcblk0

表现出来的现象是:

/dev/mmcblk0p1: No such file or directory
 

一般SD卡默认都是只有/dev/block/mmcblk0, 因此需要格式化并创建一个分区,

这里使用的是Ubuntu自带的fdisk工具, 方法如下:

1. 先删除所有分区:
#sudo fdisk /dev/sdb
#d
#1
#d
#2
根据提示删除所有的分区。

2. 新创建一个分区:
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-7744511, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-7744511, default 7744511):
Using default value 7744511

3. 保存改动并退出:
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 22: Invalid argument.
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)
Syncing disks.


4. 查看分区是否创建成功

Command (m for help): p

Disk /dev/sdb: 3965 MB, 3965190144 bytes
106 heads, 30 sectors/track, 2435 cylinders, total 7744512 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     7744511     3871232   83  Linux

4. 重新插拔

5. 格式化为fat32
#sudo mkfs.vfat -I /dev/sdb1
mkfs.fat 3.0.26 (2014-03-07)

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值