2

I have test machine that is set up with default partition settings for 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

Initially, this was how the LV was set up:

[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

I freed up some space using lvresize, like so:

[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

Hence, there's now 1GB of Free Size in the VolumeGroup:

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

How would I now go about freeing up the said 1 GB to create a new PV? The aim is to create a new partition, like /dev/sdb, or something similar - this is for testing out disk-resizing/LVM etc.

  • I don't understand, what's stopping you from creating a new lv? That 1GB is already "free", you just need to use it. – cristi Nov 17 '15 at 14:30
0

You can try pvresize --setphysicalvolumesize 6.51G /dev/sda1. I am pretty sure, this won't work because it's likely that lv_swap is allocated behind the 6.51G border.

So I think you should remove and recreate lv_swap as well:

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

Then resize the partition to around 6.5G (or slightly bigger). After that you should run a pvresize /dev/sda2 to reclaim the space produced by the "slightly bigger". Then you can recreate lv_swap:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.