1. fdisk
命令概述
fdisk
是一个用于创建和维护分区表的程序,兼容DOS、BSD和SUN类型的分区表。fdisk
命令可以列出磁盘分区信息,创建新分区,删除分区等。
2. fdisk
语法
fdisk [必要参数] [选择参数]
3. 参数说明
必要参数
-l
:列出所有分区表。
示例:fdisk -l
-u
:与-l
搭配使用,显示分区数目。
示例:fdisk -lu
选择参数
-s <分区编号>
:指定分区。
示例:fdisk -s /dev/sda1
-v
:显示版本信息。
示例:fdisk -v
4. 菜单操作说明
在使用 fdisk
进入交互模式后,可以使用以下命令进行分区管理:
m
:显示菜单和帮助信息。
示例:Command (m for help): m
a
:活动分区标记引导分区。
示例:Command (m for help): a Partition number (1-4): 1
d
:删除分区。
示例:Command (m for help): d Partition number (1-4): 1
l
:显示分区类型。
示例:Command (m for help): l
n
:新建分区。
示例:Command (m for help): n Command action e extended p primary partition (1-4)
p
:显示分区信息。
示例:Command (m for help): p
q
:退出不保存。
示例:Command (m for help): q
t
:设置分区号。
示例:Command (m for help): t Partition number (1-4): 1
v
:进行分区检查。
示例:Command (m for help): v
w
:保存修改。
示例:Command (m for help): w
x
:扩展应用,高级功能。
示例:Command (m for help): x
5. 使用举例
例1:显示当前分区情况
fdisk -l
Disk /dev/sda: 100 GB, 107374182400 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
例2:显示SCSI硬盘的每个分区情况
fdisk -lu
Disk /dev/sda: 100 GB, 107374182400 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 63 208844 104391 83 Linux
/dev/sda2 208845 20964824 10377990 8e Linux LVM
例3:扩展分区大小为50G
进入 fdisk
交互模式:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (2048-209715199, default 2048): 20964825
Last sector, +sectors or +size{K,M,G,T,P} (20964825-209715199, default 209715199): +50G
Command (m for help): p
Disk /dev/sda: 100 GB, 107374182400 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 63 208844 104391 83 Linux
/dev/sda2 208845 20964824 10377990 8e Linux LVM
/dev/sda3 20964825 31464824 10500000 83 Linux
然后保存并退出:
Command (m for help): w
例4:减少分区大小为50G
减少 /dev/sda3
的大小:
首先备份数据,然后删除分区并重新创建。
Command (m for help): d
Partition number (1-4): 3
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (2048-209715199, default 2048): 20964825
Last sector, +sectors or +size{K,M,G,T,P} (20964825-209715199, default 209715199): +50G
Command (m for help): p
Disk /dev/sda: 100 GB, 107374182400 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 63 208844 104391 83 Linux
/dev/sda2 208845 20964824 10377990 8e Linux LVM
/dev/sda3 20964825 31464824 10500000 83 Linux
然后保存并退出:
Command (m for help): w
本文由mdnice多平台发布
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。