You are not logged in.
Pages: 1
Hi.
I haven't found "the right" method for clearing /tmp directory. I used to have it mounted as tmpfs for performance reasons, but when something was misbehaving and creating stupid and very large files there it would bring my system to its knees. So I decided to have it on my disk. But I like the fact that it is cleared when I turn off my system.
So I wrote a small rc.d script, that can be added to DAEMONS in rc.conf (at the very beginning, so it doesn't remove any files that might be created by other daemons).
/etc/rc.d/clear_tmp:
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
do_clear() {
ret=0
for f in /tmp/* /tmp/.*; do
if [ ! "${f}" = "/tmp/." -a ! "${f}" = "/tmp/.." -a ! "${f}" = "/tmp/*" ]; then
rm -r ${f}
[ $? -gt 0 ] && ret=1
fi
done
return $ret
}
case "$1" in
start)
stat_busy "Clearing /tmp directory"
do_clear
if [ $? -gt 0 ]; then
stat_fail
else
stat_done
fi
add_daemon clear_tmp
;;
stop)
stat_busy "Clearing /tmp directory"
do_clear
if [ $? -gt 0 ]; then
stat_fail
else
stat_done
fi
rm_daemon clear_tmp
;;
*)
echo "usage: $0 {start|stop}"
esac
exit 0
Maybe someone else would find it useful. Or maybe I am pointed in the right direction if it's wrong
Offline
Ummm.... /tmp is cleaned on reboot anyway.
Offline
Ops. For some reason I had an impression it wasn't.
But still, it is done during booting the system, not turning it off
Offline
/etc/rc.sysinit clears it on boot
Adding `rm -Rf /tmp/*` to /etc/rc.shutdown would clear it on shutdown....
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
* Or use tmpfs
none /tmp tmpfs nodev,nosuid,mode=1777 0 0
Initially is created with size that is RAM/2
tmpfs is a clean solution, since uses the kernel internal cache, so all files inside are in ram or swap, also can change the size at runtime with a simple mount /tmp -o remount,size=N
* Or use "find -print0 | xargs -print0"
With find can delete files based on times for example, in any way /tmp should be clear at bootup. Different is the case of /var/tmp that must maintaint the content on reboots.
Offline
* Or use tmpfs
none /tmp tmpfs nodev,nosuid,mode=1777 0 0
Initially is created with size that is RAM/2
tmpfs is a clean solution, since uses the kernel internal cache, so all files inside are in ram or swap, also can change the size at runtime with a simple mount /tmp -o remount,size=N* Or use "find -print0 | xargs -print0"
With find can delete files based on times for example, in any way /tmp should be clear at bootup. Different is the case of /var/tmp that must maintaint the content on reboots.
I used to have it mounted as tmpfs for performance reasons, but when something was misbehaving and creating stupid and very large files there it would bring my system to its knees. So I decided to have it on my disk.
Offline
Fyi, you can use ramfs instead of tmpfs. Ramfs will grow if needed, so there are no space constraints. It will just eat more RAM .
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
Another alternative is to mount /tmp as an encrypted volume with a random key at each boot. If the key isn't stored anywhere, that data is practically unrecoverable once you shut off the system. As you seem concerned about removing the data at shutdown instead of letting the system clear /tmp at boot, it seems that you have sensitive data that you want to remove, so I would recommend this method.
Otherwise, consider using "wipe" or "shred" to make the data on /tmp more difficult to recover when you remove it.
My Arch Linux Stuff • Forum Etiquette • Community Ethos - Arch is not for everyone
Offline
I used to have it mounted as tmpfs for performance reasons, but when something was misbehaving and creating stupid and very large files there it would bring my system to its knees. So I decided to have it on my disk.
Ooh but... tmpfs can be tunned, see Documentation/filesystems/tmpfs.txt and adjusting swappiness values
Offline
Thanks for responses
I guess my script is not needed afterall ;(
Offline
Pages: 1