在物理卷中,我分配了 32 个物理盘区,每个盘区大小为 4194304 字节(或 4MiB)。 32*4194304 是 134217728 (128MiB)。当尝试调整大小到确切的大小时,我收到错误。尝试将大小调整为 129MiB 有效。
为什么无法将 PV 大小调整为分配的物理盘区的确切数量?我如何正确地知道我可以将其大小调整到多少?
root@osboxes:/etc/lvm# pvdisplay --unit b
--- Physical volume ---
PV Name /dev/sda4
VG Name vg1
PV Size 135266304 B / not usable 1048576 B
Allocatable yes (but full)
PE Size 4194304 B
Total PE 32
Free PE 0
Allocated PE 32
PV UUID 4XbCGL-eTnk-KFea-eZs5-MQT4-il6C-OPPVTB
root@osboxes:/etc/lvm# pvresize --setphysicalvolumesize 134217728b /dev/sda4
/dev/sda4: Requested size 128.00 MiB is less than real size <270.06 GiB. Proceed? [y/n]: y
WARNING: /dev/sda4: Pretending size is 262144 not 566349824 sectors.
/dev/sda4: cannot resize to 31 extents as 32 are allocated.
0 physical volume(s) resized or updated / 1 physical volume(s) not resized
答案1
LVM 元数据必须存放在某个地方。通常,PV 开始时的大小为 1MiB。
您可以像这样检查第一个物理范围的起始偏移量:
pvs -o +pe_start
将第一个 PE 偏移量添加到总大小中,它应该可以工作。
您还可以在 时设置此值vgcreate
,如手册页中所述:
--dataalignment Size[k|UNIT]
Align the start of the data to a multiple of this number. Also
specify an appropriate Physical Extent size when creating a VG.
To see the location of the first Physical Extent of an existing
PV, use pvs -o +pe_start. In addition, it may be shifted by an
alignment offset. See lvm.conf/data_alignment_offset_detection
and --dataalignmentoffset.
--dataalignmentoffset Size[k|UNIT]
Shift the start of the data area by this additional offset.
小心使用这些,否则你可能会得到非常奇怪的偏移。