暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MBR分区无法扩容至2T以上解决办法(MBR更改为GPT无损扩容)分享

原创 vic 2025-01-15
2118

在对 Oracle 测试环境(云主机虚拟机)进行磁盘扩容的过程中,曾遇到容量限制问题。由于磁盘分区使用的是 MBR(Master Boot Record)分区表,而 MBR 分区表的设计存在限制,其支持的最大磁盘容量仅为 2TB。这是因为 MBR 分区表采用 4 个字节存储分区的总扇区数,最多能够表示 (2^{32}) 个扇区。按照每个扇区 512 字节计算,每个分区的最大容量限制为 2TB。当磁盘容量超过 2TB 时,因超出 MBR 分区的支持范围,扩容操作无法继续进行。

报错内容如下

WARNING: The size of this disk is 3.2 TB (3221225472000 bytes). DOS partition table format can not be used on drives for volumes larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID partition table format (GPT).

(一)操作步骤


本文档介绍在不影响当前分区数据的情况下,将 MBR 转换为 GPT 并进行分区扩容的操作步骤。

⚠️ 注意事项
‼️数据珍贵,请对数据盘做镜像或本地备份后操作,此文档不为任何操作失误导致数据丢失负责!!!


1、卸载已挂载设备,并关闭已调用目录相关程序

##查看是否有程序在使用该数据盘,如果有关闭程序或将其进程杀掉 fuser -m /dev/vdb1 ##卸载已挂载设备 umount /dev/vdb1 ##还需要将fstab中写入的挂载信息先注释掉,然后执行一下mount -a重新读取一下

2、使用gdisk工具更改MBR为GPT

### 安装gdisk工具 [root@instance-daojiao2-9 ~]# yum install -y gdisk Loaded plugins: langpacks, versionlock base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): extras/7/x86_64/primary_db | 247 kB 00:00:00 (2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (3/4): epel/x86_64/primary_db | 7.0 MB 00:00:00 (4/4): updates/7/x86_64/primary_db | 16 MB 00:00:00 Excluding 1 update due to versionlock (use "yum versionlock status" to show it) Resolving Dependencies --> Running transaction check ---> Package gdisk.x86_64 0:0.8.10-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =============================================================================================================================================================================================== Package Arch Version Repository Size =============================================================================================================================================================================================== Installing: gdisk x86_64 0.8.10-3.el7 base 190 k Transaction Summary =============================================================================================================================================================================================== Install 1 Package Total download size: 190 k Installed size: 660 k Downloading packages: gdisk-0.8.10-3.el7.x86_64.rpm | 190 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : gdisk-0.8.10-3.el7.x86_64 1/1 Verifying : gdisk-0.8.10-3.el7.x86_64 1/1 Installed: gdisk.x86_64 0:0.8.10-3.el7 Complete! ### 使用gdisk更改分区格式为GPT [root@instance-xxxxxx ~]# gdisk /dev/vdb GPT fdisk (gdisk) version 0.8.10 Partition table scan: MBR: MBR only 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 Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y 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.

3、使用parted进行分区扩容

## 查看是否更改分区格式 [root@instance-instance-xxxxxx ~]# fdisk -l /dev/vdb WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/vdb: 3221.2 GB, 3221225472000 bytes, 6291456000 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 Disk label type: gpt ##gpt为gpt格式,doc为MBR格式 Disk identifier: 0CAD0003-E36D-43CB-A3A7-FD45FB802440 # Start End Size Type Name 1 2048 4294967294 2T Linux filesyste Linux filesystem ### 使用parted进行分区扩容 [root@instance-xxxxxx ~]# parted /dev/vdb GNU Parted 3.1 Using /dev/vdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print ## 查看分区内容 在这里一定要 记住Start的数字,下面新建分区需要用,如果填错可能会丢失数据!! 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 2199GB 2199GB ext4 Linux filesystem (parted) rm 1 ##删除分区 (parted) p ##查看分区内容已经删除成功 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 (parted) mkpart #新建分区 Partition name? []? ##分区名称,回车默认为主分区1 File system type? [ext2]? ext4 ##文件系统类型,必须和之前格式化分区指定的一样 Start? 1049kB #这里注意是上面删除之前start的数字 End? 100% ##结束位置为100% (parted) p ##查看分区内容 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 (parted) quit ##保存退出 Information: You may need to update /etc/fstab.

4、检测文件系统准确性,

[root@instance-xxxxxx ~]# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 14289098/134217728 files (0.1% non-contiguous), 488579163/536870655 blocks

5、对分区进行扩展

[root@instance-xxxxx ~]# resize2fs -f /dev/vdb1 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/vdb1 to 786431488 (4k) blocks. The filesystem on /dev/vdb1 is now 786431488 blocks long.

6、对分区文件系统进行挂载

[root@instance-xxxxx ~]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Tue Jan 26 10:54:21 2021 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=b8e1679f-5c4e-419d-92a1-c2925b2bbea6 / ext4 defaults 1 1 /dev/vdb1 /data ext4 defaults 0 0 [root@instance-xxxxx ~]# mount -a ### 查看扩容无误,收工 [root@instance-xxxxxx~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 704K 3.9G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/vda1 ext4 40G 3.9G 34G 11% / tmpfs tmpfs 799M 0 799M 0% /run/user/0 /dev/vdb1 ext4 2.9T 1.8T 987G 65% /data

(二)总结

本次分享的是日常工作中的一个实践案例:将 Oracle 测试环境的数据盘从 MBR 转换为 GPT,成功突破了 MBR 分区表的 2TB 限制,将磁盘扩展到了 3.2TB。整个操作流程包括分区格式转换、重新分区、扩展文件系统以及挂载验证,最终确保了数据完整性和系统的正常运行。

最后修改时间:2025-01-15 16:24:57
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论