0

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.

intuited
  • 405
  • 1
  • 5
  • 12

1 Answers1

2

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 use resize2fs /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.

baumgart
  • 2,423
  • 18
  • 17
  • My concern isn't really with LVM, but with the limitations of the ext* filesystem. I read in a couple of places (e.g. [here](http://www.tldp.org/HOWTO/LVM-HOWTO/reducelv.html)) information that suggested that it was necessary to unmount an ext* filesystem in order to run `resize2fs`. Though it looks like you're right, and those sources are outdated: the current (ubuntu 10.04) manual for `resize2fs` mentions that "As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only." – intuited Sep 16 '10 at 02:32
  • This is correct, but only works when *increasing* the size of the file system. If you want to decrease it (shrink it), you still need to unmount the partition. BTW, Knoppix is an excellent choice for this sort of work. – wolfgangsz Sep 16 '10 at 10:00
  • @wolfgangsz - Can you provide a source for the info about unmounting to shrink? I've never tried to shrink a filesystem at all, much less online, but all the information I'm seeing says that when using LVM and ext2/3, it is possible to do online resizing (both growing and shrinking). – baumgart Sep 16 '10 at 13:57
  • Read the man page for resize2fs. In the "Description" section it says: The resize2fs program will resize ext2 or ext3 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only.). – wolfgangsz Sep 16 '10 at 16:26
  • This is from version 1.41.3 (stock Debian lenny). If you use a newer version, this might be different. As said, read the man page. – wolfgangsz Sep 16 '10 at 16:27
  • I read the page now, and yes, I see the same thing. I just tried it on my system just for kicks, and it told me I can't do an online shrink. As I said, I've never tried shrinking, so I never ran into that before. Thanks for the info. – baumgart Sep 17 '10 at 15:44
  • @baumgart: It would probably be a good idea to add this detail to your answer so as to avoid misinforming casual readers. – intuited Sep 18 '10 at 02:17
  • @intuited: Good call. – baumgart Sep 18 '10 at 23:09