How to resize tmpfs in Linux

George Shuklin on 2019-01-07

How to adjust available space in tmpfs without unmouting

A simple question with a simple answer (but not that easily googlable). I wouldn’t write this article if only I hadn’t spend about 15 minutes searching for the answer.

The problem: resize tmpfs without loosing data

When one use live image (with augfs, backed by both squashfs and tmpfs), there is a big desire to have a way to adjust how much memory server uses based on later stages of the server life. There is no way to unmount root (‘/’) on booted server, so I need to find a way to adjust amount of available space on tmpfs-based root partition without unmounting it.

The solution: remount

The answer is simple: remount.

mount -o remount,size=new_size /path/to/tmpfs

F.e.

mount -o remount,size=10G /lib/live/mount/overlay

This operation preserves data. If it’s not possible (f.e. you have more data on tmpfs than you are trying to set limit to), an error will raise:

mount point not mounted or bad option.