fdisk

fdisk [选项] <disk>  改变分区表

fdisk [选项] –l <disk>  列出所有分区表

fdisk –s <partition(分区编号)>  以分区块为单位,给出指定分区的大小

  这是一个创建和维护分区的命令,兼容DOS类型的分区表、BSD或SUN类型的磁盘列表。注意fdisk不支持2T以上的硬盘分区,此时需要使用gdisk。

相关了解:

  磁头数(Heads)表示硬盘有几个磁头,也就是有几面盘片,一个硬盘最多有255个磁头

  柱面数(Cylinders)表示硬盘每面盘片上有几条磁道

  扇区数(Sectors)表示每条磁道上有几个扇区,每条磁道最多有63个扇区

(1).选项

-b <size>  指定扇区大小(512,1024,2048或4096 B)
-c 关闭DOS兼容模式
-u <size> 以扇区编号取代柱面编号来表示每个分区的起始地址,一般与-l选项联合使用
-C <number> 指定柱面编号
-H <number> 指定磁头编号
-S <number> 指定磁道扇区编号

(2).菜单操作说明:

a 设置可引导标记(活动分区/引导分区之间切换)
b 编辑BSD磁盘标签
c 设置DOS操作系统兼容标记(兼容/不兼容之间切换)
d 删除一个分区
l 显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
m 显示帮助信息
n 增加一个新的分区
o 创建一个新的空白的DOS分区表
p 显示磁盘当前的分区表
q 退出fdisk程序,不保存任何修改
s 创建一个新的空白的Sun磁盘标签
t 改变一个分区的系统ID,就是改变分区类型(比如把Linux Swap分区改为Linux分区)
u 改变显示或输入单位
v 验证磁盘分区表
w 将分区表写入磁盘并退出(保存并退出)
x 额外功能(专家级)

(3).扩展

sda和hda的区别

sd代表的是SCSI,SATA接口硬盘
hd代表IDE接口的硬盘
sda和hda最后面的a都代表的是第一块硬盘
sda1和hda1则代表的是该硬盘的第一分区

(4).实例

1).使用-l选项,列出所有分区表

/*盘/dev/sda:107.4G,107374182400字节(B),255个磁头,63个扇区,13054柱面(磁道)
* 1单位=16065柱面(磁道)*512=8225280字节(B)
* 扇区大小(逻辑/物理):512字节(B)/512字节(B)
*输入/输出大小(最小/最佳):512字节(B)/512字节(B)
*磁盘标识:0x00079700
*/
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00079700 /*设备     启动标识  开始位置 结束位置  分区块的大小  分区ID  系统(分区类型) 
* /dev/sda1  *     1     64     512000     83    Linux
* 分区1不以柱面边界结束
* /dev/sda2        64    13055   104344576   8e    Linux LVM
*/
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000 Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
255 heads, 63 sectors/track, 5952 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2).使用-l和-u选项,用扇区编号取代柱面编号显示所有分区表

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 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: 0x00079700 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 1026048 209715199 104344576 8e Linux LVM Disk /dev/sdb: 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: 0x00000000 Disk /dev/mapper/vg_centos6-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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 Disk /dev/mapper/vg_centos6-lv_swap: 4194 MB, 4194304000 bytes
255 heads, 63 sectors/track, 509 cylinders, total 8192000 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 Disk /dev/mapper/vg_centos6-lv_home: 49.0 GB, 48964304896 bytes
255 heads, 63 sectors/track, 5952 cylinders, total 95633408 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

3).你们也看到了,我的/dev/sdb还没有开始使用,下面就用这个硬盘简单的演示下fdisk主要用到的操作菜单

  1.在操作菜单下,创建一个新的分区

[root@CentOS6 桌面]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe8517189.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): n
Command action
e extended            //扩展分区,创建扩展分区会占用一个主分区,并且只有创建扩展分区后才能创建逻辑分区
p primary partition (1-4)   //主分区,最多创建4个
e
Partition number (1-4): 1
First cylinder (1-2610, default 1):   //起始柱面,默认为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):   //终止柱面,默认为最后一个数
Using default value 2610 Command (m for help): n
Command action
l logical (5 or over)    //逻辑分区
p primary partition (1-4)  //主分区
l
First cylinder (1-2610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G  //终止柱面不仅可以用柱面数表示,还可以用+[数值][单位]的格式表示 Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1307-2610, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610):
Using default value 2610 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe8517189 Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux
/dev/sdb6 1307 2610 10474348+ 83 Linux Command (m for help): w      //写入磁盘,保存并退出,否则之前的操作都无效。如果不想写入磁盘就使用q
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

  2.在操作菜单下,删除 一个分区

[root@CentOS6 桌面]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe8517189 Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux
/dev/sdb6 1307 2610 10474348+ 83 Linux Command (m for help): d
Partition number (1-6): 6  //这里输入的始分区编号,如果删除扩展分区,那扩展分区下的逻辑分区也会被删除 Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe8517189 Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 83 Linux Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

  3.在操作菜单下,修改分区类型

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): t
Partition number (1-5): 5  //操作哪一个分区
Hex code (type L to list codes): L  //这里会提示你使用L查看类型列表 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): b
Changed system type of partition 5 to b (W95 FAT32) Command (m for help): p  //可以看到由原来的Linux改成了W95 FAT32 Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe8517189 Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 1306 10490382 b W95 FAT32 Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

4).对正在使用的磁盘,再次进行分区时会出现以下提示

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)

  注意此时分区并不会立刻生效,可以重启系统,也可以使用提示的命令partprobe或kpartx。

  下面展示完整情况内容

[root@xuexi ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。 命令(输入 m 获取帮助):n  //新建分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p  //创建主分区
分区号 (2-4,默认 2):
起始 扇区 (2099200-4194303,默认为 2099200):
将使用默认值 2099200
Last 扇区, +扇区 or +size{K,M,G} (2099200-4194303,默认为 4194303):
将使用默认值 4194303
分区 2 已设置为 Linux 类型,大小设为 1023 MiB 命令(输入 m 获取帮助):w  //写入磁盘
The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@xuexi ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1
[root@xuexi ~]# partprobe /dev/sdb  //通知操作系统分区表已更改
[root@xuexi ~]# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2

  注意:能reboot重启最好重启,不行再使用命令更新

  注意:其实partprobe是更新分区表,但kpartx其实是更新分区映射(涉及到了镜像文件,例如.img文件),不过还有partx可以用来更新分区表(-a选项新增,-d选项删除,-u选项更新(好像不能在删除时使用))。

Linux命令之fdisk的更多相关文章

  1. Linux命令学习—— fdisk -l 查看硬盘及分区信息

    Linux命令学习(3)-- fdisk -l 查看硬盘及分区信息注意:在使用fdisk命令时要加上sudo命令,否则什么也不能输出linux fdisk 命令和df区别是什么? fdisk工具是分区 ...

  2. Linux命令(二十五) 磁盘管理命令(三) fdisk

    一.fdisk命令介绍 fdisk 为Linux系统下的分区管理工具,类型windows下的 分区助手等工具软件.分过区装过操作系统的人都知道硬盘分区是必要和重要的.fdisk 的帮助如下所示: [r ...

  3. Linux文件系统管理 fdisk分区命令

    概述 我们在安装操作系统的过程中已经对系统硬盘进行了分区,但是如果我新添加了一块硬盘,想要正常使用时,在Linux中有专门的分区命令 fdisk 和 parted.其中 fdisk 命令较为常用,但不 ...

  4. 【Linux命令】磁盘分区,格式化,挂载命令,创建交换分区(fdisk,mkfs,mount,umount)

    友情链接 磁盘分区,格式化,挂载,创建交换分区:https://www.cnblogs.com/HeiDi-BoKe/p/11936998.html RAID工作级别:https://www.cnbl ...

  5. Linux常用命令:fdisk mkfs mount umount fstab实现自动挂载

    写在前 记录点常用命令,fdisk mkfs mount和umount,以及fstab实现自动挂载 fdisk fdisk主要用于操作硬盘的分区表.分区,下面简单记一点最常用的部分 查看当前系统识别到 ...

  6. Linux磁盘分区fdisk命令操作(简洁版)

    实例(环境为: CentOS Linux release 7.2.1511 (Core), 3.10.0-327.el7.x86_64) 选择要具体操作的第二块磁盘(linux下一切是文件形式对应): ...

  7. 学习 Linux,101: Linux 命令行

    概述 本教程将简要介绍 bash shell 的一些主要特性,涵盖以下主题: 使用命令行与 shell 和命令交互 使用有效的命令和命令序列 定义.修改.引用和导出环境变量 访问命令历史和编辑工具 调 ...

  8. Linux命令整理中...

    Linux命令整理中... 最常用命令(我最近最常用的一般放在前面tipsbychsry) clear 清屏 date 显示日期 cal 显示日历 cal 2014 显示2014年的日历 shutdo ...

  9. LINUX命令总结 -------来自 水滴娃娃 的CSDN

    LINUX命令总结 标签: LINUX命令总结 2014-01-27 15:54 41039人阅读 评论(1) 收藏 举报  分类: linux(1)  版权声明:本文为博主原创文章,未经博主允许不得 ...

随机推荐

  1. [bzoj5285] [HNOI2018]寻宝游戏

    Description 某大学每年都会有一次Mystery Hunt的活动,玩家需要根据设置的线索解谜,找到宝藏的位置,前一年获胜的队伍可以获得这一年出题的机会. 作为新生的你,对这个活动非常感兴趣. ...

  2. [Leetcode] subsets ii 求数组所有的子集

    Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...

  3. git clone 出错 fatal: pack has bad object at offset 26060927: inflate returned -3

    $ git clone http://xxx.xxx.cn/liyafei/developer.gitCloning into 'developer'...remote: Counting objec ...

  4. Any gotchas at all with converting from MyISAM to InnoDB?

    Q: I'm ready to move from MyISAM to InnoDB but wanted to know if there was a full list of things to ...

  5. C ------ 标准函数介绍

    sprintf() 函数原型:int sprintf( char *buffer, const char *format [, argument] ... ); 功能介绍: 1.把一个字符串赋值(拷贝 ...

  6. BS架构下使用消息队列的工作流程

    异步通信 对于BS(Browser-Server 浏览器)架构,很多情景下server的处理时间较长. 如果浏览器发送请求后,保持跟server的连接,等待server响应,那么一方面会对用户的体验有 ...

  7. AWS nat monitor and route switch script

    This script will monitor another NAT instance and take over its routes if communication with the oth ...

  8. 转:Spring AOP详解

    转:Spring AOP详解 一.前言 在以前的项目中,很少去关注spring aop的具体实现与理论,只是简单了解了一下什么是aop具体怎么用,看到了一篇博文写得还不错,就转载来学习一下,博文地址: ...

  9. SpringMVC——helloword入门

    参考 http://www.cnblogs.com/bigdataZJ/p/springmvc1.html 文章主要讲述以下内容: 搭建环境 静态请求拦截 动态请求拦截 补充: 1.Controlle ...

  10. 解决cursor未关闭造成的死锁

    参考:https://blog.csdn.net/zc474235918/article/details/72731363/ https://blog.csdn.net/zmx729618/artic ...