I'm building a system with fairly limited disk space that will use LVM, and I'd like to be able to resize the partitions as freely as possible without bringing the system down. In particular, I'd like to be able to grow or shrink* /usr
.
As I understand it, it's not possible (this is only half-true: see update) to resize a mounted ext2/3 partition, even if it is part of an LVM volume.
Would it be possible to unmount, say, everything but /bin
and /sbin
(assuming that those directories are on a separate partition, of course) for the duration of the resize? Or does resize2fs
need libraries or other entities from /usr
?
Perhaps this would be more appropriately done from within a chroot environment or by some other approach?
*: shrinking /usr
would probably only be necessary right after the install, so is not as necessary as growing that partition.
update
I've discovered (see @baumgart's answer and its comments) that under recent/modern Linux kernels it's not necessary to unmount an ext3 filesystem in order to increase its size. Although it is pretty unlikely that I'd have a need to reduce the size of a /usr filesystem with any sort of frequency or immediacy, I'm still interested in learning how I would set things up so as to be able to do so, or at least in being told that "you can't get there from here".
So my original question stands.
If you use LVM, you absolutely CAN resize ext2/3 filesystems. You can grow filesystems online, but shrinking them requires them to be offline.
If you configure all your filesystems (except /boot) using LVM, you can simply say
lvresize -L +1G /dev/vgname/lvname
, then useresize2fs /dev/vgname/lvname
to do the filesystem resizing.Check out the LVM page on Wikipedia and you'll see what it can do.
EDITED: Noted that shrinking requires taking the filesystem offline.