LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 05-30-2007, 08:38 AM   #1
stry_cat
LQ Newbie
 
Registered: Apr 2005
Posts: 12

Rep: Reputation: 0
Question Shrink LVM without dataloss


I want to shrink a partition using LVM. There is some data already on that partition and I don't want to have to end up restoring from backup.

Here's what I've got so far...

I'm using RHEL5. I have two harddrives (/dev/sda and /dev/sdb). I'm using LVM. VolGroup00 and the main OS stuff are completely on /dev/sda.

I have another volume group called VG_Guests that is completely on /dev/sdb. In this group there is an lv called RH9 (there are two other lv's in this group that I don't want to touch). The one I want to shrink is currently 35G. I want to shrink it to 20G.

What I've figured out so far...

I need to first umount it (no problem there).
I need to run resize2fs first, then lvreduce.
After that I can remount it and it should be the new reduced size.

My problem...What options do I give resize2fs and lvreduce?

What I'd like to try is:
resize2fs /dev/VG_Guests/RH9 -15G
lvreduce -L -15G /dev/VG_Guests/RH9

Should I go for it or have I missed something? Is there a gui for doing this in RHEL5?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-30-2007, 10:29 AM   #2
mastrboy
Member
 
Registered: Aug 2005
Distribution: Debian, OpenBSD, PFsense
Posts: 73

Rep: Reputation: 15
if you are very unsure you should test in vmware first
but here is a good read for LVM: http://www.red-hat.com/docs/manuals/...ger/index.html

edit: forgot gui

In addition to the Command Line Interface (CLI), LVM provides a Graphical User Interface (GUI) which you can use to configure LVM logical volumes. You can bring up this utility by typing system-config-lvm. The LVM chapter of the Red Hat Enterprise Linux Deployment Guide provides step-by-step instructions for configuring an LVM logical volume using this utility.

Last edited by mastrboy; 05-30-2007 at 10:30 AM.
 
Old 05-30-2007, 01:49 PM   #3
stry_cat
LQ Newbie
 
Registered: Apr 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by mastrboy
if you are very unsure you should test in vmware first
but here is a good read for LVM: http://www.red-hat.com/docs/manuals/...ger/index.html
That doesn't really say much about shrinking. It doesn't even tell me how to reduce the file system, only provides a big red warning about you need to reduce the file system first.

Quote:
edit: forgot gui

In addition to the Command Line Interface (CLI), LVM provides a Graphical User Interface (GUI) which you can use to configure LVM logical volumes. You can bring up this utility by typing system-config-lvm. The LVM chapter of the Red Hat Enterprise Linux Deployment Guide provides step-by-step instructions for configuring an LVM logical volume using this utility.
Thank! This looked like it was going to work, however it failed saying:

Code:
Check of filesystem failed. Command attempted: "/sbin/e2fsck -f -p /dev/VG_Guests/RH9" - System Error Message: 

/: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
	(i.e., without -a or -p options)
No I'm really scared. The last time I attemped to use fsck, I had to reinstall from scratch.
 
Old 05-31-2007, 07:44 PM   #4
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
I have never shrunk a filesystem under LVM but I have a 100% success rate when I'm growing it. Since you can't mount this anymore, you have to run 'fsck' against it. Let us know how it goes. Also, it's a 35gig filesystem so restoring it isn't so bad. I had to restore a 17TB filesystem once and that wasn't pretty at all.

-twantrd
 
Old 06-12-2007, 02:54 AM   #5
brianmcgee
Member
 
Registered: Jun 2007
Location: Munich, Germany
Distribution: RHEL, CentOS, Fedora, SLES (...)
Posts: 399

Rep: Reputation: 40
Shrinking volume from 10G to 9G:

While online enlarging is no problem, you have to umount for shrinking!
Code:
# umount /dev/vg_blah/lv_blah
Perform a check of the filesystem...
Code:
# e2fsck -f /dev/vg_blah/lv_blah
Resize the filesystem first.
Code:
# resize2fs /dev/vg_blah/lv_blah 9G
Then reduce the size of the logical volume.
Code:
# lvreduce -L -1G /dev/vg_blah/lv_blah
After that you can shrink down the volume group if desired.
Code:
# vgreduce vg_blah /dev/sdxy
Warning: It is crucial that you use the exact amount of space. If you reduce volume more than the filesytem you truncate the logical volume and you risk data loss!

!!! I WOULD NEVER SHRINK A FILESYSTEM WITHOUT A BACKUP !!!
 
3 members found this post helpful.
Old 04-15-2008, 09:44 PM   #6
ernst
Member
 
Registered: May 2006
Location: Sydney
Distribution: Debian etch, SkoleLinux
Posts: 77

Rep: Reputation: 15
shrink LVM volume without data loss

Quote:
Originally Posted by brianmcgee View Post
Shrinking volume from 10G to 9G:

While online enlarging is no problem, you have to umount for shrinking!
Code:
# umount /dev/vg_blah/lv_blah
Perform a check of the filesystem...
Code:
# e2fsck -f /dev/vg_blah/lv_blah
Resize the filesystem first.
Code:
# resize2fs /dev/vg_blah/lv_blah 9G
Then reduce the size of the logical volume.
Code:
# lvreduce -L -1G /dev/vg_blah/lv_blah
After that you can shrink down the volume group if desired.
Code:
# vgreduce vg_blah /dev/sdxy
Warning: It is crucial that you use the exact amount of space. If you reduce volume more than the filesytem you truncate the logical volume and you risk data loss!

!!! I WOULD NEVER SHRINK A FILESYSTEM WITHOUT A BACKUP !!!
Brian,
I followed your procedure with success.
First I made a backup.
Then I decided how much is empty in the volume with
#df -h

Because I could not unmount (in use) I booted a Knoppix live-CD.
Then activate the volume in question
#lvchange -ay <vol>

Then continued from # e2fsck in your procedure.

Thank you!
 
Old 11-13-2010, 05:49 AM   #7
kobayashison
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
A tip.
To be sure not to crop the filesystem when I reduce lv, I reduce the filesystem a bit more than the final size, lvreduce to the desired size and then resize again the filesystem to fill the lv container.
In this case:
Code:
resize2fs /dev/vg_blah/lv_blah 8G
lvreduce -L -1G /dev/vg_blah/lv_blah
resize2fs /dev/vg_blah/lv_blah
The last resize2fs grow the 8G filesystem to fill the about 9G partition
 
Old 04-21-2011, 02:36 AM   #8
viral.infection2000
LQ Newbie
 
Registered: Apr 2011
Location: In a house
Distribution: Centos
Posts: 1

Rep: Reputation: 0
Shrink LVM without dataloss

Hi All

Thanks Brian
Like ernst i was able to follow your instructions and was able to resize the file system
and then the Logical Volume and was going so well but hit a brick wall with the resize of
the volume group .

Story so far , did a quick install of Centos 5 and did not take sufficient notice of the fact that
it grabbed the whole 500Gb drive for the install .
I wanted to reduce the install to only 100Gb of the drive .
so i searched and found your instructions which ( on a clone of the original drive )
i then proceeded to follow with hope and trepidation . ( i break things :-) )
Booting from a boot CD
i get to the last command all has been sweet to that point and it reports
"" still in use "" .
Can anyone be more specific about that commend ?
I want to reduce the VolGroup00 so that i can format the remaining drive for another project.
currently VolGroup00 = 500Gb
LogVol00 = 100Gb
drive is a SATA 500Gb

Thanks for any pointers
Very much a newbie
 
Old 06-14-2011, 09:32 PM   #9
gattler
LQ Newbie
 
Registered: Nov 2010
Posts: 5

Rep: Reputation: 0
The last command, the most important one, wasn't explained enough, could someone please elaborate how to extract the free space from the Volume Group and "map" it to a Physical Volume?

Code:
vgreduce vg_blah /dev/sdxy
Wouldn't be a "pvresize /dev/saxy 8G" the correct command to use here?

For the GUI, on Fedora or RHEL just do a

Code:
yum install system-config-lvm
system-config-lvm
How-To: http://www.centos.org/docs/5/html/De...onfig-lvm.html

Last edited by gattler; 06-14-2011 at 10:05 PM.
 
Old 03-16-2015, 04:04 PM   #10
lnrdo1
LQ Newbie
 
Registered: Mar 2015
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by gattler View Post
The last command, the most important one, wasn't explained enough, could someone please elaborate how to extract the free space from the Volume Group and "map" it to a Physical Volume?

Code:
vgreduce vg_blah /dev/sdxy
Wouldn't be a "pvresize /dev/saxy 8G" the correct command to use here?
For future reference who still have interests in this topic, I make a reply to this old question.

The case of the original question is that Volume Group is composed of several Physical Volumes which actually represents physical device (or partition). Therefore you can just shrink volume group by excluding physical volume.
In the case that you want to reduce the size of physical volume itself,
Code:
pvresize --setphysicalvolumesize 8G /dev/sdxy
Refer to the man page of pvresize. This command works only when 8G bytes are enough for allocated PE's.
In case that PE allocation is not linear, say, some of PE at the last parts are allocated, pvresize fails. In that case, you have to move PE first, and next pvresize:
Code:
pvmove --alloc anywhere  -n lvname /dev/sdaxy /dev/sdaxy
Refer to the man page of pvmove. The last two arguments for source and destination should be same in this case, since you are moving PE inside the physical volume.

Next I simply used Gparted, and now it sees free space, and enables modification. I also used system-config-lvm to make the free space inside volume group itself. It's easy and safe to use that tool to reduce the size of logical volume with that tool, but it does not allow to convert the free space to a new partition.

Last edited by lnrdo1; 03-16-2015 at 08:43 PM. Reason: Incorrect info modification
 
Old 04-02-2015, 01:49 AM   #11
royujjal
LQ Newbie
 
Registered: Apr 2015
Posts: 1

Rep: Reputation: Disabled
Smile These are all the steps required to resize a LVM or LVM2 partition

sudo lvresize --verbose --resizefs -L -150G /dev/ubuntu/root

sudo pvresize --setphysicalvolumesize {any size here} /dev/sda5

/dev/sda5: cannot resize to xxxxx extents as later ones are allocated.

You have to rearrange the unallocated space at the end of the LVM. That means after root and swap_1 partition. So, you need to move that free space using the command below

pvs -v --segments /dev/sda5

This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx yyyy 0 free
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyyy end swap 0 linear /dev/sda5:yyyy-end
Now use the command below to remove external fragmentation -

sudo pvmove --alloc anywhere /dev/sda5:yyyy-end
Now let us see how it goes -

pvs -v --segments /dev/sda5

This will show the output like below
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g 0 xxx root 0 linear /dev/sda:0-xxx
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g xxx yyyy swap 0 linear /dev/sda5:xxx-yyyy
/dev/sda5 ubuntu lvm2 a-- 698.04g 150g yyyy end 0 free
After that use the gparted and resize the LVM to maximum used area and rest will be in unallocated space. Enjoy...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Back Up (And Restore) LVM Partitions With LVM Snapshots LXer Syndicated Linux News 0 04-17-2007 11:16 AM
DVD Shrink pblogic Linux - Software 7 03-20-2005 11:13 AM
Change file system, no dataloss? Moist Linux - Newbie 9 03-07-2005 12:37 PM
DVD Shrink zebbedi Linux - Software 3 10-06-2003 10:52 AM
A sob story about dataloss--any help appreciated chort Linux - Hardware 2 07-08-2003 12:58 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 05:35 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration