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): ma
:活动分区标记引导分区。
示例:Command (m for help): a
Partition number (1-4): 1d
:删除分区。
示例:Command (m for help): d
Partition number (1-4): 1l
:显示分区类型。
示例:Command (m for help): ln
:新建分区。
示例:Command (m for help): n
Command action
e extended
p primary partition (1-4)p
:显示分区信息。
示例:Command (m for help): pq
:退出不保存。
示例:Command (m for help): qt
:设置分区号。
示例:Command (m for help): t
Partition number (1-4): 1v
:进行分区检查。
示例:Command (m for help): vw
:保存修改。
示例:Command (m for help): wx
:扩展应用,高级功能。
示例: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
非常感谢您读到这里!如果您觉得这篇文章对您有帮助,请不要忘记关注公众号。关注后,您将第一时间获得最新的AI、云计算、运维(Linux、数据库,容器等)技术,以及更多实用的技能干货。
点击页面右上角的“关注”按钮,不错过任何精彩内容!

扫码获取联系方式



文章转载自周同学带您玩AI,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




