Logical Volume Management is a vast improvement over standard partitioning schemes. Among many other things, it allows you to decrease the size of a volume without recreating it completely. Here’s how.
First, as is always the case when you’re modifying disk volumes, partitions, or file systems, you should really have a recent backup. A typo in one the following commands could easily destroy data. You have been warned!
All of the required steps must be performed on an unmounted volume. If want to reduce the size of a non-root volume, simply unmount it. For a root volume, you’ll have to boot from a CD. Any modern live or rescue CD should work fine. I prefer SystemRescueCD. It includes almost any disk management programs you might need. After booting from a CD, you may have to issue:
# vgchange -a y
This makes any logical volumes available to the Linux. Most boot CD’s will do it automatically some time during the boot process, but repeating the command won’t hurt. Next, force a file system check on the volume in question:
# e2fsck -f /dev/polar/root
Device names for LVM volumes follow the convention: /dev/<volume group>/<logical volume>. In this case, my volume group is named polar and the volume I’m going to shrink is named root. This is a critical step; resizing a file system in an inconsistent state could have disastrous consequences. Next, resize the actual file system:
# resize2fs /dev/polar/root 180G
Replace 180G with about 90% of the size you want the final volume to be. For example, in this case, I want the final volume to be 200 gigabytes, so I’ll reduce the file system to 180 gigabytes. Why is this necessary? When we reduce the size of the actual volume in the next step, it’s critical that the new size is greater than or equal to the size of the file system. After reading the documentation for both resizefs and lvreduce, I still haven’t been able to find out whether they’re using standard computer gigabytes (1024^3 bytes) or drive manufacturer gigabytes (1000^3 bytes). In this case, the difference is very important. To be on the safe side, we’ll just shrink the file system a bit more than necessary and expand it to use the full space available later. Next, reduce the size of the logical volume:
# lvreduce -L 200G /dev/polar/root
In this case, use the actual size you want to the volume to be. Finally, grow the file system so that it uses all available space on the logical volume:
# resize2fs /dev/polar/root
That’s it. Enjoy your newly acquired free space.
Excellent tutorial, exactly what I was after, thanks for sharing!
[...] [...]
[...] affect the logical volume. Most of the recipes on the web for shrinking ext3 inside an LV (e.g. this one), follow this basic pattern to alleviate problems with inaccurate calculations of filesystem [...]
Great tutorial!
Be aware to unmount volume and be certain that the command doesn’t give you errors, otherwise you destroy the filesystem! By expirience :.(
[...] http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/ [...]
[...] Reference URL: http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/ [...]
If you are not careful, you can shrink the LV to a size less than what is required by the file system. If the LV is resized smaller than what the file system has been resized to, things will go very badly for you. Did I mention you should backup your data before hand?
# lvreduce -L 200G /dev/polar/root
Under RHEL5.6 this command is like wrong turn. Beside reducing the size its make the LV size 200M, Dangreous for real experiment.
This is a right comman which reduce the size.
# lvreduce -L -200G /dev/polar/root
@Vkram the requirement is to change the size to 200G and not to remove 200G from the Logical Volume. So the initial command is correct.
What is the difference between:
# lvreduce -L 200G /dev/polar/root and
# lvreduce -L 200G /dev/polar/root ??
hello,
lvreduce or lvextend can automaticaly resize fs with -r flag
lvreduce -r -L 200G /dev/polar/root
have fun
I wanted to post you the very small word just to give many thanks as before regarding the unique concepts you have shown here. It was extremely generous of people like you to make extensively all that many people could have made available for an ebook to end up making some dough for their own end, especially given that you could possibly have tried it if you ever considered necessary. These basics additionally served to provide a great way to understand that the rest have a similar dream like my very own to grasp somewhat more regarding this issue. I’m certain there are millions of more enjoyable periods in the future for individuals who look over your blog post.
1 GB = 1 gigabyte = 1000 migabytes, while 1 GiB = 1 gibibyte = 1024 mibibytes, see http://en.wikipedia.org/wiki/Gigabyte
Thank you so much for clarifying this.
Today, I went to the beachfront with my kids. I found a sea shell and gave it to
my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear. She never wants to
go back! LoL I know this is totally off topic but I had to tell someone!
Thanks for sharing.. Amazing post. Really helpful..