I was trying to install a database from a local rpm using yum -localinstall but it failed updating the dependencies because there wasn't enough space on my /usr/lib directory.
The problem was, way back when I installed Fedora 9, I never gave /usr/lib its own filesystem – it was sharing an 8 GB filesystem with /. Clearly this was an oversight.
Fortunately Fedora 9 uses logical volumes by default, and reducing and extending file systems with logical volumes is a cinch.
Here's how my file systems looked before the start of this exercise:
[root@localhost ~]# df -k
| Filesystem | 1K-blocks | Used | Available | Use% | Mounted on |
| /dev/mapper/VolGroup00-LogVol00 | |||||
| 8256952 | 5437692 | 2399832 | 70% | / | |
| /dev/mapper/VolGroup00-LogVol02 | |||||
| 4257464 | 345632 | 3695564 | 9% | /home | |
| /dev/mapper/VolGroup00-LogVol03 | |||||
| 4257464 | 1137560 | 2903636 | 29% | /opt | |
[root@localhost ~]#
(I've left out the filesystems that aren't relevant to this discussion)
You don't have to login as root to run this command but since we will need to run later commands as root its a good idea to start now.
By the way lvm2 uses something called device-mapper so df shows the name /dev/mapper/VolGroup00-LogVol00 for a filesystem that you call /dev/VolGroup00/LogVol00 and so on.
As you can see my / filesystem had only about 2.3 GB available – evidently not enough for a greedy application like a database and all its dependencies – whereas my /home filesystem was only 9% full.
I decided to reduce the size of /home down to, say, 2 GB, which would free up over 2 GB of space (I'll do the fine arithmetic in a minute), which I would then allow my / filesystem to gobble up.
The arithmetic:
Lvm2 allocates logical volumes in integral multiples of something called the 'physical extent size' (or 'PE size'). This can vary from system to system and you need to know what it is. To find out what yours is:
[root@localhost ~]# pvdisplay | grep 'PE Size'
PE Size (KByte) 32768
[root@localhost ~]#
This shows my PE size to be 32 MB. Therefore logical volumes on my system may have any size that is an integral multiple of 32 MB. Run this command on your system and remember what your PE size is.
Now we need to know how many PE's each filesystem occupies:
[root@localhost ~]# lvdisplay | grep '\(LV Name\|Current LE\)'
LV Name /dev/VolGroup00/LogVol00
Current LE 256
LV Name /dev/VolGroup00/LogVol02
Current LE 132
LV Name /dev/VolGroup00/LogVol03
Current LE 132
LV Name /dev/VolGroup00/LogVol01
Current LE 112
[root@localhost ~]#
So:
/dev/VolGroup00/LogVol00 occupies 256 * 32 MB = 8192 MB (this is /)
/dev/VolGroup00/LogVol02 occupies 132 * 32 MB = 4224 MB (this is /home)
/dev/VolGroup00/LogVol03 occupies 132 * 32 MB = 4224 MB (this is /opt)
/dev/VolGroup00/LogVol01 occupies 112 * 32 MB = 3584 MB (this is swap)
I am going to reduce the size of my /home filesystem from 4224 MB down to 2048 MB, which will free up exactly 2176 MB of space. I am then going to allow my / filesystem to expand into this, increasing it in size from 8192 MB to 10368 MB.
Reduce the size of /home
Now for the fun part:
First, let's reduce /home.
Prior to linux kernel 2.6 you had to unmount a filesystem before resizing it, which clearly presents a problem if its a filesystem such as / or /home that you want to resize. Starting with linux kernel 2.6 you can extend ext3, and some other filesystem types, while they are mounted. My filesystems are all ext3 (use df -T to find out the type). However you still have to unmount the filesystem to reduce it in size.
So the first thing to do is to logout your ordinary user and login as root – you don't want to be using the /home filesystem when you umount it.
Next, run the following commands:
Unmount the /home filesystem:
[root@localhost ~]# umount /home
Run a check on the filesystem (/dev/VolGroup00/LogVol02 is where my /home lives):
[root@localhost ~]# e2fsck -f /dev/VolGroup00/LogVol02
e2fsck 1.41.0 (10-Jul-2008)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup00/LogVol02: 1606/270336 files (8.4% non-contiguous), 103386/1081344 blocks
[root@localhost ~]#
Warning: Never run this command (e2fsck) on a mounted filesystem.
Now reduce the size of the filesystem. Choose a size that accommodates your existing data (The Used column in the df display) while allowing room for growth. The size you specify does not have to be an integral multiple of your PE size (that comes in with the lvreduce command). I am going to temporarily reduce it below the target size (2048 MB) and then nudge it back up again after running lvreduce:
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol02 2000M
resize2fs 1.41.0 (10-Jul-2008)
Resizing the filesystem on /dev/VolGroup00/LogVol02 to 512000 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol02 is now 512000 blocks long.
[root@localhost ~]#
Now reduce the size of the logical volume. lvreduce is clever enough to round up the size you specify to an integral multiple of your PE size, although in this case our target size happens to be an integral multiple of my PE size:
[root@localhost ~]# lvreduce -L 2048M /dev/VolGroup00/LogVol02
WARNING: Reducing active logical volume to 2.00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol02? [y/n]: y
Reducing logical volume LogVol02 to 2.00 GB
Logical volume LogVol02 successfully resized
[root@localhost ~]#
Now run resize2fs again to nudge the size of the filesystem up to use all of the available space (note no size argument this time):
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol02
resize2fs 1.41.0 (10-Jul-2008)
Resizing the filesystem on /dev/VolGroup00/LogVol02 to 524288 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol02 is now 524288 blocks long.
[root@localhost ~]#
Now mount /home:
[root@localhost ~]# mount /dev/VolGroup00/LogVol02 /home
Check the size:
[root@localhost ~]# df -h /home
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol02
2064208 343528 1615828 18% /home
[root@localhost ~]#
It should be 2048MB in size or thereabouts.
Increase the size of /
Next, lets extend / to soak up the newly available space (recall we can extend filesystems while online).
First extend the logical volume that underlies the / filesystem (/dev/VolGroup00/LogVol00 from the earlier df output):
[root@localhost ~]# lvextend -L 10368M /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 10.12 GB
Logical volume LogVol00 successfully resized
[root@localhost ~]#
Now resize the filesystem to fill the logical volume (again, note no size argument):
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.41.0 (10-Jul-2008)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2654208 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2654208 blocks long.
[root@localhost ~]#
Check size:
[root@localhost ~]# df -h /
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
10450224 5441756 4477656 55% /
[root@localhost ~]#
All done. Phew!
Now for that database...
