Enlarging an LVM partition on a linux machine is trivial. You only need one command to do it and it can even be done when the partition is mounted.

lvresize -r -L +20G /vg1/lvm1

This command enlarges the LVM lvm1 to 20GB. Assuming you use an ext, ReiserFS or XFS filesystem on the LVM-layer it gets enlarged, too (with the -r-switch.

But if you need to shrink an existing partition it can get ugly. It is possible to shrink the LVM on-line, but you cannot lessen the size of the filesystem while it is mounted.

shrink_lvm


So recently I had to reconfigure the partitions on a linux host as there was no separate partition for /tmp or /opt. I had the choice of shrinking the root-filesystem or the one where the logging-directory (/var/log) resides. To avoid unnecessary downtime and complicated resizing actions with a live-cd I choose to shrink the latter.

The problem that presents itself is that there are many programs that write into logfiles in this directory. Or so I thought…

Actually, most programs do not write directly into this directory, most use the syslog-daemon[] to handle log-writing.

Now all you have to do is stop the syslog-daemon and other applications that do not use syslog but still write to /var/log. To find out which applications do that, you can use lsof:

lsof /var/log

This shows all the applications that currently write into the directory. Now all you have to do is stop these applications and syslog and resize the LVM with the command mentioned above. Then start syslog again and it’s done!



Related posts: