Linux: Temporarily remap /tmp

In my case, I am using gogs on an Azure VM, which has a not-large main drive, but a rather large drive that only exists as long as the VM is running.

Given that the gogs backup is rather disk hungry, I found the need to move its use away from /tmp and onto the temporary disk.

# Since "resource" is owned by root, make a subfolder and make it world-usable
sudo mkdir /mnt/resource/TEMP && sudo chmod 777 /mnt/resource/TEMP
# Verify
ls -ld /mnt/resource/TEMP
# while TMP and TEMP did not affect gogs, TMPDIR DID, indicating that gogs uses mktemp
TMPDIR=/mnt/resource/TEMP ./gogs backup

Whether or not it works for other linux programs, depends upon how they find the /tmp directory. Try setting the TMP, TEMP and TMPDIR environmentvars in succession and see if any of them works.

If it uses mktemp as it should, that takes TMPDIR into consideration
Ref.:https://www.baeldung.com/linux/change-tmp-directory-path

If it does not use mktemp, some temporary mounting onto “tmp” is probably needed

Leave a Reply

Your email address will not be published. Required fields are marked *