LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 10-28-2009, 09:47 AM   #1
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Rep: Reputation: 33
Arrow 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.
 
Old 10-28-2009, 11:37 AM   #2
softbear
LQ Newbie
 
Registered: Sep 2005
Location: Long Island, NY
Distribution: Slackware
Posts: 19

Rep: Reputation: 0
Post 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...

Last edited by softbear; 10-28-2009 at 12:30 PM. Reason: Missed first and final steps. Grammar.
 
Old 10-28-2009, 06:13 PM   #3
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by softbear View Post
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).

Last edited by Mountain; 10-28-2009 at 07:37 PM. Reason: update
 
Old 10-28-2009, 08:06 PM   #4
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 33
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.
 
Old 10-28-2009, 08:48 PM   #5
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 33
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...
 
Old 10-28-2009, 08:54 PM   #6
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 33
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.

Last edited by Mountain; 10-28-2009 at 08:55 PM. Reason: added instructions
 
  


Reply

Tags
lvm, lvm2, partitioning


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
lvm2 Newly created Volume Group lost after reboot seanikins Linux - Newbie 5 04-11-2010 12:55 PM
LVM2 volume size / free space ,mismatch Grismar Linux - Newbie 4 09-28-2009 03:47 AM
how can increase my physical volume group space in linux ilu_nishant Linux - Newbie 3 09-12-2009 01:41 PM
Gparted not letting me shrink Vista partition despite free space allele Linux - Software 5 06-24-2009 06:37 AM
LVM - Extending logical volume - Insufficient free space deim Linux - Newbie 0 04-07-2007 09:47 PM


All times are GMT -5. The time now is 03:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration