Increase and secure /tmp partition

in this post we will show how to increase and secure /tmp partition .

we will increase it to 5 GB in our example .

First stop cpanel , apache and mysql services by excute the next commands :

service cpanel stop
service mysql stop
service httpd stop

Then , take a copy all session in /tmp :
cp -Rp /tmp /tmp_backup

Delete all /tmp files :
rm -rf /tmp/*
rm -rf /var/tmp/*

then unmount partition :
umount /tmp
umount /var/tmp

Note : Be sure that partition is unmounted after excute the above command , and if it’s show message “cannot unmout , drive is busy” , so you will have to delete all files in partition again by excute :
rm -rf /tmp/*
rm -rf /var/tmp/*
then unmount it again .

now for create /tmp with 5 GB partition , you will excute the next commands :
dd if=/dev/zero of=/usr/tmpDSK bs=1024 count=5120000

wait until it’s finish creating partition from harddisk , then make an extended filesystem for /usr/tmpDSK file by excute the next command :

mkfs.ext3 /usr/tmpDSK
you will see this message :
——
Proceed anyway? (y,n)
——
so you must press “y” to continue , and wait until it finish .

Now , mount the filesystem as /tmp partition with noexec , by excute the next command :
mount -o loop,rw,noexec,nosuid /usr/tmpDSK /tmp
mount -o bind,rw,noexec,nosuid /tmp /var/tmp

Now you can see the new partition and it’s size by excute :
df -h

then set permission :
chmod 1777 /tmp

copy files back to new partition :
cp -Rp /tmp_backup/* /tmp/

delate backup files “/tmp_backup” :
rm -rf /tmp_backup

then start services that we stopped it again :

service cpanel start
service mysql start
service httpd start

Have a great day ! .

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: