Move tmp folder from '/' partition to mounted partition (/mnt)
You can bind the /tmp
mount point to /mnt/tmp
:
sudo mount -B /tmp /mnt/tmp
Moving a "/tmp" partition requires some extra not suggested in this wrong answer https://askubuntu.com/a/371628/298086.
Moving data implies erase data from original partition once cloned to destination one, what is absolutelly not performed by a bind mount.
RECOMENDATION: Read this brilliant post if you wanna understand what a bind mount is https://unix.stackexchange.com/a/198591
If you give a try to the right mount option ("MOVE", not bind):
mount -M /tmp /mnt/tmp
I'm convinced it will fail reporting that "tmp is a shared mountpoint" (what indeed means "I cannot move a mountpoint if still being any process using it")
The "answer" you are looking for, may require stopping and restarting services using/accessing /tmp, before moving content.
You can list those services/processes by running:
lsof +D /tmp/
So once you listed what is actually accessing/using /tmp
, is when you can reallly decide "how to act".
In my opinion most safe way passes-by
- Stopping all services accessing /tmp (if you can do that)
- Copying entirely /tmp contents to a new place
- Editing /etc/fstab and changing /tmp mount point physical location (no matter if is a bind or device mount)
- Restarting the system to perform the remount
But there is another way what does not require system restart, but is not safer as previous one. It is described here and consists in umounting /tmp
in a lazy way, what should allow you to execute mount -M
This two links will be helpful for your demand:
- https://unix.stackexchange.com/questions/55773/move-tmp-to-ram
- https://unix.stackexchange.com/questions/5489/how-to-safely-move-tmp-to-a-different-volume