LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do I shrink a volume group once I have created free space in it? (http://www.linuxquestions.org/questions/linux-general-1/how-do-i-shrink-a-volume-group-once-i-have-created-free-space-in-it-765047/)

Mountain 10-28-2009 09:47 AM

How do I shrink a volume group once I have created free space in it?
 
I have already resized the file system and the logical volumes. Now I have free PEs in the volume group. What are the next steps to reduce the volume group?

My setup is 1 HDD with 2 partitions:
sda1 (/boot)
sda2 (LVM inside crypto)

inside the LVM is 1 VG which contains 3 logical volumes that become mounted as:
/
/home
swap
These now take up on 16.92 GB.

I want to shrink the VG from 109.42 GB to 20 GB.
Then I want to shrink sda2 down from 109 GB to 20 GB -- and keep the crypto and VG.

Here's some relevant info:

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xxxxx

Device Boot Start End Blocks Id System
/dev/sda1 * 1 309 2474010 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 310 14593 114736230 8e Linux LVM

# vgdisplay
--- Volume group ---
VG Name VgOne
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 109.42 GB
PE Size 4.00 MB
Total PE 28011
Alloc PE / Size 4331 / 16.92 GB
Free PE / Size 23680 / 92.50 GB
VG UUID xxxxx

Basically, I want to use the free space to make a new partition, sda3. sda3 will not be managed by the LVM and it will not be part of this VG. Thanks.

softbear 10-28-2009 11:37 AM

From the pvresize man page
 
Before starting, be sure to create a good, retrievable image or expect to lose your data.

In the examples section of my pvresize man page (assuming we have the same version of LVM!):
Shrink the PV on /dev/sda1 prior to shrinking the partition with fdisk (ensure that the PV size is appropriate for your intended new partition size):
pvresize --setphysicalvolumesize 40G /dev/sda1
It may fail, the user is further warned, if there are allocated extents in the area you seek to free, and that pvmove might solve that problem.

Finally, vgreduce --removemissing volgrp should clear up the volume group inconsistencies as regards the now missing PEs, and then modify the partition.

Assuming it works as documented, you won't need the backup.


N.B.: This system is not particularly current and may not have the save version of LVM. Verify on the target system. And if you're putting some other OS on sda3, have that backup handy...

Mountain 10-28-2009 06:13 PM

Quote:

Originally Posted by softbear (Post 3735497)
Before starting, be sure to create a good, retrievable image or expect to lose your data.

In the examples section of my pvresize man page (assuming we have the same version of LVM!):
Shrink the PV on /dev/sda1 prior to shrinking the partition with fdisk (ensure that the PV size is appropriate for your intended new partition size):
pvresize --setphysicalvolumesize 40G /dev/sda1
It may fail, the user is further warned, if there are allocated extents in the area you seek to free, and that pvmove might solve that problem.

Finally, vgreduce --removemissing volgrp should clear up the volume group inconsistencies as regards the now missing PEs, and then modify the partition.

Assuming it works as documented, you won't need the backup.


N.B.: This system is not particularly current and may not have the save version of LVM. Verify on the target system. And if you're putting some other OS on sda3, have that backup handy...

Thanks for the help. So far here is what I have done.
I started with this:
Code:

# pvresize --setphysicalvolumesize 20G /dev/mapper/sda2_crypt
NOTE I had to use the opened crypto volume, not sda2.
However, that failed, as anticipated, due to allocated extents. So my next step was:
Code:

# pvmove -v --alloc anywhere /dev/mapper/sda2_crypt
That's in progress...
I'll report back when it is done.

EDIT: pvmove takes about 20 minutes to finish. When finished, everything looked good (e.g., vgreduce reports all is consistent).

However, pvresize would not resize to 20G even though there is less than 20G in the used extents. So I experimented and found that pvresize worked when I set the size to 80G. That freed up over 20G for another partition.

I thought about going ahead and resizing the sda2 partiton next, but I decided to run pvmove one more time and see what happens with pvresize after that.

BTW, the backup warnings are a good reminder in general. In my case, I am working on a system set up for experimentation, so I won't care if I lose everything. I'll just start over. I'm just testing different distros. I have sidux on one partition, Chakra on another, and I'm planning to install openSUSE 11.2 RC1, Mandriva 2010, and Kubuntu Karmic (and Mythbuntu too).

Mountain 10-28-2009 08:06 PM

after running pvmove again, I was than able to run pvresize and set it to 40G, down from 80G. However, that's still far larger than the used PEs.

Code:

# pvs
  PV                    VG                  Fmt  Attr PSize  PFree
  /dev/mapper/sda2_crypt VgOne                lvm2 a-  40.00G 25.00G

However, I'll live with that for now.

Next question: how do I resize the disk partition sda2, down from 117 GB to 40GB? gparted and cfdisk won't do it because the partition type is LVM.

Mountain 10-28-2009 08:48 PM

I'm trying the instructions here:
http://www.linuxquestions.org/questi...sizing-666683/

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0xxxxx

Before:
Device Boot Start End Blocks Id System
/dev/sda1 * 63 4948082 2474010 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 4964085 234436544 114736230 8e Linux LVM


After:
Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0xxxxx

Device Boot Start End Blocks Id System
/dev/sda1 * 63 4948082 2474010 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 4964085 88850165 41943040+ 8e Linux LVM

now rebooting...

Mountain 10-28-2009 08:54 PM

It worked! :)

I used fdisk -u /dev/sda
And for the new partition I set the start sector to be the same as the original and for the end I use "+40G"

Other than that, I used the steps listed at the link.


All times are GMT -5. The time now is 07:57 PM.