How can I either free up enough space on root or resize my partitions?

5,538

Since you went back to the previous Snapshot you could boot from a LIVE CD that supports LVM Partitions (Like SYSTEM RESCUE CD ) maybe read a little just to start on working with LVM Partitions. Anyway the normal steps there are after booting from the live cd (This are going to be several command lines not gui bases):

  1. Do NOT mount any of the LVM (Obvious reasons. you are going to resize it so do not mounted yet.)
  2. Do a fsck to the partition you want to change. Just in case.
  3. First do e2fsck -f PARTITION
  4. Since we want to remove space from /home and give it to root we do:
    4.1. Do resize2fs PARTITION SIZE or resize2fs -f PARTITION SIZE to the HOME partition before you use lvreduce on it. Remember that you MUST have enough space free for the final size after the resize is made. Do a resize2fs -p on the new home partition size just to make sure it has the correct block size.
    4.2 Use lvextend on the ROOT partition and then do resize2fs PARTITION SIZE or resize2fs -f PARTITION SIZE on it. And do again a resize2fs -p on it to make sure it has the correct block size.

NOTE - After doing lvreduce or lvextend to each partition you need to do e2fsck -fn to force a check on the partition for consistency (It will read-only the partition and check if even if it is clean)

An example for the lvm tools:

lvreduce -L -35G "Home Partition" - Home Partition will have 35GB less.
lvextend -L +35G "Root Partition" - Root Partition will have 35GB more.

Hope this helps in figuring out how to do it and with the snapshots am guessing you will.

UPDATE - After doing a curious search found another user from Red Hat, similar problem: https://serverfault.com/questions/13666/how-can-i-resize-a-lvm-partition-in-red-hat-without-lose-of-data

UPDATE2 - Added what psusi says in the comments since THAT is the correct way and i need to drink coffee before reading/writing something.

UPDATE3 - Thank psusi below for the several corrections.

NOTE - This is for partitions made with ext2/3/4 and am guessing blocks that are not 1K/2K since i read somewhere that it did not work for them (Not tested since i have 512 Bytes)

Share:
5,538

Related videos on Youtube

Kenneth Cochran
Author by

Kenneth Cochran

Updated on September 18, 2022

Comments

  • Kenneth Cochran
    Kenneth Cochran almost 2 years

    I'll start my saying that although I've used Ubuntu for a number of years I've rarely taken the time to explore Linux under the hood. I've been content to rely on GUI tools for most of my needs, only resorting to a terminal when a suitable GUI tool could not be found.

    A few weeks back I did a default install of the Zentyal (ebox) distro and set up an email server for a school. Unfortunately, the default file system configuration allocated only three partitions:

    • / - 6GB
    • swap - 4GB
    • /home - 96GB

    After being in operation for only a few weeks the root parition has filled and has taken the server to its knees. So I need to find a way to either resize or free up space in the root partition.

    I've been able to figure out that the space hog is /var, the file system was setup using lvm and that both / and /home are in the same volume group. I've attempted booting from a live cd so I could shrink /home and enlarge /. I'm more comfortable with GUI tools so I used system-config-lvm. The odd thing is that from the live cd it showed the /home partition (or volume or whatever its called) as not having a file system at all. When I log in normally I can see that it is in fact using ext4.

    This server is running as a vmware guest so I made a snapshot and went ahead and tried to resize. Everything appeared to resize without error however, after rebooting I was informed that /home could no longer be mounted. The only account that needs the /home folder is the server administrator (me) but apparently Zentyal must use it for something because I couldn't access Zentyal's web interface and the server wasn't receiving any emails.

    So I reverted to the snapshot I had taken and here I sit. No closer to solving this problem than I was before.

    Any help would be appreciated.

  • psusi
    psusi over 13 years
    -1: resise2fs without a size argument will INCREASE the size of the fs to fill the whole device. You need to specify a size to SHRINK it first, and THEN use lvreduce to shrink the logical volume. The one you are expanding you do in the reverse order like you said. Also -L35G sets the size to 35G, if you want to reduce it by 35G you need -L-35G, and -L+35G to add.
  • Luis Alvarado
    Luis Alvarado over 13 years
    You are totally correct forgot about that. Did not mention it correctly but just for note am using resize2fs -P which shows the amount of blocks the partition has. Am not using it to resize.
  • Luis Alvarado
    Luis Alvarado over 13 years
    Updated with the stuff psusi mention.
  • psusi
    psusi over 13 years
    You didn't fix the part about resize2fs. You need to shrink the fs with resize2fs first or you will corrupt the fs when you lvreduce it. You also should run e2fsck -fn after the lvreduce to make sure you didn't mess it up, and if it complains, extend it back and that should undo the damage before it becomes permanent.
  • Luis Alvarado
    Luis Alvarado over 13 years
    -.- OK i am dumb today. Did not have my coffee today. Added
  • psusi
    psusi over 13 years
    4) is still not quite right. Extend and reduce are mirror images of each other; you resize then reduce, or extend and then resize. Also block size and sector size are two different things. Most hard drives have a 512 byte sector size, but the smallest block size ext[234] can use is 1024 bytes, and only on very small filesystems ( like 1.44 mb floppies ). Virtually all ext[234] filesystems today use a 4kb block size.
  • Kenneth Cochran
    Kenneth Cochran over 13 years
    gparted doesn't support LVM.
  • Luis Alvarado
    Luis Alvarado over 13 years
    There you go buddy