您的位置:首页 > 运维架构 > Linux

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

2015-12-29 16:07 477 查看
在开发的时候经常会遇到系统使用 /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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: