How to create a larger /tmp location using ext2 filesystem

Increasing the size of /tmp is not a practical thing to do on a busy server, mainly because you probably won't be able to dismount /tmp because it's constantly used by various services--trying to find and kill them all is too tedius. (Plus you won't be able to do single user mode through SSH)

So what we will do here is create a whole new /tmp storage location, make a backup of the old /tmp, add the new location to fstab, reboot the server, copy everything from the backup /tmpBKP location to new location, and lastly reboot the server again.

We'll make the file container 4GB, and assign the ext2 filesystem to it--it's faster than ext3.

cp -prf /tmp /tmp.bak
dd if=/dev/zero of=/var/tmpDSK bs=1024k count=4096
mkfs -t ext2 /var/tmpDSK

Check the new container filesystem

file /var/tmpDSK

Add new container to your fstab

vi /etc/fstab

Add the following to your /etc/fstab and comment out the old /tmp location if present

#/var/tmpMnt  /tmp  ext2  loop,noexec,nosuid,nodev,rw  0  0
/var/tmpDSK  /tmp  ext2  loop,noexec,nosuid,nodev,rw  0  0

Reboot the Server

reboot

After server reboots

chmod -R 1777 /tmp
yes | cp -rpf /tmp.bak/* /tmp

Now reboot one last time, and it should be all good.
Note: we reboot, because a lot of processes will not be able to start automatically, meaning you'd have to go through each one and manually start them--forget that nonsense.

reboot

Check the size and permissions to make sure everything is working

df -mh

You should see something like this included in the results:

/var/tmpDSK           4.0G  8.8M  3.8G   1% /tmp

And that should do it..

Tags: Linux linux server admin