Is it possible to temporarily rename / tmp and then create a tmp symbolic link elsewhere?
Instead of renaming and / or symbolic link, you can:
mount --bind /path/to/dir/with/plenty/of/space /tmp
And umount /tmp
when you're done.
If you are on a mission critical server, you might want to check if any program is currently using / tmp s lsof /tmp
before doing so.
Note. Run all commands as root.
source to share
It depends...
As a best practice, you can set TMPDIR
an environment variable to point to this location before starting the application. This variable can be accounted for in your application (but you need to test). Also the application may have some settings or some other variable to set the temporary location (check the manual).
As for creating a symbolic link, launching applications that have files open in /tmp
should not accept this change (the i-node number would not change, even if you delete /tmp
, open files will be freed after they are closed by all processes. who are currently opening them).
This could be a problem if another application expects to find something in /tmp
(for example, tries to open /tmp/.X11-unix
). Such an application will receive an error. You can try to overcome this by making symlinks from the new tmp to files in the original tmp (symlinks should be correct after /tmp
renaming) before creating the symlink. This might not work for security or bugs.
And still there is some stopping possibility (this is not an attomic operation for rename and symlink, so some application can still access /tmp
when it is removed, but the symlink has not been created yet).
So it depends on what you are using on that machine.
If you can restart your computer and access the console (physical access, LOM, virtual machine, condolence, or the like). You can switch the OS to "single user" ( telinit 1
) mode , make a symbolic link and reboot. Or you can edit /etc/fstab
to do mount --bind
.
If you have Redhat / CentOS or a derivative distribution, there may be problems if SElinux is enabled.
source to share
If it is a busy or critical server, I would not do this, as there might be an important program trying to create the file while / tmp is missing. Or he might want to rename the file. But on a moderately used server, especially when you can pause the app, you can try it.
It may have problems with open sockets / fifos in the directory. It depends a little on Linux distribution, how much else / tmp is using. Candidates include X11, screen, kde / gnome. So it's better to check lsof first.
If / tmp is a mount point, you cannot rename it.
The safest way to do this is to boot in single user mode or from external bootable media to make changes. Then it is quite safe (unless you are using SELinux).
source to share