5

My partition detail is like this

/dev/mapper/VolGroup00-LogVol00
                       57G  8.8G   46G  17% /
/dev/mapper/VolGroup00-LogVol05
                      259G  7.0G  239G   3% /home
/dev/mapper/VolGroup00-LogVol02
                       19G  493M   18G   3% /var
/dev/mapper/VolGroup00-LogVol03
                       19G  458M   18G   3% /tmp
/dev/mapper/VolGroup00-LogVol04
                      9.5G  152M  8.9G   2% /opt
/dev/sda1             965M   33M  883M   4% /boot
tmpfs                 7.7G  3.7G  4.0G  48% /dev/shm

I want to increase the size of the / by reducing the size of the /home partition, without lose of data in the / and home.

Can anybody help me in solving this issue?

1
  • 1
    It's a good idea to leave unallocated space in the volume group to hand out to needy LVs in future. It's part of the benefits of using LVM. Otherwise you end up in this situation.
    – Allen
    Jun 7, 2009 at 17:45

5 Answers 5

5
  • Boot with a live distro (lvm capable)
  • don't mount your lvm partitions
  • fsck LogVol00 and LogVol05 (twice this step)
  • lvreduce -L-xG /dev/VolGroup00/LogVol05
  • resize2fs -p /dev/VolGroup00/LogVol05

do the same for /dev/mapper/VolGroup00-LogVol00 with lvextend instead of lvreduce

1
  • 2
    This assumes Charly is using ext. While most filesystems can be shrunk no problem, XFS (for example) can only be grown, never shrunk.
    – Scott Pack
    May 28, 2009 at 13:09
1

I second vishaal's answer, however he left out a couple steps..as well as the fact you can do this with linux rescue

  1. Boot into linux rescue
  2. skip mounting
  3. run lvm vgchange -a y (in rescue mode you preface the commands with lvm)
  4. verify visibility by OS with ls /dev/VolGroup00/
  5. The rest is much like vishaal described, but you'll want to force the e2fsck with a -f ie: e2fsck -f /dev/VolGroup00/LogVol..

  6. IMPORTANT, you resize the filesystem before you reduce the volume, so..

  7. resize2fs -f /dev/VolGroup00/LogVol.. 40G (if you wanted the size to be exactly 40G)
  8. lvm lvreduce -L40G /dev/VolGroup00/LogVol.. (again if you wanted the size to be exactly 40G and not reduced by 40G)

Mine is simply an addition to what advice vishaal has already given.

0

A minor tweak to the process given by vishaal and Bobby Cox:

  • resize2fs the /home LV down to a bit smaller than you really want
  • lvm lvreduce it down to the size you really want
  • resize2fs it back up to fill the LV (by not specifying a size)

This leaves a safety margin on the off-chance that the two commands interpret explicit sizes differently (I know the lvm commands round to an integer number of Extents; how the default Extent size is determined I'm not sure, and don't really care).

When increasing an LV's size the procedure is somewhat simpler:

  • lvm lvextend to the size you want
  • resize2fs to fill
0

You don't have to reboot to do this; however make sure you have a fresh backup at hand.

  • Close all your user sessions.
  • Login as root. If you need to login as a user first, use "exec su -" or "exec sudo -i" so as not to leave your user logged in and preventing a clean umount
  • Find out if anything is still using /home with "lsof -n | grep /home"; terminate the processes that do
  • umount /home
  • Figure the new size you want in bytes, make it a multiple of the LVM extents size, let's call it $newsize
  • fsck /dev/mapper/VolGroup00-LogVol05
  • resize2fs -P /dev/mapper/VolGroup00-LogVol05 $newsize
  • lvreduce -L $newsze /dev/mapper/VolGroup00-LogVol05
  • mount /home

That's, of course, assuming you use ext[234].

0

Want to re-iterate:

When shrinking, resize the FS first then resize the LVM When extending, resize the LVM first, then resize the FS.

When shrinking, you do need to umount the volume. When extending, depending on your linux kernel, you can do it online while system is mounted

When shrinking, crucial to have backups When extending, very very very very good idea to have backups (when is it not) but not as risky as when shrinking

Other than that, everyone else is spot on

2
  • The -r option to lvreduce handles this for you. Feb 21, 2014 at 1:08
  • :D sysadmins are creatures of habit. Hadn't heard of that, thanks!!
    – ben
    Mar 4, 2014 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .