MBR分区无法扩容至2T以上解决办法(MBR更改为GPT无损扩容)
目录
MBR分区扩容发现高于2T报错,如果解决
- 报错内容如下
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分区是用4个字节存储分区的总扇区数,最大能表示2的32次方的扇区个数,按每扇区512字节计算,所以每个分区最大不能超过2TB。
解决MBR数据磁盘只能扩容2T,将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-daojiao2-9 ~]# 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