DEV Community

rndmh3ro
rndmh3ro

Posted on • Originally published at zufallsheld.de on

2 2

Shrinking the (LVM) log-partition on Linux

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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!

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay