Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to temporarily rename /tmp and then create a tmp symlink to a different location?

Tags:

linux

symlink

tmp

The situation is that this application needs more space in /tmp. Currently my tmp folder is in root's partition. Is it safe to temporarily create a tmp symlink to a different partition just to take advantage of the larger space?

like image 251
maki57 Avatar asked Jan 05 '15 06:01

maki57


3 Answers

Instead of renaming and/or symlinking, you can:

mount --bind /path/to/dir/with/plenty/of/space /tmp

And umount /tmp when you are done.

If you are on a mission critical server, you can check if any program is currently using /tmp with lsof /tmp before doing the above.

NB: Run all commands as root.

like image 175
Innocent Bystander Avatar answered Nov 07 '22 18:11

Innocent Bystander


It depends...

Your better option may be seting TMPDIR environment variable to point to this location before starting Your application. This variable may be taken into account by Your application (but You need to test). Also application itself may have some settings or some other variable to set temporary location (check manual).

As for making symlink, runing applications which have files open in /tmp should not sense this change (i-node number would not change; even if You delete /tmp, open files would be deallocated after they are closed by all processes who currently have them open).

It may be a problem if another application expects to find something in /tmp (will be trying to open /tmp/.X11-unix for example). Such application would get an error. You can try to overcome this by making symlinks from new tmp to files in original tmp (symlinks must be correct after /tmp is renamed) before creating symlink. It may not work well for security concious or buggy applications.

Yet some chance to brake remains (it is not attomic operation to rename and symlink, so some application still may access /tmp when it is removed, but symlink is not yet created).

So it depends on what You have running on this machine.

If You can reboot the machine and have access to it's console (physical access, LOM, virtual machine condole, or similar) You can take OS to "single user" mode (telinit 1), make symlink and reboot. Or You can edit /etc/fstab to do mount --bind.

If You have Redhat/CentOS or derivative distribution there may be issues if SElinux is enabled.

like image 22
kestasx Avatar answered Nov 07 '22 20:11

kestasx


If it is a busy or mission critical server I would not do it, as there might be an important program trying to create a file while /tmp is missing. Or it might want to rename a file. But on a moderately used server, especially when you can pause the application you can try it.

It may have some problems with open sockets/fifos in the directory. It depends a bit on the Linux distribution how much is still using /tmp. Things like X11, screen, kde/gnome are candidates. So you better check with lsof first.

If /tmp is a mountpoint you might not rename it.

The most secure way to do this is booting in single user mode or from an external boot media to do the change. Then it is quite safe (as long as you do not use SELinux).

like image 30
eckes Avatar answered Nov 07 '22 18:11

eckes