How to expand the allocated space of /tmp in Linux?

On a Linux server /tmp partition was only 1 GB, it gets full at times, no matter how many times it gets cleaned automatically with tmpwatch.

The server had the following in its /etc/fstab file:

[root@server1 ~]# cat /etc/fstab 
UUID=c0f46bb1-c0bc-4199-95d6-551d03c12a0a /                       xfs     defaults        1 1
/var/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0
/tmp /var/tmp none bind 0 0
[root@server1 ~]#

As you can see currently file /var/.tempdisk is mounted as /tmp.

So I created a new file with a 4 GB size

dd if=/dev/zero of=/var/sok_tmp bs=1M count=4096

Format it as an ext4 file system

mkfs -t ext4 /var/sok_tmp

Before I switch /tmp to the newly created disk, I need to copy the content of the current /tmp to it. For this, I mount the new disk as /tmp2

mkdir /tmp2
mount -o loop /var/sok_tmp /tmp2
rsync -avzP /tmp/ /tmp2/

Now you have all files of /tmp in /tmp2, edit /etc/fstab

nano /etc/fstab

Find the entry for the current /tmp partition

/var/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0

Replace it with the new file you created

/var/sok_tmp /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0

Reboot the server. You will have a 4 GB /tmp partition now.

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to restrict direct root access in Linux

We can do it just in two steps. Step One: At first we will create new root user as follows (for...

How to extract .tar.gz files in Linux/UNIX OS

A tarball is a group of files that are bundled together using the tar command. Use the...

How to add welcome message when SSH start?

You need to change the contents of /etc/motd. Unfortunately, by default, /etc/motd is a link to...

How to change root password when SSH logged in

Run the following command: passwd Now type your new passwordOnce done, retype new passwordDone!...

How to install Pinguzo on any Linux/UNIX OS

Login to Pinguzo panel using Softaculous account or create an account of Pinguzo To add new...