Skip to content

服务器如何对大于2T硬盘分区-GPT分区表格式

作者: ryan 发布于: 2/14/2020 更新于: 8/24/2025 字数: 0 字 阅读: 0 分钟

在Linux系统中对大于2TB的硬盘分区时,必须使用GPT分区表格式parted工具(替代传统的fdisk),因为MBR分区表(由fdisk支持)最大仅支持2TB磁盘空间。

GPT支持最大18EB空间(约18百万TB),远超MBR的2TB限制

一. 查看硬盘信息

由于新添加硬盘时要确定是对哪个盘进行分区挂载,以免误操作而造成数据损失。 使用 fdisk -l 进行查看。

bash
Disk /dev/vdd: 10 TiB, 10995116277760 bytes, 21474836480 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

从图中可以看出即将进行分区挂载的新硬盘大约是7.3T的可用空间,磁盘位置为/dev/sdb 由于磁盘的空间大于2T,所以不能用直接使用fdisk的方法进行分区,在这里我们使用GPT分区。

二. 建立磁盘标签

选择要分区的硬盘:parted /dev/vdd

bash
[root@OpenEuler2203 dataserver2]# parted /dev/vdd
GNU Parted 3.5
Using /dev/vdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/vdd: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
create the GPT disklabel in other words, create the partitioning tables to support GPT:

建立GPT的磁盘标签,换句话说就是创建磁盘分区表支持GPT

使用(parted) mklabel gpt
bash
[root@OpenEuler2203 dataserver2]# parted /dev/vdd
GNU Parted 3.5
Using /dev/vdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: /dev/vdd: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) mkpart primary ext4
Start?
Start? 0
End? 100%
Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s
Ignore/Cancel? cancel
(parted) exit
  align-check TYPE N                       check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all]            display the partition table, or available devices, or free space, or all found partitions
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) quit
Information: You may need to update /etc/fstab.

[root@OpenEuler2203 dataserver2]#
[root@OpenEuler2203 dataserver2]# parted /dev/vdd
GNU Parted 3.5
Using /dev/vdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/vdd will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart primary ext4
Start? 2048s
End? 100%
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  11.0TB  11.0TB  ext4         primary

(parted) quit
Information: You may need to update /etc/fstab.

[root@OpenEuler2203 dataserver2]# mkfs.ext4 /dev/vdd1
mke2fs 1.46.4 (18-Aug-2021)
Discarding device blocks: done
Creating filesystem with 2684354048 4k blocks and 335544320 inodes
Filesystem UUID: 62aa557e-b5de-4723-9093-a361723b6f49
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
        2560000000

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

添加开机自动挂载

确定文件系统类型

这里的 TYPE 字段就是文件系统类型,例如 ext4

bash
[root@OpenEuler2203 202412]# sudo blkid /dev/vdd1
/dev/vdd1: UUID="62aa557e-b5de-4723-9093-a361723b6f49" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="31ee174c-b47d-445a-b57d-0c0a000a9ebb"

编辑 /etc/fstab 文件

使用文本编辑器(如 vinano)打开 /etc/fstab 文件:

bash
sudo vi /etc/fstab
# 在末尾添加:
UUID=62aa557e-b5de-4723-9093-a361723b6f49 /www/wwwroot/cloud_ceamg_com/data/dataserver2/emby-data2/ ext4 defaults 0 0
  • 参数解释

  • 第一列:设备名,这里是 /dev/vdd1

  • 第二列:挂载点,即 /www/wwwroot/cloud_ceamg_com/data/dataserver2/emby-data2/

  • 第三列:文件系统类型,根据 blkid 命令的输出填写,如 ext4

  • 第四列:挂载选项,defaults 表示使用默认选项。

  • 第五列:是否使用 dump 备份,0 表示不备份。

  • 第六列:是否在开机时使用 fsck 检查磁盘,0 表示不检查。

检查配置正确性

bash
sudo mount -a

验证挂载结果

bash
df -h | grep /dev/vdd1

Updated at: