阿里云盘MBR分区格式改为GPT格式支持大于2T文件系统扩展
背景
平台ECS主机,磁盘2T吃紧需要扩容,阿里云上扩展到3T后,因文件系统格式为MBR,扩展的磁盘使用不到,需要修改分区表格式。
声明:虽然本人实际操作没有出现丢数据的情况,但肯定是有意外的案例,因为阿里云技术支持没有给出这个方案,说明本身是有风险的。生产的数据,能备份的先备份,保证数据不丢失的前提下进行以下方案操作。
参考:https://blog.csdn.net/matrixgod/article/details/89642547
1、修改分区格式
修改前:
# parted -l
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 42.9GB 42.9GB primary ext4 boot
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 2048GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos # 分区表类型为msdos
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2048GB 2048GB ext4
2、修改分区表格式
# umount /data # 卸载磁盘
# yum install -y gdisk # 安装gdisk命令
# gdisk /dev/vdb # 注意, 是直接给/dev/vdb修改分区表, 千万不要将/dev/vdb1(带盘符ID)进行修改!!!!!!!!!!!!
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: MBR only # 仅有MBR分区表
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************
Command (? for help): w # 写入GPT分区表
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y # Yes, 确认
OK; writing new GUID partition table (GPT) to /dev/vdb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot. # 需重启
The operation has completed successfully.
# init 6
若是新建,执行命令创建 分区表:mklabel,不是则跳过
(parted) mkpart # 无分区表
Error: /dev/vdd: unrecognised disk label
(parted) unit s
(parted) mklabel # 新建分区表
New disk label type? gpt # msdos是mbr分区,gpt是gpt分区
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 4194304000s
Sector size (logical/physical): 512B/512B
Partition Table: gpt # 现在的分区格式
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart
Partition name? []?
File system type? [ext2]? ext4
Start? 2048
End?
End? 100% # 2048s-->100%容量
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 4194304000s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 4194301951s 4194299904s
(parted) quit
# mkfs.ext4 /dev/vdd1 # 格式化
3、扩展分区
# parted /dev/vdb # 开始扩展分区
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s # 单位改为s
(parted) p # 打印一下信息
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 6291456000s
Sector size (logical/physical): 512B/512B
Partition Table: gpt # 修改后的分区格式
Disk Flags:
# 以下信息极为重要,一定要记录:Number是分区号, 删除时候需要; Start是开始节点, 绝对不要搞错; File system是文件系统格式, 和原来要保持完全一致;
Number Start End Size File system Name Flags
1 2048s 4294967295s 4294965248s ext4 Linux filesystem
(parted) rm 1 # 删除分区1, 这里理解为临时删除, 因为后面创建的新分区会包含老分区的所有扇区, 即: 扩展
(parted) mkpart # 重建分区
Partition name? []? # 默认回车即可
File system type? [ext2]? ext4 # 文件系统格式, 与上面的ext4一致(如果是ext3等, 必须要一致)
Start? 2048 # 开始的区域, 与上面的Start必须完全一致, 否则原来的数据就GG了.
End? 100% # End边界定义到物理边界的100%
(parted) quit # 退出
Information: You may need to update /etc/fstab.
[root@iZ2zeet2qekjwuluf3lhayZ ~]# resize2fs /dev/vdb1 # 重新resize, 如果提示需要e2fsck的话, 执行一下e2fsck -f /dev/vdb1即可, 过后再resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vdb1 is mounted on /data; on-line resizing required # 这里磁盘自动被挂载了, 保证磁盘被卸载的情况下操作.
old_desc_blocks = 256, new_desc_blocks = 375
The filesystem on /dev/vdb1 is now 786431488 blocks long.
# 修改后
# parted -l # 仅显示vdb部分
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 3221GB 3221GB ext4
转载请注明:liutianfeng.com » 阿里ECS的云盘格式由MBR切换为GPT