LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (http://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   Shrink LVM without dataloss (http://www.linuxquestions.org/questions/linux-enterprise-47/shrink-lvm-without-dataloss-557746/)

stry_cat 05-30-2007 08:38 AM

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?

mastrboy 05-30-2007 10:29 AM

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.

stry_cat 05-30-2007 01:49 PM

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.

twantrd 05-31-2007 07:44 PM

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

brianmcgee 06-12-2007 02:54 AM

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 !!!

ernst 04-15-2008 09:44 PM

shrink LVM volume without data loss
 
Quote:

Originally Posted by brianmcgee (Post 2784317)
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!

kobayashison 11-13-2010 05:49 AM

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

viral.infection2000 04-21-2011 02:36 AM

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

gattler 06-14-2011 09:32 PM

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


All times are GMT -5. The time now is 02:36 PM.