Random Bits

Random Bits

  • Home
  • Contact

How to Shrink an LVM Volume Safely

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.

Related Posts:

  • Safely Removing External Drives in Linux

    Simply unmounting a filesystem is not the ideal way to...

  • Monitoring Hard Drive Health on Linux with smartmontools

    S.M.A.R.T. is a system in modern hard drives designed to...

  • Log iptables Messages to a Separate File with rsyslog

    Learn how to filter iptables log messages to a separate...

Sponsored Links:

This entry was posted on Saturday, August 30th, 2008 at 6:38 AM and is filed under Linux. You can leave a response, or trackback from your own site.

11 Comments on “How to Shrink an LVM Volume Safely”

  1. Col says:
    February 18, 2010 at 6:48 PM

    Excellent tutorial, exactly what I was after, thanks for sharing!

    Reply
  2. Anonymous says:
    July 22, 2010 at 12:48 PM

    [...] [...]

    Reply
  3. How can I minimise the size of an ext3 partition (and its LVM logical volume)? Drija says:
    November 17, 2010 at 10:31 PM

    [...] 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 [...]

    Reply
  4. m47730 says:
    January 19, 2011 at 5:24 AM

    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 :.(

    Reply
  5. 秋天的博客 » How to Shrink an LVM Volume Safely says:
    March 4, 2011 at 9:43 PM

    [...] http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/ [...]

    Reply
  6. Vincent's Memo » Blog Archive » lvm – shrink lvm volume says:
    June 4, 2011 at 9:18 AM

    [...] Reference URL: http://blog.shadypixel.com/how-to-shrink-an-lvm-volume-safely/ [...]

    Reply
  7. How To : Shrink LVM Volume Safely | masrust.web.id says:
    July 31, 2011 at 10:31 PM

    [...] source This entry was posted in Computer, Linux and tagged centos, computer, debian, distro, fedora, how to, komputer, Linux, lvm, mandriva, online, opensource, opensuse, partition, redhat, server, ubuntu by masrust. Bookmark the permalink. [...]

    Reply
  8. How can I minimise the size of an ext3 partition (and its LVM logical volume)? - Admins Goodies says:
    August 20, 2011 at 6:18 AM

    [...] 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 [...]

    Reply
  9. Natuerliche Arzneimittel says:
    September 16, 2011 at 5:40 AM

    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?

    Reply
  10. Squeeze Dual Root With Single Userspace says:
    December 21, 2011 at 8:57 PM

    [...] their own unique IDs. The only option wold be to extract some free space from your existing disk (http://blog.shadypixel.com/how-to-sh…volume-safely/) and create a new /usr partition (non-LVM) and move your data to this partition , later on you can [...]

    Reply
  11. Vkram says:
    January 3, 2012 at 11:10 AM

    # 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

    Reply

Leave a Reply

Click here to cancel reply.

  • Topics

    • Personal (2)
    • Technology (13)
      • Linux (11)
      • Web (4)
  • Meta

    • Register
    • Log in
    • Valid XHTML

Feed | Privacy Policy
Copyright © 2008-2009 Random Bits
Powered by Wordpress