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? |
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. |
Quote:
Quote:
Code:
Check of filesystem failed. Command attempted: "/sbin/e2fsck -f -p /dev/VG_Guests/RH9" - System Error Message: |
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 |
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 Code:
# e2fsck -f /dev/vg_blah/lv_blah Code:
# resize2fs /dev/vg_blah/lv_blah 9G Code:
# lvreduce -L -1G /dev/vg_blah/lv_blah Code:
# vgreduce vg_blah /dev/sdxy !!! I WOULD NEVER SHRINK A FILESYSTEM WITHOUT A BACKUP !!! |
shrink LVM volume without data loss
Quote:
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! |
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 |
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 |
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 For the GUI, on Fedora or RHEL just do a Code:
yum install system-config-lvm |
Quote:
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 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 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. |
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... |
All times are GMT -5. The time now is 07:14 AM. |