Is there a way to resize a UFS /root partition while running OS which resides on it? I am running FreeBSD.


There's a fairly comprehensive guide to growing a disk under FreeBSD in the handbook. For UFS (the default for FreeBSD), you can grow online from kernel version 10.0 onward.

However, changing the partitions around mounted filesystems might lead to data loss or inconsistencies which might be first discovered when the system tries to boot the next time. Also remember to check up on your bootloader.

Growing a filesytem basically boils down to this:

  1. Adjust your partition table. Be very careful with this step, as messing up here can lead to corrupting your entire disk. You'd probably want to unmount all partitions that are not actively needed to run a minimal system, most notably the swap partition.

    From your question, I assume you know how to use gpart to accomplish this.

    After having made the adjustments, you can safely remount all partitions and re-enable swap.

  2. Actually grow the FS. For FreeBSD, this is as easy as issuing growfs <blockdevice> with <blockdevice> being the partition that you resized.

For shrinking, you have to do these steps in reverse:

  1. Shrink the filesystem to make sure you won't overwrite anything important: growfs -s <new_size> <blockdevice>. Make sure that you choose a size less than your new target filesystem size, i.e. if you want to go down from a 100GB partition to a 70GB one, resize the FS to about 60-65GB at this step. Overshooting more means more headroom, but usually also means more relocations and thus longer wait time.
  2. Adjust the partition table. Unlike before, at this step you choose your exact target size. You'd probably want to unmount additional partitions at this step too, especially if you move other partitions around (in fact, in this case you have to unmount these).
  3. Grow the filesystem. This gets rid of the headroom you left at the end of the (new) partition: growfs <blockdevice>. Omitting the size parameter tells it to use the entire partition.
| improve this answer | |
  • Actually, growing a mounted partition under FreeBSD 10 or later should be perfectly safe. Resizing a partition should be safe as well - as long as you don't use the "debugflags" hack, which disables the safety mechanisms. – Edward Tomasz Napierala Sep 29 '17 at 18:45

You have to mount rootfs as readonly, and do instant reboot after resizing finished.

| improve this answer | |
  • 1
    Note that what's true for one operating system is not universally true. For a correct answer for FreeBSD, I suggest researching growfs and (for recent versions of FreeBSD) ZFS. – JdeBP Nov 18 '16 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.