Home cPanel, Server • Increase the size of /tmp on a cPanel server

Increase the size of /tmp on a cPanel server

 - 

cpanel_logo
I regularly see cPanel servers at work that have a very small /tmp disk (512MB default) and can result in issues with PHP sessions and other temporary files that are put there. Based on how you use the server and the amount of data that is placed in /tmp it is sometimes necessary to increase the size of that folder.

In this case you can’t just edit a fstab entry as it is not based on tmpfs like most Linux server do, but cPanel uses a static file that is mounted as /tmp, that file is called tmpDSK and is located in /usr/.

If we want to increase the size of /tmp we need to increase the size of the /usr/tmpDSK file, which I’ll explain how to do so below:

Stopping all services that use /tmp:
We need to unmount the /tmp location but need to stop all services that are currently using the mountpoint. Mostly this will be Apache, MySQL and cPanel, but we can check this out easily by running the following command:
lsof /tmp

This will result in something like the list below:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 27607 mysql 4u REG 7,1 0 13 /tmp/ibyXz7YL (deleted)
mysqld 27607 mysql 5u REG 7,1 0 14 /tmp/ibGyCv33 (deleted)
mysqld 27607 mysql 6u REG 7,1 0 15 /tmp/ibJIYT7l (deleted)
mysqld 27607 mysql 7u REG 7,1 0 16 /tmp/ibWsbsjW (deleted)
mysqld 27607 mysql 11u REG 7,1 0 17 /tmp/ibvEV7Ge (deleted)

In this example I only needed to stop the MySQL service, but to make sure that everything is stopped I stop Apache and cPanel as well:
/etc/init.d/crond stop
/etc/init.d/httpd stop
/etc/init.d/mysql stop
/etc/init.d/cpanel stop

For Systemd based systems:
systemctl stop crond.service
systemctl stop httpd.service
systemctl stop mysql.service
ssytemctl stop cpanel.service

Unmounting /tmp and removing it:
Now that everything is stopped, check again with “lsof /tmp” to see if anything is still using it, if not we can unmount the /tmp location:
umount /tmp

We now need to remove the file that is used as the /tmp disk:
rm -f /usr/tmpDSK

Increasing the size of /tmp:
Now we need to edit the following script:
/scripts/securetmp

Search for the following line:
my $tmpdsksize = 512000

The notation is in bytes, so in the above config it would create a 512MB file, increase it to 1024000 or 2048000 for 1GB or 2GB tmpDSK files.

I see that line mostly around line 175 in the script, saves some searching!

Recreate and mount /tmp:
Now that we have set the new size for the tmpDSK file we need to recreate it. For this you need to run the script we edited earlier (it will ask 2 questions in the process, you should answer them both with “y”):
/scripts/securetmp

This will result in alot of output, example below from a cPanel machine:
umount: /usr/testDSK: not found
Building /usr/testDSK...10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.0554831 s, 189 MB/s
mke2fs 1.41.12 (17-May-2010)
/usr/testDSK is not a block special device.
Proceed anyway? (y,n) Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2560 inodes, 10240 blocks
512 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1280 inodes per group
Superblock backups stored on blocks:
8193


Writing inode tables: done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Done
*** Notice *** No loop module detected
If the loopback block device is built as a module, try running `modprobe loop` as root via ssh and running this script again.
If the loopback block device is built into the kernel itself, you can ignore this message.
Would you like to secure /tmp & /var/tmp at boot time? (y/n) y
Would you like to secure /tmp & /var/tmp now? (y/n) y
Securing /tmp & /var/tmp
Calculating size on /tmp
/tmp calculated to be 2000 M based on available disk space in /usr
No separate partition for tmp!
Building /usr/tmpDSK...2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 16.693 s, 126 MB/s
mke2fs 1.41.12 (17-May-2010)
/usr/tmpDSK is not a block special device.
Proceed anyway? (y,n) Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
128000 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912


Writing inode tables: done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
tune2fs 1.41.12 (17-May-2010)
Creating journal inode: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Done
Setting up /tmp... Done
Setting up /var/tmp... Done
Checking fstab for entries ...Done
Logrotate TMPDIR already configured
Process Complete

After the script finishes the /tmp is remounted with the newly configured size (in this example 2GB):
# df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/usr/tmpDSK 2.0G 67M 1.8G 4% /tmp

A update of cPanel may change the script that we have changed, this has no effect on the /tmp size as it is a file and is only changed once you run the securetmp script again!

Starting the services:
Now that /tmp is mounted with the new size we need to start the services that we stopped earlier:
/etc/init.d/crond start
/etc/init.d/httpd start
/etc/init.d/mysql start
/etc/init.d/cpanel start

For Systemd based systems:
systemctl start crond.service
systemctl start httpd.service
systemctl start mysql.service
ssytemctl start cpanel.service

That’s it, the size of /tmp is now increased!

Author:langerak

Leave a Reply

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

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.