fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device fdisk -l [-u] [device...] fdisk -s partition... fdisk -v fdisk -h
-b:指定磁盘的山区大小。有效值512、1024、2048、4096 -l:列出指定磁盘的分区表信息 -s:显示分区大小,单位为块
-u:搭配-l,用山区数目取代柱面数目,来表示每个分区的起始地址 -C:指定柱面数 -H:指定磁头数
-S:指定磁盘每磁道的扇区数
子命令
m:显示所有能在fdisk中使用的自命令 p:显示磁盘分区信息 a:设置磁盘启动分区 n:创建新的分区 e:创建扩展分区 p:创建主分区
t:更改分区的系统ID d:删除磁盘分区
q:退出fdisk,不保存磁盘分区设置 l:列出抑制的分区类型 v:验证分区表
w:保存磁盘分区涉资并退出fdisk
[root@centos7 ~]# fdisk /dev/sda
命令(输入 m 获取帮助):m
a toggle a bootable flag——————————切换可引导标志 b edit bsd disklabel————————————编辑BSD磁盘标签 c toggle the dos compatibility flag——————切换DOS兼容性标志 d delete a partition————————————删除分区
g create a new empty GPT partition table———创建一个新的空GPT分区表 G create an IRIX (SGI) partition table—————创建一个IRIX(SGI)分区表 l list known partition types—————————列出已知分区类型 m print this menu————————————打印此菜单 n add a new partition———————————添加新分区
o create a new empty DOS partition table———创建一个新的空dos分区表 p print the partition table—————————打印分区表 q quit without saving changes———————不保存更改退出 s create a new empty Sun disklabel—————创建一个新的标签 t change a partition's system id———————更改系统的分区ID u change display/entry units————————更改显示/输入单元 v verify the partition table—————————验证分区表
w write table to disk and exit————————将表写入磁盘并退出 x extra functionality (experts only)——————额外功能(仅专家)
命令(输入 m 获取帮助):p
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区 Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos
磁盘标识符:0x000eed68
设备 Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
创建和删除主分区
Command (m for help): n Command action
e extended——————————创建扩展分区 p primary partition (1-4)—————创建主分区
. . . . . . . . . . . . . . . . . .
parted——分区维护程序
parted [options] [device [command [options...]...]]
-s:从不提示用户 -i:在必要时提示用户 -l:显示所有磁盘分区表
查看分区信息
[root@centos7 ~]# parted /dev/sda print -s Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:
Number Start End Size Type File system 标志 1 1049kB 525MB 524MB primary xfs 启动 2 525MB 21.5GB 20.9GB primary lvm 创建主分区
[root@centos7 ~]# parted /dev/sda mkpart primary 2G 5G //从2G开始,5G结束 删除主分区
[root@centos7 ~]# parted /dev/sda rm 4 //删除分区号码为4的分区
创建扩展分区
[root@centos7 ~]# parted /dev/sda mkpart extended 2G 5G //从2G开始,5G结束 创建逻辑驱动器
[root@centos7 ~]# parted /dev/sda mkpart logical 2G 5G //从2G开始,5G结束 对分区指定分区类型
[root@server ~]# parted /dev/sda mkfs
WARNING: you are attempting to use parted to operate on (mkfs) a file system. parted's file system manipulation code is not as robust as what you'll find in dedicated, file-system-specific packages like e2fsprogs. We recommend you use parted only to manipulate partition tables, whenever possible. Support for performing most operations on most types of file systems will be removed in an upcoming release.
Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue? Yes/No? yes Partition number? 2 File system type? [ext2]? ext2
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@server ~]# parted /dev/sda print -s Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B Partition Table: msdos
Number Start End Size Type File system Flags 1 1049kB 525MB 524MB primary ext4 boot 2 525MB 21.5GB 20.9GB primary ext2 lvm
cfdisk——基于磁盘分区操作
cfdisk [-agvz] [-c cylinders] [-h heads] [-s sectors-per-track] [-P opt] [device]
-l:列出设备的分区
-a:使用箭头光标,而不是以反白表示 -f:强制执行
-q:抑制警告信息
-T:显示识别的类型(系统id)
-P:在指定格式中显示分区表。选择可以是一个或多个r、s或t,r显示整个分区表的详细信息,s依照磁区的顺序显示相关信息,t以磁头、磁区、柱面的方式来显示信息 -z:开始归零分区表。当重新分区整个磁盘此选项很有用
-g:不使用磁盘驱动器给出的几何形状,而尝试从分区表中猜测一个几何形状 -s:指定磁盘分区数目 -c:指定柱面数目 -h:指定磁头数目
对磁盘进行分区
[root@centos7 ~]# cfdisk /dev/sda
cfdisk (util-linux 2.23.2)
磁盘驱动器:/dev/sda
大小:21474836480 字节,21.4 GB
磁头数:255 每磁道扇区数:63 柱面数:2610
名称 标志 分区类型 文件系统 [标签] 大小 (MB) --------------------------------------------------------------------------------------------------------------------------------------------------------------------- 主/逻辑 剩余空间 1.05
* sda1 启动 *
sda2 20949.50 *
[ 帮助 ] [ 新建 ] [ 打印 ]
使用箭头光标,而不是以反白表示对磁盘/dev/sda进行分区[root@centos7 ~]# cfdisk -a 指定磁盘分区数目进行磁盘分区
[root@centos7 ~]# cfdisk -s 2
主分区 xfs 退出 ] [ 单位 ] [ 写入 ] 在剩余空间上创建新分区 主分区 524.29 LVM2_member
[
partx——告诉内核关于磁盘上的分区号码
partx [-a|-d|-s|-u] [-t TYPE] [-n M:N] [-] disk / partx [-a|-d|-s|-u] [-t TYPE] partition [disk]
-d:删除指定分区或所有分区
-a:添加指定分区或读取磁盘,及添加所有分区 -l:列出分区
--type:指定分区类型
--nr
列出磁盘/dev/sda的分区
[root@centos7 ~]# partx /dev/sda
删除分区/dev/sda3
[root@centos7 ~]# partx /dev/sda /dev/sda3
sfdisk——Linux分区表管理
sfdisk [options] device
/
sfdisk -s [partition]
-l:列出设备的分区 -x:列出扩展分区
-T:列出已知的分区类型 -q:取消警告信息 -n:不实际写入磁盘
-O:保存山区将被覆盖到文件 -c:列出或更改分区ID -s:列出分区的大小 -R:使内核重读分区表 -C:设置使用柱面数的数量 -D:使用于DOS的兼容性 -H:设置使用磁头的数量 -S:设置使用扇区的数量
-d:在一个有用的格式只呢个转储设备的分区 -i:柱面数从1开始 -uS:接受以扇区为单位 -uB:接受以块为单位 -uC:接受以柱面为单位 -uM:接受以MB为单位 -N:只更改指定号码的分区 -I(大写i):再次还原这些扇区 -g:列出指定磁盘的几何内核 -f:强制执行
列出磁盘设备/dev/sda的分区
[root@centos7 ~]# sfdisk -l /dev/sda 列出已知的分区类型
[root@centos7 ~]# sfdisk -T /dev/sda 列出磁盘设备/dev/sda的大小
[root@centos7 ~]# sfdisk -s /dev/sda 列出磁盘分区/dev/sda1的大小
[root@centos7 ~]# sfdisk -s /dev/sda1
delpart——在Linux内核中删除分区
delpart device partition
在Linux内核张删除分区/dev/sda4
[root@centos7 ~]# delpart /dev/sda 4
partprobe——告知操作系统分区表更改
partprobe [-d] [-s] [devices...]
-h:显示选项摘要 -d:不更改内核
-s:显示设备和分区的概要信息
告知操作系统分区表更改
[root@centos7 ~]# partprobe
告知操作系统分区表/dev/sda更改
[root@centos7 ~]# partprobe /dev/sda
因篇幅问题不能全部显示,请点此查看更多更全内容