How do I shrink a volume group once I have created free space in it?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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 --setphysicalvolumesize40G /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...
Last edited by softbear; 10-28-2009 at 01:30 PM.
Reason: Missed first and final steps. Grammar.
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 --setphysicalvolumesize40G /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:
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).
Last edited by Mountain; 10-28-2009 at 08:37 PM.
Reason: update
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.