如何将硬盘分区成GPT格式

简介: MBR分区标准决定了MBR的硬盘,为了支持能使用大于2T硬盘空间,需使用GPT格式进行分区。创建大于2TB的分区,需使用parted工具。

基于GPT格式的磁盘分区



  • MBR分区标准决定了MBR的硬盘,为了支持能使用大于2T硬盘空间,需使用GPT格式进行分区。创建大于2TB的分区,需使用parted工具。


MBR是Master Boot Record的简称,也就是主引导记录,是位于磁盘最前边的一段引 导(Loader)代码,主要用来引导操作系统的加载与启动


特点:

  1. MBR支持最大2TB磁盘,它无法处理大于2TB容量的磁盘
  2. 只支持最多4个主分区。若想要更多分区,需要创建扩展分区,并在其中创建逻辑分区


GPT磁盘是指使用GUID分区表的磁盘,GUID磁盘分区表(GUID Partition Table,缩写:GPT)其含义为“全局唯一标识磁盘分区表”,是一个实体硬盘的分区表的结构布局的标准


特点:

  1. GPT对磁盘大小没有限制
  2. 最多可以创建128个分区


在企业真实环境中,通常一台服务器有多块硬盘,整个硬盘容量为10T,需要基于GTP格式对10T硬盘进行分区,操作步骤如下:


  • 确认是否有parted命令


[root@localhost ~]# which parted
/usr/sbin/parted                   这里安装的有,我们直接使用
[root@localhost ~]#
[root@localhost ~]# yum -y install parted    如果没有,需要安装parted 命令


  • Parted 命令分为两种模式:命令行模式和交互模式。


  • 命令模式:


parted -s   /dev/sdb  mklabel gpt        设置分区类型为gpt格式;
mkfs.ext3  /dev/sdb                    基于Ext3文件系统类型格式化;
mount     /dev/sdb  /data/             挂载/dev/sdb设备至/data/目录。


  • 交互模式:


parted            直接进入
select /dev/sdb       选择/dev/sdb磁盘
mklabel gpt         格式类型为gpt
mkpart primary 0  -1      将整块磁盘分一个分区
print             打印刚分区的磁盘信息
quit              退出
mkfs.ext3  /dev/sdb1      格式化磁盘
moun /dev/sdb1  /data/    挂在


详细操作情况


[root@localhost ~]# parted 
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p          #打印磁盘信息                                                          
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  211MB   210MB   primary  xfs          boot
 2      211MB   751MB   540MB   primary               lvm
 3      751MB   32.2GB  31.5GB  primary  xfs
(parted) select /dev/sdb          #选择空的磁盘                                                 
Using /dev/sdb
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 
Number  Start  End  Size  Type  File system  Flags
(parted) mklabel gpt             #用GPT分区,支持2T以上的硬盘                                 
Warning: The existing disk label on /dev/sdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? yes     输入yes                                                          
(parted) mkpart primary 0 -1     -1 #将整块磁盘分为1个分区  1表示从最开始分区,也可以用百分比表示                                         
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?                                                            
Ignore/Cancel? ignore
(parted) print         #打印刚分好的分区                                                   
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  21.5GB  21.5GB               primary
(parted) quit 


将磁盘分成多个分区


(parted) mkpart primary
File system type?  [ext2]? ext4                         #选择文件系统类型                  
Start? 1024                                                          #分区开始位置     
End? 2048                                                             #分区结束位置    
Error: Partition(s) 1, 2, 3 on /dev/sda have been written, but we have been unable
to inform the kernel of the change, probably because it/they are in use.  As a
result, the old partition(s) will remain in use.  You should reboot now before
making further changes.
Ignore/Cancel? ignore
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name     Flags
 1      1024MB  2048MB  1023MB               primary
(parted) mkpart primary 
File system type?  [ext2]? ext3                                           
Start? 0                                                                  
End? 1023                                                                 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? ignore                                                     
Error: Partition(s) 1, 2, 3 on /dev/sda have been written, but we have been unable
to inform the kernel of the change, probably because it/they are in use.  As a
result, the old partition(s) will remain in use.  You should reboot now before
making further changes.
Ignore/Cancel? ignore                                                     
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name     Flags
 2      17.4kB  1023MB  1023MB               primary
 1      1024MB  2048MB  1023MB               primary
(parted) mkpart exclude 
File system type?  [ext2]? ext3                                           
Start? 2049                                                               
End? 4096
Error: Partition(s) 1, 2, 3 on /dev/sda have been written, but we have been unable
to inform the kernel of the change, probably because it/they are in use.  As a
result, the old partition(s) will remain in use.  You should reboot now before
making further changes.
Ignore/Cancel? ignore                                                     
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name     Flags
 2      17.4kB  1023MB  1023MB               primary
 1      1024MB  2048MB  1023MB               primary
 3      2049MB  4096MB  2047MB               exclude
(parted)


  • 如果创建错误,需要删除错误分区


(parted) select /dev/sdb
Using /dev/sdb
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  21.5GB  21.5GB               primary
(parted) rm 1                                                             
(parted) p 


总结



  • 磁盘格式化、挂载 参考上期文章 linux 磁盘分区管理

     linux磁盘分区管理

相关文章
|
3天前
|
Linux
linux系统如何使用GPT工具进行分区
linux系统如何使用GPT工具进行分区
|
Unix Linux 开发者
MBR 和 GPT 分区| 学习笔记
快速学习 MBR 和 GPT 分区
433 0
MBR 和 GPT 分区| 学习笔记
|
Windows
Windows无法安装,选中的磁盘为GPT分区形式
Windows无法安装,选中的磁盘为GPT分区形式
398 0
|
Windows
Parted 创建 GPT 分区
对于磁盘的分区表 MBR与GPT区别。MBR:MBR分区表(即主引导记录)大家都很熟悉,是过去我们使用windows时常用的。所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区 GPT: GPT(即GUID分区表)。
5535 0