* /var/run and /var/lock are already mounted as tmpfs by default. So far so good.
* I moved /tmp and /var/tmp to tmpfs. I added these lines to /etc/fstab:
tmp /tmp tmpfs noexec,nosuid,rw,size=1024K 0 0 vartmp /var/tmp tmpfs noexec,nosuid,rw,size=1024K 0 0Then just rm -rf everything currently in /tmp and /var/tmp, reboot, and the temp directories are now tmpfs filesystems using 1MB of RAM each. That was easy enough. /var/log is a bit more difficult. This isn't a server, so I don't particularly care about extensive logs, but I do want to save the logs from at least one session of use in case something goes wrong. I wrote these scripts:
/etc/init.d/logbkup.sh - back up one session's worth of logs
#!/bin/sh if [ -f /var/log_bkup/log_bkup.tar.gz ]; then /bin/rm /var/log_bkup/log_bkup.tar.gz fi echo "Backing up logs to tar archive..." /bin/tar czf /var/log_bkup/log_bkup.tar.gz /var/logMake sure /var/log_bkup (or somewhere to back up the logs to) exists.
/etc/init.d/mklogdir.sh - create a skeleton in /var/log at boot
echo "Creating directories in /var/log" /bin/mkdir /var/log/apparmor /bin/mkdir /var/log/apt /bin/mkdir /var/log/cups /bin/mkdir /var/log/dist-upgrade /bin/mkdir /var/log/fsck /bin/mkdir /var/log/gdm /bin/mkdir /var/log/news /bin/mkdir /var/log/samba /bin/mkdir /var/log/unattended-upgrades /bin/mkdir /var/log/installerI'm not sure if the mklogdir script is really necessary, the directories may be created automatically as needed, but it can't hurt. Then link the scripts so they're called at boot and shutdown. I linked them to /etc/rc2.d/S05mklogdir.sh, /etc/rc0.d/S15logbkup.sh, and /etc/rc6.d/S15logbkup.sh. Then I added this to /etc/fstab:
Next, I rebooted from my Xubuntu live USB stick (the one I installed from) and mounted my install partition on /media/sda1, then deleted everything from /media/sda1/var/log to make sure it's an empty mount point. Then I rebooted, no problems. Thus, I'm using 10MB worth of RAM for all my temp files and logs, and the logs get written to disk once at shutdown rather than lots of small writes to different files the whole time the machine is on. With 1GB of ram and no swap I still have around 730MB RAM free on average. I could just not back up the logs at all, but you never know when you'll need them. This may be obsessive, but every write to the SSD you can save counts, and it was easy to do (writing this took much longer than it did to actually do it.
Edited by nickca, 19 December 2007 - 10:43 AM.