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?
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.
/tmp
and I needed to keep it running for some reason. I couldn't reboot the machine at the time to actually configure /tmp
to a drive with more space and things started crashing anyway once it eventually filled up. I think lsof
would do for the "in case something was using tmp
" concern and I was able to use the solution above as I was trying to find the issue with the app that was causing tmp
to fill up. –
Perspiration 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.
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).
With assumption that nothing critical running on machine.
First create backup : sudo mkdir /tmp_bak && sudo rsync -avz /tmp/ /tmp_bak
We can follow below steps to created symbolic link by following the steps below
- mkdir $largedrive$/tmp
- cd /
- sudo rsync -avz /tmp/ $largedrive$/tmp && sudo rm -rf /tmp/ && sudo ln -s $largedrive$/tmp
where $largedrive$ is folder path where more space is available.
© 2022 - 2024 — McMap. All rights reserved.
/tmp
. Your desktop for example, a file manager, a database, etc.. If you mask the mount to/tmp
in the interim between when a temporary file was written and when the application attempts to read it -- things will crash. Instead, why not actually configure/tmp
to refer to your location with plenty of storage and restart all daemons/services needing/tmp
and be done with it. (a reboot after the config change will also do) – Fa