Moving /tmp/log to USB (mount --bind?)

I exhausted my tmpfs due to runaway nginx logs in /tmp/log. I would like to move all the logs, and possibly the whole /tmp tree to my SSD to prevent future problems. It was fairly easy to move /tmp/log by using mount --bind.


  1. how can I get my mount --bind to survive a reboot? Normally I'd do this in fstab. (When I searched, unfortunately I get a bunch of unrelated info on the Bind package...)
  2. is there a way to cleanly disable the whole tmpfs system and use the ssd instead?

I'm OK with using mount --bind to redirect /tmp/log to an SSD, if disabling the tmpfs is going to be messy and complicated.

Well, this might not be the right approach but I ended up putting this into the startup commands section of LuCI:

mkdir /tmp/oldlog 
mv /tmp/log/* /tmp/oldlog 
mount --bind /opt/log /tmp/log
mv /tmp/oldlog/* /tmp/log
rm -r /tmp/oldlog
  • Use the System>Mount Points menu.

I think you want to look into extroot or the like...there are threads on this.

Using System->Mount Points didn't seem to make a mount --bind available. I did look at that.

1 Like

no really... ssd is likely module related... so "post pre-init"

cat /lib/functions/ | grep -C20 tmpfs

then you've got some init.d action @ /etc/init.d/boot... with ssd traditionally being kicked in at /etc/init.d/fstab... you could add the commands there after block mount for a more "precise" hook ... but any earlier introduces complexities in the os-init and recovery routines... in the event the ssd is ever to become unavailable...

on that... you should probably have something like;

if [ ! -b /dev/ssdpart ]; then exit 0; fi
if ! mount | grep -q '/ssdmountpoint'; then exit 0; fi

etc. etc.

startup is also ok... for whole of /tmp, you could try -o move...

1 Like

Thanks for the tips.

I'm a little confused about the --move (or -o move) option. Didn't actually know it existed. From the docs:

mount --bind olddir newdir
mount --move olddir newdir
    This will cause the contents which previously appeared under olddir to be accessed
    under newdir. The physical location of the files is not changed.

The bind option I understand. I use mount --bind /opt/log /tmp/log.
The move option seems backwards to me. --bind will already make olddir available at newdir. What i want is the original contents of newdir merged into olddir.

1 Like

Just a quick and dirty solution:

Add a swap partition to your SSD. After plugin:
swapon -a
mount -o remount,size=2G /dev/shm /tmp/
Tmpfs should claim 2G using swap if needed. You can check this with "df -h /dev/shm"
Last step: add the tmpfs remount command and swapon command into rc.local.


Clever, I like it!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.