我使用这些命令将LVM缩小了一半:
e2fsck -f /dev/VG/LV resize2fs /dev/VG/LV 5G lvreduce -L 5G /dev/VG/LV
检查物理量产生这样的结果:
--- Physical volume --- PV Name /dev/sdb VG Name VG PV Size 10.00 GiB / not usable 4.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 2559 Free PE 1279 Allocated PE 1280
如何通过fdisk将免费的PE(启动的柱面)作为标准分区来分配?
如果您创build了PV作为分区,则必须先使用pvresize --setphysicalvolumesize 5124M /dev/sdb缩小PV,然后使用fdisk或parted等工具调整分区表中的分区大小。
但是在你的情况下,你不能在那里创build新的分区,因为PV包含整个驱动器,所以你不能安全地创build一个新的分区表而不破坏PV。 那么,实际上你可以直接操纵分区表,但这是危险的,将会回来,咬你进一步沿线。
相反,最安全的方法是在另一个驱动器上创build另一个PV,将其添加到卷组,将LV移到另一个PV,从VG中删除第一个PV,从/ dev / sdb中删除第一个PV,创build分区在/ dev / sdb上,在其中一个分区上创buildPV,将PV添加到VG,将LV移动到此时正确的PV,最后从VG中删除临时PV。
就像这样:( 注意,你必须确保你使用的设备名称适用于你的特定configuration,不要只是复制和粘贴, /dev/sdc只是一个例子,你可能会有所不同 ):
# plug in external USB drive dmesg | tail # Check which device name the plugged in drive got. lsblk # another way to verify, assuming `lsblk` is installed cat /proc/partitions # one more way to verify, sizes are in KiB fdisk /dev/sdc # Make at least one partition on the drive, minimum of 5124 MiB. pvcreate /dev/sdc1 # create the Physical Volume (PV) vgextend VG /dev/sdc1 # add the PV to the Volume Group (VG) pvmove -i 5 /dev/sdb /dev/sdc1 # Try to move every Logical Volume (LV) on PV /dev/sdb over to PV /dev/sdc1. # There's no need to unmount anything, the process is completely transparent # to the LV and anything using it. You may want to make a tea or two ;) # Watch out for errors regarding insufficient space on the target PV, tho. vgreduce VG /dev/sdb # Remove the old PV from the VG. pvremove /dev/sdb # Wipe the PV metadata from the drive. Don't continue in case of errors here! fdisk /dev/sdb # Properly partition the drive. Partition for PV should be 5124 MiB minimum. pvcreate /dev/sdb1 # Create a PV on the just created partition. vgextend VG /dev/sdb1 # Add PV to the VG. pvmove -i 5 /dev/sdc1 /dev/sdb1 # Move LVs back from the temporary PV to the freshly partitioned one. vgreduce VG /dev/sdc1 # Remove temporary PV from the VG. pvremove /dev/sdc1 # Wipe PV metadata from the drive.
在尝试之前进行备份。
给定的pv*和vg*命令是安全的,如果使用像这里所示。 如果前提条件没有得到满足,他们会拒绝工作,或者会问你是否要这样做(在这种情况下回答n )。 尤其是,当LV缩小到5 GiB时,您需要一个比5120 MiB稍大的分区(我build议增加4 MiB,因此5124 MiB),以便PV能够容纳元数据,并且会抱怨如果不是这样的话。
但是, fdisk是不安全的,它会很乐意继续你的出价,即使它会写你的宝贵的数据,所以要格外小心。