LVM adds storage just in time
I've been using LVM (Logical Volume Manager) on Linux ever since I first heard about it several years ago. I use it fairly mundanely and just use it to be able to resize the multiple partitions I carve out of a single drive on the fly. But that capability has helped at times. Earlier tonight, for instance.
I was restoring from SQL dumps a database that has a fairly big (6G) table with an even bigger index (about 15G). This is a slow process on my home machine (it's been running for nearly five hours now). Somewhere along the way I got a desktop notification saying that the MySQL partition had less than 1G free. I checked and, yep, only 931K. And going down slowly (the index was being rebuilt). What to do?
Well, I intentionally don't use all of my drive when I set up machines. It lets me increase space where I need it, while keeping each type of data relatively separate (MySQL, music, stock images). So, I knew I could increase the size with LVM. Here's how:
$ pydf # A pretty version of df
Filesystem Size Used Avail Use% Mounted on
. . .
/dev/ixchel/mysql 29G 27G 931M 91.8 [############.] /var/lib/mysql
. . .
$ sudo lvextend -L +20G /dev/ixchel/mysql # Expand the requisite partition by 20G.
$ sudo resize2fs /dev/ixchel/mysql # Make the FS understand.
$ pydf
Filesystem Size Used Avail Use% Mounted on
. . .
/dev/ixchel/mysql 49G 32G 14G 66.1 [#########....] /var/lib/mysql
. . .
And done. In just a few (<5) minutes.
Now, most places that talk about lvextend
and resize2fs
warn that you could lose stuff. But I've
been doing live resizes for years and haven't run into any problems (yet). Backups are, of course,
important. But doing this live resize saved me from having to re-run the restore.