欢迎访问linux宝典,请记住本站唯一域名:www.linuxbaodian.com

fdisk命令

来源:原创    更新时间:2018-08-27 16:20:42    作者:管理员    浏览:2423
  • 命令描述
Linux fdisk是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。
  • 命令语法
fdisk [选项] [参数]
  • 命令选项
-b <size> 指定扇区大小(512,1024,2048或4096 B)
-c 关闭DOS兼容模式
-u <size> 以扇区编号取代柱面编号来表示每个分区的起始地址,一般与-l选项联合使用
-C <number> 指定柱面编号
-H <number> 指定磁头编号
-S <number> 指定磁道扇区编号
-l 显示所有分区表
  • 命令参数
设备名
  • 内置功能及变量
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 额外功能(专家级)
  • 命令实例

实例1:显示分区表

[root@linuxbaodian /]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x000267ce
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         124      786432   fd  Linux raid autodetect
Partition 2 does not end on cylinder boundary.
/dev/sda3             124        1045     7396352   83  Linux
Disk /dev/sdb: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x31f57818
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         204      208880   83  Linux
WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdc: 213 MB, 213909504 bytes
255 heads, 63 sectors/track, 26 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
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1          27      208895+  ee  GPT
Partition 1 has different physical/logical beginnings (non-Linux?):
     phys=(0, 0, 1) logical=(0, 0, 2)
Partition 1 has different physical/logical endings:
     phys=(1023, 254, 63) logical=(26, 1, 39)

实例2:创建新分区

[root@linuxbaodian /]# 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<br>The partition table has been altered!<br><br>Calling ioctl() to re-read partition table.<br>Syncing disks.


上一条命令:umount

下一条命令:showmount

笔记分享

表情

共0条分享记录
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

相关内容

最受欢迎

猜你喜欢

最受争议