减小现有 VolumeGroup 的大小以创建新的 PhysicalVolume

减小现有 VolumeGroup 的大小以创建新的 PhysicalVolume

我有一台测试机,它设置了 CentOS 6 的默认分区设置。

[root@base_machine ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      7.5G  936M  6.3G  15% /
tmpfs                 246M     0  246M   0% /dev/shm
/dev/sda1             477M   57M  395M  13% /boot

最初,LV 是这样设置的:

[root@base_machine ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                irl20b-p6jE-y7Vi-3QlF-fVGf-zhr5-2SrU0K
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-09-10 20:51:26 +0530
  LV Status              available
  # open                 1
  LV Size                6.71 GiB
  Current LE             1718
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                DBDWBm-SjBB-OtDa-wRFC-uBTc-kWE8-j2De1R
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-09-10 20:51:28 +0530
  LV Status              available
  # open                 1
  LV Size                816.00 MiB
  Current LE             204
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

我使用 释放了一些空间lvresize,如下所示:

[root@base_machine ~]# lvresize -L -1024M /dev/VolGroup/lv_root
  WARNING: Reducing active and open logical volume to 5.71 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_root? [y/n]: y
  Size of logical volume VolGroup/lv_root changed from 6.71 GiB (1718 extents) to 5.71 GiB (1462 extents).
  Logical volume lv_root successfully resized

因此,VolumeGroup 中现在有 1GB 的可用大小:

root@base_machine ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.51 GiB
  PE Size               4.00 MiB
  Total PE              1922
  Alloc PE / Size       1666 / 6.51 GiB
  Free  PE / Size       256 / 1.00 GiB
  VG UUID               BRzfQl-CIJO-YYno-y9dj-TLnY-NLeb-paN9N7

我现在如何释放上述 1 GB 来创建新的 PV?目的是创建一个新分区,例如/dev/sdb,或类似的东西 - 这是为了测试磁盘调整大小/LVM 等。

答案1

你可以试试pvresize --setphysicalvolumesize 6.51G /dev/sda1。我很确定,这不会起作用,因为它很可能lv_swap分配在 6.51G 边界后面。

所以我认为你lv_swap也应该删除并重新创建:

swapoff /dev/VolGroup/lv_swap
lvremove /dev/VolGroup/lv_swap
pvresize --setphysicalvolumesize 6G /dev/sda2

然后将分区大小调整到6.5G左右(或稍大一些)。之后,您应该运行 apvresize /dev/sda2来回收“稍微大一点”产生的空间。然后你可以重新创建lv_swap

lvcreate -n lv_swap -l 100%FREE VolGroup
mkswap /dev/VolGroup/lv_swap
swapon /dev/VolGroup/lv_swap

相关内容