AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
如何擴展具有 LVM 分區的 EBS 磁碟區?
我想擴展具有 LVM 分區的 Amazon Elastic Block Store (Amazon EBS) 磁碟區。
簡短說明
擴展邏輯磁碟區有兩個選項:
- 增加現有 EBS 磁碟區的大小。
- 將其他 EBS 磁碟區新增至磁碟區群組,並擴展 VG-LV。
解決方法
選項 1: 增加現有 EBS 磁碟區的大小
**注意:**改變現有磁碟區大小通常會在磁碟區進入最佳化狀態後的幾秒內生效。處於最佳化狀態時,磁碟區的效能會受到影響,但不會低於來源組態規格。視您的磁碟區類型而定,效能變更可能需要幾分鐘到幾小時。如需詳細資訊,請參閱監視磁碟區修改進度。
1. 修改現有 EBS 磁碟區的大小。
2. 執行下列命令以安裝 growpart 公用程式:
$ sudo yum install cloud-utils-growpart
注意: 執行以下命令,以便在基於 Debian 或 Ubuntu 的系統上安裝 growpart 公用程式:
$ sudo apt install -y cloud-guest-utils
3. 執行 growpart 命令以擴展該分區。
$ sudo growpart /dev/xvdh 1 CHANGED: disk=/dev/xvdh partition=1: start=2048 old: size=20971519,end=16777182 new: size=41940958,end=41943006
4. 執行pvresize 命令以調整 PV 的大小。在下列範例中,分區 /dev/xvdh1 已擴展:
$ sudo pvresize /dev/xvdh1 Physical volume "/dev/xvdh1" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized
使用 pvs 或 pvdisplay 來檢視實體磁碟區詳細資訊:
$ sudo pvs PV VG Fmt Attr PSize PFree /dev/xvdh1 examplegroup1 lvm2 a-- <20.00g <13.00g
使用 vgs 或 vgdisplay 來檢視磁碟區群組詳細資訊:
$ sudo vgs VG #PV #LV #SN Attr VSize VFree examplegroup1 1 1 0 wz--n- <20.00g <13.00g
5. 執行 lvextend 命令來擴展邏輯磁碟區:
$ sudo lvextend -L 19G /dev/examplegroup1/lvexample1
注意: 在前面的範例中,19G 是 LV 的新增大小。LV 不是一定要增加 19G。
使用 lvs 或 lvdisplay 命令來檢視邏輯磁碟區詳細資訊:
$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lvexample1 examplegroup1 -wi-a----- 19.00g
6. 執行以下命令以擴展該檔案系統:
Ext2、Ext3、Ext4 檔案系統:
$ sudo resize2fs /dev/examplegroup1/lvexample1
XFS 檔案系統:
$ sudo xfs_growfs /dev/examplegroup1/lvexample1
選項 2: 將其他 EBS 磁碟區新增至您的磁碟區群組並擴展 VG-LV
1. 建立另一個 10 GB 的 EBS 磁碟區,然後將該磁碟區附加至執行個體。依照在 EBS 磁碟區分區上建立實體磁碟區的步驟 3,在裝置 /dev/xvdi 上建立分區。然後,執行 pvcreate 命令。在下列範例中,磁碟區的區塊裝置名稱為 /dev/xvdi1。
$ sudo pvcreate /dev/xvdi1 Physical volume "/dev/xvdi1" successfully created
2. 使用 vgextend 指令來擴充磁碟區群組並新增磁碟區。下列範例會將磁碟區群組 examplegroup1 擴充至包含 /dev/xvdi1 的磁碟區:
$ sudo vgextend examplegroup1 /dev/xvdi1 Volume group "examplegroup2" successfully extended
若要確認擴充功能,請執行 vgs 或 vgdisplay 命令。下列範例顯示 examplegroup1 磁碟區群組中現在有兩個 PV:
$ sudo vgs VG #PV #LV #SN Attr VSize VFree examplegroup1 2 1 0 wz--n- 29.99g 20.99g
3. 執行 lvextend 命令來擴展邏輯磁碟區:
$ sudo lvextend -L 29G /dev/examplegroup1/lvexample1
注意: 在前面的範例中,29G 是 LV 的新增大小。LV 不是一定要增加 29G。
4. 調整檔案系統大小:
Ext2、Ext3、Ext4 檔案系統:
$ sudo resize2fs /dev/examplegroup1/lvexample1
XFS 檔案系統:
$ sudo xfs_growfs /dev/examplegroup1/lvexample1
擴展分割磁碟區
分割是一種將資料分散到多個磁碟的技術。擴展邏輯磁碟區時,您可能會收到類似下列內容的訊息:
$ pvcreate /dev/xvdd Physical volume "/dev/xvdd" successfully created. $ vgextend vg01 /dev/xvdd Volume group "vg01" successfully extended $ vgs VG #PV #LV #SN Attr VSize VFree vg01 3 1 0 wz--n- <23.99g <13.99g $ lvextend /dev/vg01/lv01 -L +10G Using stripesize of last segment 128.00 KiB Insufficient suitable allocatable extents for logical volume lv01: 1026 more required
在未新增足夠數量的裝置來分割資料的情況下擴展「分割」邏輯磁碟區時,會發生上述錯誤或類似錯誤。
若要避免擴展分割磁碟區時發生這些錯誤,請完成以下步驟:
1. 執行下列命令,以識別 LV 在其中分割資料的裝置數量。
$ lvs -o+lv_layout,stripes LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Layout #Str lv01 vg01 -wi-a----- 10.00g striped 2
2. #Str (等量) 欄表示資料被分割時所在裝置的數量。在前面的範例中,資料會跨 2 個裝置分割。因此,您需要在 vg 中新增至少 2 個裝置 (或 2 的倍數) 才能擴展 LV。由於您已新增一個裝置 (在上述步驟中),因此您要新增第二個裝置並嘗試再次擴展:
$ pvcreate /dev/xvde Physical volume "/dev/xvde" successfully created. $ vgextend vg01 /dev/xvde Volume group "vg01" successfully extended $ vgs VG #PV #LV #SN Attr VSize VFree vg01 4 1 0 wz--n- 31.98g 21.98g $ lvextend /dev/vg01/lv01 -L +10G Using stripesize of last segment 128.00 KiB Size of logical volume vg01/lv01 changed from 10.00 GiB (2560 extents) to 20.00 GiB (5120 extents). Logical volume vg01/lv01 successfully resized. $ lvs -o+lv_layout,stripes LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Layout #Str lv01 vg01 -wi-a----- 20.00g striped 2 lv01 vg01 -wi-a----- 20.00g striped 2
上述範例輸出顯示,在新增第二個裝置時,lvextend 命令已成功完成。
3. 執行以下命令以調整檔案系統的大小:
Ext2、Ext3、Ext4 檔案系統:
$ sudo resize2fs /dev/vg01/lv01
XFS 檔案系統:
$ sudo xfs_growfs /dev/vg01/lv01
相關內容
已提問 4 年前

