启动与虚拟机故障

无法调整大于 2 TB 的数据磁盘的 MBR 分区大小 - Virtual Machines

· 52CE 我爱测

适用于:✔️ Linux VM 总结 本文提供了一个解决方案,用于解决以下问题:无法在 Azure Linux 虚拟机中为大于 2 TB 的数据磁盘调整主启动记录(MBR)分区的大小。 重要 本文适用于受支持的认可的 Linux 分发版(/zh-cn/azure/virtual-machines/linux/endorsed-distros)。 现象 运行 fdisk 命令以重设 MBR 分区大小时,会收到以下警告消息: 此磁盘的大小为 8.8 TB。 对

适用于:✔️ Linux VM

总结

本文提供了一个解决方案,用于解决以下问题:无法在 Azure Linux 虚拟机中为大于 2 TB 的数据磁盘调整主启动记录(MBR)分区的大小。

重要

本文适用于受支持的认可的 Linux 分发版。

现象

运行 fdisk 命令以重设 MBR 分区大小时,会收到以下警告消息:

此磁盘的大小为 8.8 TB。 对于 512 字节扇区大于 2 TB 的卷,DOS 分区表格式不能用于驱动器。 使用 parted(1)和 GUID 分区表格式(GPT)。

下面是一个命令示例:

sudo fdisk /dev/sdd

下面是命令输出示例:

WARNING: The size of this disk is 8.8 TB (8796093022208 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).
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): n
Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4294967295, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294):
Using default value 4294967294
Partition 1 of type Linux and of size 2 TiB is set   <--- HERE
Command (m for help): p
Disk /dev/sdd: 8796.1 GB, 8796093022208 bytes, 17179869184 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x7024d1b6
    Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048  4294967294  2147482623+  83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

若要验证新大小,请执行以下步骤:

  1. 运行以下命令,通知操作系统(OS)分区表更改:

    sudo partprobe /dev/sdd
    
  2. 运行以下命令检查分区 /dev/sdd1 的新大小:

    sudo lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,RO,MOUNTPOINT
    

    命令输出显示分区的大小仅为 2 TB。 下面是命令输出示例:

    NAME              TYPE FSTYPE      LABEL  SIZE RO MOUNTPOINT
    sda               disk                     32G  0
    ├─sda1            part vfat               500M  0 /boot/efi
    ├─sda2            part xfs                500M  0 /boot
    ├─sda3            part xfs                 31G  0 /
    └─sda4            part                      2M  0
    sdb               disk                    256G  0
    └─sdb1            part ext4               256G  0 /mnt
    sdd               disk                      8T  0
    └─sdd1            part ext4                 2T  0 /appext4
    

原因

MBR 包含分区边界和分区(文件系统)类型信息,其寻址限制为 2^32 扇区。 MBR 分区数据结构中的 32 位地址限制会限制磁盘和分区的大小。

对于 512 字节扇区,MBR 分区的地址限制为 2 TB。 对于较新的 4Kn 设备,每个逻辑扇区为 2^32 x 4,096 字节或 16 TB。

解决方案

由于 GUID 分区表(GPT)没有扇区地址限制,因此我们建议将 GPT 用于 2 TB 或更大的数据磁盘。

下面是在数据磁盘上使用 GPT 的两种方法:

  • 将分区类型从 MBR 更改为 GPT。
  • 对磁盘上的数据进行完整备份,然后重新创建 GPT。

将分区类型从 MBR 更改为 GPT

重要

  • 在进行任何更改之前,先创建 数据磁盘的快照 。
  • 此更改只能在数据磁盘上完成,而不是 OS 磁盘上。 如果在 OS 磁盘上进行操作,最终会导致无法启动的状态。
  • 对于 Red Hat, 无法在不丢失数据的情况下将 MSDOS 标签转换为 GPT。

步骤 1:标识当前分区表类型

使用以下工具之一检查当前数据磁盘是否为 MBR 或 GPT。

fdisk

sudo fdisk -l /dev/sdd | grep -i type
Disk label type: dos

分手

sudo parted /dev/sdd print | grep -i '^Partition Table'
Partition Table: msdos

gdisk

sudo gdisk -l /dev/sdd | grep -A4 '^Partition table scan:'
 Partition table scan: 
   MBR: MBR only
   BSD: not present
   APM: not present
   GPT: not present

步骤 2:重新创建分区

注意

本部分使用 gdisk 该工具重新创建分区作为示例。

  1. gdisk如果未在 Linux 虚拟机中安装该工具,请安装该工具:

Red Hat 7.x

    sudo yum install gdisk -y
    ```

# [Red Hat 8.x/9.x](#tab/rhel89)
```bash
    sudo dnf install gdisk -y
    ```

# [Ubuntu](#tab/ubuntu)
```bash
    sudo apt -y install gdisk
    ```

# [SUSE](#tab/sles)
```bash
    sudo zypper install gdisk
    ```

# [Azure Linux](#tab/azurelinux)
```bash
    sudo dnf install gdisk -y
    ```

---
2. 验证数据磁盘的当前大小:

    ```bash
    sudo gdisk -l /dev/sdd | grep Disk | grep sectors
    ```

    ```output
    Disk /dev/sdd: 17179869184 sectors, 8.0 TiB
    ```
3. 停止在虚拟机上运行的应用程序,并卸载文件系统:

    ```bash
    sudo systemctl stop myapp.service
    sudo umount /appext4
    ```

    注意

    - 两者都是`myapp.service``/appext4`示例条目。 相应地替换它们。
    - 如果需要增加数据磁盘大小,现在可以通过Azure帐户执行此操作。 在Azure门户中的磁盘大小调整操作需要停机。 有关详细信息,请参阅 [Expand Azure 托管磁盘](/zh-cn/azure/virtual-machines/linux/expand-disks?tabs=ubuntu#expand-an-azure-managed-disk)。
4. 使用 `gdisk` 以下命令重新创建分区号 1:

    ```bash
    sudo gdisk /dev/sdd
    ```

    ```output
    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 dont want to convert your MBR partitions
    to GPT format!
    ***************************************************************
    Command (? for help): p                                                --> PRINT PARTITION TABLE
    Disk /dev/sdd: 17179869184 sectors, 8.0 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 8A3DAD49-6916-4BC5-836B-2F90C5161C05
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 17179869150
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 12884903870 sectors (6.0 TiB)
    Number  Start (sector)    End (sector)  Size       Code  Name
        1            2048      4294967294   2.0 TiB     8300  Linux filesystem
    Command (? for help): d                                                --> DELETE PARTITION TABLE
    Using 1
    Command (? for help): n                                                --> CREATE NEW PARTITION TABLE
    Partition number (1-128, default 1):                                   --> PARTITION 1
    First sector (34-17179869150, default = 2048) or {+-}size{KMGTP}: 2048 --> SAME 1th SECTOR AS THE ORIGINAL PARTITION
    Last sector (2048-17179869150, default = 17179869150) or {+-}size{KMGTP}: --> HIT ENTER TO USE THE WHOLE SPACE, IN THIS CASE 8 TB
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300):
    Changed type of partition to 'Linux filesystem'
    Command (? for help): p                                                --> PRINT PARTITION TABLE
    Disk /dev/sdd: 17179869184 sectors, 8.0 TiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 8A3DAD49-6916-4BC5-836B-2F90C5161C05
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 17179869150
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 2014 sectors (1007.0 KiB)
    Number  Start (sector)    End (sector)  Size       Code  Name
        1            2048     17179869150   8.0 TiB     8300  Linux filesystem
    Command (? for help): w                                                  --> APPLY CHANGES
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    Do you want to proceed? (Y/N): Y                                          --> "Y" TO APPLY
    OK; writing new GUID partition table (GPT) to /dev/sdd.
    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.
    ```
5. 验证分区样式是否已更改为 GPT:

    ```bash
    sudo gdisk -l /dev/sdd | grep -A4 '^Partition table scan:'
    ```

    ```output
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: present    
    ```
6. 运行以下命令检查分区的大小:

    ```bash
    sudo lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,RO,MOUNTPOINT
    ```

    ```output
    NAME              TYPE FSTYPE      LABEL  SIZE RO MOUNTPOINT
    sda               disk                     32G  0
    ├─sda1            part vfat               500M  0 /boot/efi
    ├─sda2            part xfs                500M  0 /boot
    ├─sda3            part xfs                 31G  0 /
    └─sda4            part                      2M  0
    sdb               disk                    256G  0
    └─sdb1            part ext4               256G  0 /mnt
    sdd               disk                      8T  0
    └─sdd1            part ext4                 2T  0 /appext4
    ```
7. 卸载自动装载的文件系统并对其进行修复:

    ```bash
    sudo umount /appext4
    sudo fsck.ext4 -fy /dev/sdd1
    ```

    ```output
    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/sdd1: 6728/134217728 files (0.2% non-contiguous), 8849024/536870655 blocks
    ```
8. 重新装载文件系统:

    ```bash
    sudo mount /appext4
    ```
9. 调整文件系统大小:

    如果文件系统为 `ext4`,请运行以下命令:

    ```bash
    sudo resize2fs /dev/sdd1
    ```

    ```output
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/sdd1 is mounted on /appext4; on-line resizing required
    old_desc_blocks = 256, new_desc_blocks = 1024
    The filesystem on /dev/sdd1 is now 2147483387 blocks long.
    ```

    如果文件系统为 `XFS`,请运行以下命令:

    ```bash
    sudo xfsgrowfs /dev/sdd1
    ```
10. 验证新大小:

    ```bash
    sudo lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,RO,MOUNTPOINT
    ```

    ```output
    NAME              TYPE FSTYPE      LABEL  SIZE RO MOUNTPOINT
    sda               disk                     32G  0
    ├─sda1            part vfat               500M  0 /boot/efi
    ├─sda2            part xfs                500M  0 /boot
    ├─sda3            part xfs                 31G  0 /
    └─sda4            part                      2M  0
    sdb               disk                    256G  0
    └─sdb1            part ext4               256G  0 /mnt
    sdc               disk                      1T  0
    └─sdc1            part LVM2_member          1T  0
      └─vgtest1-lvol1 lvm  ext4               500G  0
    sdd               disk                      8T  0
    └─sdd1            part ext4                 8T  0 /appext4
    sde               disk                      1T  0
    ```

**第三方信息免责声明**

本文讨论的第三方产品由独立于Microsoft的公司制造。 Microsoft对这些产品的性能或可靠性不作任何默示或其他保证。

资料来源与适用范围

资料来源
微软官方 Linux 虚拟机排障文档
适用范围
Azure Linux 虚拟机;按正文发行版、内核及代理版本
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-10-26
授权说明
CC BY 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。