转换MBR分区为GPT分区

重要

本文中含有需要您注意的重要提示信息,忽略该信息可能对您的业务造成影响,请务必仔细阅读。

MBR分区格式不支持2 TiB以上的云盘。如果您的云盘目前使用的是MBR分区类型,且希望将其扩容至2 TiB以上,需要先将分区类型从MBR转换为GPT,再扩容分区及文件系统。

准备工作

操作步骤

  1. (可选)为云盘创建快照,做好数据备份。

    说明

    转换过程中通常不会丢失数据,但建议提前备份以防误操作。

  2. 连接RDS Custom实例

  3. 执行以下命令,安装gdisk工具。

    • Alibaba Cloud Linux 2/3版本、CentOS 7及以上版本运行以下命令。

      type sgdisk || sudo yum install -y gdisk
    • Debian 11及以上版本、Ubuntu14及以上版本运行以下命令。

      type sgdisk || sudo apt-get install -y gdisk
  4. 执行以下命令,将MBR分区转换为GPT分区。

    警告

    sgdisk只能对云盘(例如/dev/nvme2n1)进行操作,不能对分区(例如/dev/nvme2n1p1)进行操作,否则可能会损坏文件系统。

    以云盘名称/dev/nvme2n1为例,请根据实际情况替换云盘名称。

    sudo sgdisk -g /dev/nvme2n1

    其中,-g表示将MBR转换为GPT并保留原有MBR备份。

    当出现successfully字段时,表示转换成功。

    说明

    如果运行sgdisk命令出现报错提示,请参见常见问题进行解决。

  5. 执行以下命令,查看分区转换结果。

    以云盘名称/dev/nvme2n1为例,请根据实际情况替换云盘名称。

    sudo fdisk -lu /dev/nvme2n1

    Disklabel type值为gpt时,表示已转换为GPT分区,分区转换成功。

后续操作

扩容分区和文件系统

常见问题

  1. 问题:运行转换分区sgdisk -g命令时,提示如下信息。

    Warning! Secondary partition table overlaps the last partition by 33 blocks!
    You will need to delete this partition or resize it in another utility.

    原因:云盘尾部剩余空间不足33个扇区,没有足够的空间用于MBR转换为GPT。

    解决方案:先扩容云盘容量后,再转换分区格式。

  2. 问题:运行转换分区sgdisk -g命令时,提示如下信息。

    Warning! Main partition table overlaps the first partition by 24 blocks! 
    Try reducing the partition table size by 96 entries.
    (Use the 's' item on the experts' menu.)
    Warning! Main partition table overlaps the first partition by 24 blocks! 
    Try reducing the partition table size by 96 entries.
    (Use the 's' item on the experts' menu.)
    Aborting write of new partition table.

    原因:云盘头部剩余空间不足以容纳GPT分区表所需的头部信息。这通常是因为数据或分区位于磁盘的非常靠前位置,没有足够的空间来放置GPT的分区表结构。这种情况下,是不支持转换分区的。

    解决方案

    1. 为云盘创建快照

    2. 创建新云盘挂载到RDS Custom实例

    3. 通过rsync相关命令,将旧云盘的数据拷贝至新云盘。

    4. 卸载释放旧云盘。

  3. 问题:运行转换分区type sgdisk || sudo yum install -y gdisk命令时,提示如下信息。

    Error downloading packages:
      gdisk-0.8.10-3.1.al7.x86_64: Insufficient space in download directory /var/cache/yum/x86_64/2.1903/updates/packages
        * free   0
        * needed 190 k

    原因:下载目录(/var/cache/yum/x86_64/2.1903/updates/packages)没有足够的空间来下载所需的包。

    解决方案:需要清理空间,增加下载目录的大小。

相关文档

RDS Custom简介