共用方式為


無法在 Linux 虛擬機中調整大於 2 TB 的數據磁碟 MBR 磁碟大小

適用於:✔️ Linux VM

對於無法為 Azure Linux 虛擬機器中大於 2 TB 的資料磁碟調整主開機記錄 (MBR) 分割區大小的問題,本文提供了解決方案。

重要

本文適用於支援的 已背書 Linux 發行版

徵兆

當您執行 fdisk 命令來調整 MBR 磁碟分區的大小時,您會收到下列警告訊息:

此磁碟的大小為8.8 TB。 DOS 磁碟分區數據表格式不能用於磁碟驅動器上,磁碟區超過 2 TB 的 512 位元組扇區。 使用 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) 沒有扇區位址限制,因此我們建議針對 2 TB 或更大的數據磁碟使用 GPT。

以下是在資料磁碟上使用 GPT 的兩種方法:

將分割區類型從 MBR 變更為 GPT

重要

步驟 1:識別目前的分割區數據表類型

使用下列其中一個工具來檢查目前的數據磁碟是否為 MBR 或 GPT。

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

步驟 2:重新建立分割區

注意

本節使用 gdisk 工具來重新建立分割區作為範例。

  1. gdisk如果未在 Linux 虛擬機中安裝此工具,請安裝此工具:

    sudo yum install gdisk -y
    
  2. 確認資料磁碟的目前大小:

    sudo gdisk -l /dev/sdd | grep Disk | grep sectors
    
    Disk /dev/sdd: 17179869184 sectors, 8.0 TiB
    
  3. 停止在虛擬機器上執行的應用程式,並取消掛接檔案系統:

    sudo systemctl stop myapp.service
    sudo umount /appext4
    

    注意

    • /appext4 都是myapp.service範例專案。 據以取代它們。
    • 如果您需要增加資料磁碟大小,您現在可以透過 Azure 帳戶來執行此作業。 Azure 入口網站 中的磁碟大小需要停機。 如需詳細資訊,請參閱 展開 Azure 受控磁碟
  4. 使用 gdisk 命令重新建立分割區編號 1:

    sudo gdisk /dev/sdd
    
    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:

    sudo gdisk -l /dev/sdd | grep -A4 '^Partition table scan:'
    
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: present    
    
  6. 執行下列命令來檢查分割區的大小:

    sudo lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,RO,MOUNTPOINT
    
    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. 取消掛接自動掛接的文件系統,並加以修復:

    sudo umount /appext4
    sudo fsck.ext4 -fy /dev/sdd1
    
    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. 重新掛接檔案系統:

    sudo mount /appext4
    
  9. 調整檔案系統大小:

    如果檔案系統為 ext4,請執行下列命令:

    sudo resize2fs /dev/sdd1
    
    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,請執行下列命令:

    sudo xfsgrowfs /dev/sdd1
    
  10. 確認新的大小:

    sudo lsblk -o NAME,TYPE,FSTYPE,LABEL,SIZE,RO,MOUNTPOINT
    
    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 不以默示或其他方式,提供與這些產品的效能或可靠性有關的擔保。

與我們連絡,以取得說明

如果您有問題或需要相關協助,請建立支援要求,或詢問 Azure community 支援。 您也可以向 Azure 意見反應社群提交產品意見反應。