擴展磁盤分區和文件系統前,請先檢查磁盤的分區形式和文件系統,并根據磁盤的分區形式選擇對應的操作指導。
-
檢查磁盤分區形式,請參見:
- 方法一:使用fdisk命令查看分區形式和文件系統
- 方法二:使用parted命令查看分區形式和文件系統
-
選擇操作指導,請參見下表。
表 分區和文件系統擴展場景說明
磁盤 場景 方法 系統盤 為擴容部分的云硬盤分配新的MBR分區 新增MBR分區 將擴容部分的容量劃分至已有的MBR分區內 擴大已有MBR分區(內核版本高于3.6.0) 擴大已有MBR分區(內核版本低于3.6.0) 數據盤 為擴容部分的云硬盤分配新的MBR分區 新增MBR分區 將擴容部分的容量劃分至已有的MBR分區內 擴大已有MBR分區 為擴容部分的云硬盤分配新的GPT分區 新增GPT分區 將擴容部分的容量劃分至已有的GPT分區內 擴大已有GPT分區 SCSI數據盤 為擴容部分的云硬盤分配新的MBR分區 新增MBR分區 將擴容部分的容量劃分至已有的MBR分區內 擴大已有MBR分區
說明
MBR分區支持的磁盤最大容量為2 TB,超過2 TB的部分無法使用。
如果當前磁盤采用MBR分區形式,并且需要將該磁盤擴容至2 TB以上投入使用。則必須將磁盤分區形式由MBR切換成GPT,期間會中斷業務,并且更換磁盤分區形式時會清除磁盤的原有數據,請在擴容前先對數據進行備份。
方法一:使用fdisk命令查看分區形式和文件系統
步驟 1 執行以下命令,查看云主機掛載的所有磁盤情況。
lsblk
回顯類似如下信息:
[root@ecs-test-0001 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 150G 0 disk
└─vdb1 253:17 0 100G 0 part /mnt/sdc
本示例中數據盤“/dev/vdb”擴容前已有分區“/dev/vdb1”,將數據盤擴容50GB后,新增的容量還未劃分磁盤分區,因此“/dev/vdb”顯示150GB,“/dev/vdb1”顯示100GB。
步驟 2 執行以下命令,查看當前磁盤分區的分區形式。
fdisk -l
回顯類似如下信息:
[root@ecs-test-0001 ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: dos
Disk identifier: 0x000bcb4e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886079 41942016 83 Linux
Disk /dev/vdb: 161.1 GB, 161061273600 bytes, 314572800 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: dos
Disk identifier: 0x38717fc1
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 83 Linux
“system”為“Linux”表示分區形式為MBR。“system”為“GPT”表示分區形式為GPT。
- 若回顯中沒有列出所有的磁盤分區,和步驟1中的信息不符合。可能原因是:磁盤已有分區為GPT,并且擴容后存在未分配分區的空間,此時使用fdisk -l無法查看所有分區的信息,請參考方法二:使用parted命令查看分區形式和文件系統重新確認磁盤分區形式和文件系統。
- 若回顯中列出了所有的磁盤分區,和步驟1中的信息符合,則繼續執行以下操作。
步驟 3 執行以下命令,查看磁盤分區的文件系統格式。
blkid 磁盤分區
命令示例:
blkid /dev/vdb1
“TYPE”為“ext4”:表示為/dev/vdb1的文件系統是ext4。
步驟 4 執行以下命令,確認文件系統的狀態。
ext*:e2fsck -n 磁盤分區
xfs:xfs_repair -n 磁盤分區
以“ext4” 為例:
e2fsck -n /dev/vdb1
回顯類似如下信息:
[root@ecs-test-0001 ~]# e2fsck -n /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Warning! /dev/vdb1 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
/dev/vdb1: clean, 11/6553600 files, 459544/26214144 blocks
文件系統狀態為clean表示狀態正常,若不是clean,請先修復問題后執行擴容操作。
方法二:使用parted命令查看分區形式和文件系統
步驟 1 執行以下命令,查看云主機掛載的所有磁盤情況。
lsblk
回顯類似如下信息:
[root@ecs-test-0001 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 150G 0 disk
└─vdb1 253:17 0 100G 0 part /mnt/sdc
本示例中數據盤“/dev/vdb”擴容前已有分區“/dev/vdb1”,將數據盤擴容50GB后,新增的容量還未劃分磁盤分區,因此“/dev/vdb”顯示150GB,“/dev/vdb1”顯示100GB。
步驟 2 執行以下命令,指定一塊磁盤,然后輸入“p”,查看磁盤的分區形式。
parted 磁盤
以查看“/dev/vdb”的分區形式為例:
parted /dev/vdb
回顯類似如下信息:
[root@ecs-test-0001 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the
disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? Fix
Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600
blocks) or continue with the current setting?
Fix/Ignore? Fix
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 107GB 107GB ext4 test
(parted)
“Partition Table”表示當前磁盤的分區形式,msdos表示磁盤分區形式為MBR,gpt表示磁盤分區形式為GPT。
-
若系統出現以下Error,請輸入“Fix”。
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
GPT分區表信息存儲在磁盤開頭,為了減少分區表損壞的風險,同時在磁盤末尾會備份一份。當磁盤容量擴大后,末尾位置也會隨之變化,因此需要根據系統提示輸入“Fix”,將分區表信息的備份文件挪到新的磁盤末尾位置。
- 系統出現以下Warning,請輸入“Fix”。
Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600
blocks) or continue with the current setting?
Fix/Ignore? Fix
根據系統提示輸入“Fix”,系統會自動將磁盤擴容部分的容量設置為GPT。
步驟 3 查看完成后,輸入“q”,退出parted模式。