本文中含有需要您注意的重要提示信息,忽略该信息可能对您的业务造成影响,请务必仔细阅读。
MBR分区格式不支持2 TiB以上的云盘。如果您的云盘目前使用的是MBR分区类型,且希望将其扩容至2 TiB以上,需要先将分区类型从MBR转换为GPT,再扩容分区及文件系统。
准备工作
已完成步骤一:扩容云盘容量。
不同分区类型支持的最大分区容量和分区数量不同。更多信息,请参见初始化数据盘概述。
操作步骤
(可选)为云盘创建快照,做好数据备份。
说明转换过程中通常不会丢失数据,但建议提前备份以防误操作。
执行以下命令,安装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
执行以下命令,将MBR分区转换为GPT分区。
警告sgdisk
只能对云盘(例如/dev/nvme2n1
)进行操作,不能对分区(例如/dev/nvme2n1p1
)进行操作,否则可能会损坏文件系统。以云盘名称
/dev/nvme2n1
为例,请根据实际情况替换云盘名称。sudo sgdisk -g /dev/nvme2n1
其中,
-g
表示将MBR转换为GPT并保留原有MBR备份。当出现
successfully
字段时,表示转换成功。说明如果运行
sgdisk
命令出现报错提示,请参见常见问题进行解决。执行以下命令,查看分区转换结果。
以云盘名称
/dev/nvme2n1
为例,请根据实际情况替换云盘名称。sudo fdisk -lu /dev/nvme2n1
当
Disklabel type
值为gpt
时,表示已转换为GPT分区,分区转换成功。
后续操作
常见问题
问题:运行转换分区
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。
解决方案:先扩容云盘容量后,再转换分区格式。
问题:运行转换分区
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的分区表结构。这种情况下,是不支持转换分区的。
解决方案:
为云盘创建快照。
通过
rsync
相关命令,将旧云盘的数据拷贝至新云盘。
问题:运行转换分区
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)没有足够的空间来下载所需的包。
解决方案:需要清理空间,增加下载目录的大小。