Linux fdisk命令操作磁盘(添加、删除、转换分区等)

创建分区
1->查看原始分区
sudo fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x000a424d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 39847934 41940991 1046529 5 Extended
/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

Disk /dev/sdb: 31.0 GB, 30953963520 bytes
64 heads, 32 sectors/track, 29520 cylinders, total 60456960 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: 0x000ababa

Device Boot Start End Blocks Id System

2->创建Partition
sudo fdisk /dev/sdb

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)

->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-60456959, default 2048): (分区起始位置,一般直接回车)
Using default value 2048
->Last sector, +sectors or +size{K,M,G} (2048-60456959, default 60456959): +5G (分区大小)

->Command (m for help): w (保存设置)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3->format partition
sudo mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.12 (29 Oct 2011)



4->分区结果
sudo fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x000a424d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 39847934 41940991 1046529 5 Extended
/dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris

Disk /dev/sdb: 31.0 GB, 30953963520 bytes
64 heads, 32 sectors/track, 29520 cylinders, total 60456960 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: 0x000ababa

Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux

fdisk -l /dev/mmcblk0 | grep "^/dev" | wc -l

猜你喜欢

转载自www.cnblogs.com/Malphite/p/9138746.html