Filesystem Resizing on the Fly

Filesystem Resizing on the Fly

Posted on 2013-12-12 by Ed Braaten

I recently rushed through an installation of CentOS 6 on a system with 32GB of memory installed. At first I didn’t notice the resulting automatic swap partition had eaten up 32+GB of my 40GB solid-state drive. When I unexpectedly ran out of disk space on the root partition, I finally realized what had happened. Below, for future reference, are the simple steps I took to shrink the swap space back to a reasonable 2GB size and re-allocate the freed swap space to the root partition. All of these steps can be performed without a reboot of the system.

  1. Disable the swap space we’re going to resize.
    swapoff -v /dev/vg_testhost/lv_swap
  2. Resize the swap space.
    lvm lvresize /dev/vg_testhost/lv_swap -L 2G
  3. Format it as swap space.
    mkswap /dev/vg_testhost/lv_swap
  4. Re-activate the new swap space.
    swapon -v /dev/vg_testhost/lv_swap
  5. Now add the free space to the root partition.
    lvm lvresize -l+100%FREE /dev/vg_testhost/lv_root
  6. Resize the filesystem to use the additional space.
    resize2fs /dev/vg_testhost/lv_root

Copyright (C) 2013 by Ed Braaten.  All rights reserved.
Other Blog Entries
https://ed.braaten.net/