Red Hat Training
A Red Hat training course is available for RHEL 8
10.2. 创建精简配置的逻辑卷
使用精简配置的逻辑卷,您可以创建大于可用物理存储的逻辑卷。创建精简配置的卷集允许系统分配您所使用的卷,而不是分配所请求的全部存储。
使用 lvcreate
命令的 -T
或 --thin
选项,您可以创建精简池或精简卷。您还可以使用 lvcreate
命令的 -T
选项,使用单个命令创建精简池和精简卷。这个流程描述了如何创建和增大精简配置的逻辑卷。
先决条件
- 您已创建了一个卷组。如需更多信息,请参阅创建 LVM 卷组。
流程
创建精简池:
# lvcreate -L 100M -T vg001/mythinpool Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data. Logical volume "mythinpool" created.
请注意:由于您要创建物理空间池,您必须指定池的大小。
lvcreate
命令的-T
选项不使用参数;它从随命令一起添加的其他选项来确定要创建的设备类型。您还可以使用额外的参数创建精简池,如下面的例子所示:您还可以使用
lvcreate
命令的--thinpool
参数创建精简池。与-T
选项不同,--thinpool
参数要求您指定您要创建的精简池逻辑卷的名称。以下示例使用--thinpool
参数在卷组 vg001 中创建名为 mythinpool 的精简池,大小为 100M :# lvcreate -L 100M --thinpool mythinpool vg001 Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data. Logical volume "mythinpool" created.
由于池创建支持条带,所以您可以使用
-i
和-I
选项创建条带。以下命令在卷组 vg001 中创建一个名为 thinpool 的 100M 精简池,其有两个 64 kB 条带和一个大小为 256 kB 的块。它还会创建一个名为 vg001/thinvolume 的 1T 的精简卷。注意确保卷组中有两个有足够空闲空间的物理卷,否则您无法创建精简池。
# lvcreate -i 2 -I 64 -c 256 -L 100M -T vg001/thinpool -V 1T --name thinvolume
创建精简卷:
# lvcreate -V 1G -T vg001/mythinpool -n thinvolume WARNING: Sum of all thin volume sizes (1.00 GiB) exceeds the size of thin pool vg001/mythinpool (100.00 MiB). WARNING: You have not turned on protection against thin pools running out of space. WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full. Logical volume "thinvolume" created.
在这种情况下,您为卷指定了虚拟大小,其大于包含它的池。您还可以使用额外的参数创建精简卷,如下面的例子所示:
要创建精简卷和精简池,请使用
lvcreate
命令的-T
选项,并指定大小和虚拟大小参数:# lvcreate -L 100M -T vg001/mythinpool -V 1G -n thinvolume Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data. WARNING: Sum of all thin volume sizes (1.00 GiB) exceeds the size of thin pool vg001/mythinpool (100.00 MiB). WARNING: You have not turned on protection against thin pools running out of space. WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full. Logical volume "thinvolume" created.
要使用剩余的空闲空间来创建精简卷和精简池,请使用
100%FREE
选项:# lvcreate -V 1G -l 100%FREE -T vg001/mythinpool -n thinvolume Thin pool volume with chunk size 64.00 KiB can address at most <15.88 TiB of data. Logical volume "thinvolume" created.
要将现有的逻辑卷转换成精简池卷,请使用
lvconvert
命令的--thinpool
参数。您还必须将--poolmetadata
参数与--thinpool
参数结合使用,将现有的逻辑卷转换成精简池卷的元数据卷。以下示例将卷组 vg001 中的现有逻辑卷 lv1 转换为精简池卷,并将卷组 vg001 中的现有逻辑卷 lv2 转换为那个精简池卷的元数据卷:
# lvconvert --thinpool vg001/lv1 --poolmetadata vg001/lv2 Converted vg001/lv1 to thin pool.
注意将逻辑卷转换成精简池卷或者精简池元数据卷会破坏逻辑卷的内容,因为
lvconvert
不会保留设备的内容,而是覆盖其内容。默认情况下,
lvcreate
命令使用以下公式近似设置精简池元数据逻辑卷的大小:Pool_LV_size / Pool_LV_chunk_size * 64
如果您有大量快照,或者您的精简池有小的块,且预期以后精简池的大小会显著增长,则您可能需要使用
lvcreate
命令的--poolmetadatasize
参数来增加精简池的元数据卷的默认值。精简池元数据逻辑卷所支持的值在 2MiB 到 16GiB 之间。以下示例演示了如何增大精简池的元数据卷的默认值:
# lvcreate -V 1G -l 100%FREE -T vg001/mythinpool --poolmetadatasize 16M -n thinvolume Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data. Logical volume "thinvolume" created.
查看创建的精简池和精简卷:
# lvs -a -o +devices LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices [lvol0_pmspare] vg001 ewi------- 4.00m /dev/sda(0) mythinpool vg001 twi-aotz-- 100.00m 0.00 10.94 mythinpool_tdata(0) [mythinpool_tdata] vg001 Twi-ao---- 100.00m /dev/sda(1) [mythinpool_tmeta] vg001 ewi-ao---- 4.00m /dev/sda(26) thinvolume vg001 Vwi-a-tz-- 1.00g mythinpool 0.00
可选:使用
lvextend
命令扩展精简池的大小。但是您无法缩小精简池的大小。注意在创建精简池和精简卷的过程中,如果您使用
-l 100%FREE
参数,这个命令会失败。以下命令通过扩展 100M 来调整现有大小为 100M 的精简池的大小:
# lvextend -L+100M vg001/mythinpool Size of logical volume vg001/mythinpool_tdata changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents). WARNING: Sum of all thin volume sizes (1.00 GiB) exceeds the size of thin pool vg001/mythinpool (200.00 MiB). WARNING: You have not turned on protection against thin pools running out of space. WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full. Logical volume vg001/mythinpool successfully resized
# lvs -a -o +devices LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices [lvol0_pmspare] vg001 ewi------- 4.00m /dev/sda(0) mythinpool vg001 twi-aotz-- 200.00m 0.00 10.94 mythinpool_tdata(0) [mythinpool_tdata] vg001 Twi-ao---- 200.00m /dev/sda(1) [mythinpool_tdata] vg001 Twi-ao---- 200.00m /dev/sda(27) [mythinpool_tmeta] vg001 ewi-ao---- 4.00m /dev/sda(26) thinvolume vg001 Vwi-a-tz-- 1.00g mythinpool 0.00
可选:要重命名精简池和精简卷,请使用以下命令:
# lvrename vg001/mythinpool vg001/mythinpool1 Renamed "mythinpool" to "mythinpool1" in volume group "vg001" # lvrename vg001/thinvolume vg001/thinvolume1 Renamed "thinvolume" to "thinvolume1" in volume group "vg001"
重命名后查看精简池和精简卷:
# lvs LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert mythinpool1 vg001 twi-a-tz 100.00m 0.00 thinvolume1 vg001 Vwi-a-tz 1.00g mythinpool1 0.00
可选:要删除精简池,请使用以下命令:
# lvremove -f vg001/mythinpool1 Logical volume "thinvolume1" successfully removed. Logical volume "mythinpool1" successfully removed.
其他资源
-
lvcreate(8)
、lvrename(8)
、lvs(8)
和lvconvert(8)
手册页