Showing posts with label /tmp. Show all posts
Showing posts with label /tmp. Show all posts

Wednesday, June 1, 2011

Cannot Umount /tmp : Drive Is Busy

umount: /tmp: device is busy + Resolved

Guys,

Just check who is accessing the device. Here are the commands to check who are using it.

=======
lsof |grep /tmp
=======

You'll get the process ID and kill the processes like kill -9 PID. Here is an example(Second column is PID) :

=======
root@server [~]# lsof |grep /tmp
mysqld 2579 mysql 4u REG 7,0 0 6098 /tmp/ibZGlGm2 (deleted)
mysqld 2579 mysql 5u REG 7,0 68 6100 /tmp/ibgWnlrp (deleted)
mysqld 2579 mysql 6u REG 7,0 0 6101 /tmp/ib7XB0vM (deleted)
mysqld 2579 mysql 7u REG 7,0 0 6102 /tmp/ibQx1jB9 (deleted)
mysqld 2579 mysql 11u REG 7,0 0 6103 /tmp/ibBSaB7w (deleted)
=======

Then retry to umount the device like : umount /tmp_device_name //You'll get device from /etc/fstab. This file contains the mounting file system table information after system reboot and /etc/mtab holds the current mounted table information.

=======
fuser -m /dev/sda3 //You can also get the PID from here also. But note that deleting all the PID related to this device may cause the problem on the system and you may need to restart the machine.
=======

That's it. Try :)

How To Clear /tmp For Over Period Of Time

You may need to use a command called tmpwatch which removes files which haven’t been accessed for a period of time. Normally, it’s used to clean up directories which are used for temporary holding space such as /tmp.

Following code will remove all files/dirs from /tmp if they are not accessed in last 2 weeks (24 * 14 days = 336)

Code:
tmpwatch --mtime --all 336 /tmp

You can also add this command to the crontab.