Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
如何扩展具有 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 大小。19G 不是 LV 必须增加的大小。
使用 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 大小。29G 不是 LV 必须增加的大小。
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

