当前位置: > Linux教程 > Linux学习 >

fdisk和parted的区别

时间:2019-04-02 17:32来源:linux.it.net.cn 作者:IT
Linux系统中有两个分区工具
 
fdisk
parted
二者都可以对linux的硬盘进行分区,但是二者从细节上来说,又有很大的区别,如果不加注意,有可能造成磁盘空间的浪费。
 
首先我们来介绍一下磁盘,Linux系统中,每个磁盘中有一部分叫做MBR主引导记录。
 
**
 
MBR
**
 
大小512字节,分为三部分
主引导程序:446字节
硬盘分区表:64字节
分区结束标记(硬盘有效位):2字节
 

 
 
其中硬盘分区表DPT需要特别注意
 
DPT的大小是64字节,每个主分区要占用16字节,扩展分区也要占用16个字节的主分区空间,所以每个磁盘上最多只能建立四个主分区
 
 
那么如果需要将磁盘分成5个或者更多个分区的话,可以采取的方法:
 
创建一到三个主分区,将剩下的空间作为扩展分区,由扩展分区分出多个逻辑分区
不创建主分区,全做磁盘作为扩展分区,由扩展分区分出来多个逻辑分区
接下来就是如何使用fdisk和parted进行分区
单纯的使用这两个工具去进行硬盘分区倒没什么难点,两者都是交互式的界面,如果忘记如何分区,可以进入交互之后使用h或者help查看帮助。
 
但是在使用二者进行分区的时候,就需要注意一些区别:
1、fdisk
(1)fdisk命令只支持msdos,分区的时候只支持小容量硬盘(<=2T),但是如果不需要分区的话,那么整块sdb硬盘,类型为msdos,那么他的大小是可以大于2T的。
(2)fdisk命令不支持gpt,所以当使用fdisk命令给gpt类型硬盘分区是会出现告警,就像下面例子中的WARNING
 
[root@centos6 ~]# fdisk /dev/sdc
 
WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util fdisk doesn't support GPT. Use GNU Parted.
 
 
WARNING: The size of this disk is 5.4 TB (5368709120000 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).
 
 
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): 
 

 
(3)当使用parted命令给一个5T的硬盘分好三个分区之后,在使用fdisk命令查看,会不兼容(parted打印的分区有三个,而fdisk命令打印的分区只有一个)
 
[root@centos6 ~]# parted /dev/sdc print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 5369GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start  End  Size  File system  Name  Flags
 
[root@centos6 ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart a 1 100G
(parted) mkpart b 100G 500G                                               
(parted) mkpart c 500G 2000G
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 5369GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  100GB   100GB   ext4         a
 2      100GB   500GB   400GB                b
 3      500GB   2000GB  1500GB               c
 
(parted) quit                                                             
Information: You may need to update /etc/fstab.                           
 
[root@centos6 ~]# fdisk -l /dev/sdc
 
WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util fdisk doesn't support GPT. Use GNU Parted.
 
 
Disk /dev/sdc: 5368.7 GB, 5368709120000 bytes
255 heads, 63 sectors/track, 652708 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      267350  2147483647+  ee  GPT
[root@centos6 ~]# 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2、parted:
(1)支持msdos和gpt,可以支持大硬盘,也支持小硬盘。
(2)区分parted命令给msdos类型和gpt类型硬盘分区的不同:
①下面是parted给msdos类型硬盘分区:
 
[root@centos6 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print        
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number  Start  End  Size  Type  File system  Flags
 
(parted) mkpart aaa 1 10G          使用mkpart添加分区
parted: invalid token: aaa         显示无效的输入
Partition type?  primary/extended? primary            这里要求选择分区类型(主分区/扩展分区?)先创建一个主分区                    
File system type?  [ext2]? ext4                 这里提醒确定文件系统的类型,输入ext4                          
Start? 1                                        分区的开始:1                         
End? 10G                                        分区结束:10G那么就确定了分区是一个10G大小的分区                         
(parted) print                                  print打印分区表                          
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
 
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  10.0GB  9999MB  primary
                                                       这里可以看到一个大小为10G,类型为主分区的文件系统已经创建完成                                  
(parted) 
 
②下面是parted给gpt类型硬盘分区:
 
[root@centos6 ~]# parted /dev/sdc print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 5369GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start  End  Size  File system  Name  Flags
 
[root@centos6 ~]# parted /dev/sdc
GNU Parted 2.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart a 1 100G
(parted) mkpart b 100G 500G                                               
(parted) mkpart c 500G 2000G
(parted) print                                                            
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 5369GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
 
Number  Start   End     Size    File system  Name  Flags
 1      1049kB  100GB   100GB   ext4         a
 2      100GB   500GB   400GB                b
 3      500GB   2000GB  1500GB               c
 
(parted)
 
3、msdos
支持小于2T的硬盘,不支持大于2T的硬盘
有主分区,扩展分区,逻辑分区
如果使用fdisk命令给一个大于2T的msdos类型硬盘分区,只能给2T的部分分区,超过2T的部分不能使用,也就浪费了。

 
4、gpt
支持大小容量的硬盘
不区分主分区,扩展分区,逻辑分区,也没有4个分区数量的限制
 


 


(责任编辑:IT)
------分隔线----------------------------