3

I fear I already know the answer to this question, but here goes.

I need to carve out a new partition on a running system. /var/ is mounted from an LVM volume (hdd1_vg-var) and has only 3% used disk space.

/ is mounted separately (hdd1_vg-root) and has about 80% used disk space.

Filesystem            Size  Used Avail Use% Mounted on
/dev/**/hdd1_vg-root
                      2.0G  1.4G  481M  75% /
/dev/**/hdd1_vg-var
                       33G  699M   31G   3% /var

Unfortunately I don't have any free extents to grow this partition organically - vgdisplay shows:

  Total PE              10000
  Alloc PE / Size       10000 / 39.06 GB
  Free  PE / Size       0 / 0

So seeing that I have all this free disk space on /var/, can I shrink /var/ without un-mounting it or is this just a pipe dream?

I am really hoping to be able to do this work on a running system - un-mounting would of course not be difficult but it would interfere with system functionality.

javanix
  • 247
  • 4
  • 15
  • Shrinking a mounted filesystem (assuming extX) is not possible. If you want to get kludgy, to use the space under /var elsewhewre, you can create directories under /var and then symlink to them. – Mark Wagner Oct 22 '13 at 17:36

2 Answers2

1

Yes, you can shrink/move/grow an online root partition without any reboots (nor livecd, nor usbkey): consult this answer. It's very well written and easy to follow, although quite long and a little risky.

This allows to bypass limitation of resize2fs not being able to shrink ext4 partitions.

Of course, if you only want to grow your ext4 partition, you can stick to the conventional working resize2fs solutions.

The general solution I've lnked will work on any type of dedicated or VPS solution for instance.

TLDR; this solution implies to pivot_root to tmpfs so you can umount safely your root partition live and fiddle with it. Once done, you'll pivot_root back on your new root partition.

This allows pretty much any manipulation on the root file system (move it, change filesystem, changing it's physical device...).

I have personally used this, and it works very well on debian system also, but the guide was initially written in 2007 for redhat, the answer I've linked was updated for CentOS7. It's highly probable that it'll work on your CentOS6.

vaab
  • 532
  • 4
  • 14
  • Actually the `pivot_root` technique seems to work only with `/` modification. But I didn't find a way to use this for `/var/` filesystem which is a non-root filesystem... – Anthony O. Oct 21 '16 at 14:19
0

As fas as I know, C6 doesn't support shrinking mounted file systems; the following is from man resize2fs:

   The resize2fs program will resize ext2, ext3, or ext4 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.

But you should be OK as long as you're prepared to have a little downtime. If the system is booted single-user, you should be fine to unmount /var, and it won't take long to shrink the FS and underlying LV.

MadHatter
  • 79,770
  • 20
  • 184
  • 232