0

I have a ssd drive in my laptop and I followed various advice that said to put /var/log /var/spool & /var/cache on a tmpfs so that the constant read/writes wouldn't lessen the life of my ssd.

However, anacron now doesn't start and the error message in /var/log/syslog says

anacron[4169]: Can't chdir to /var/spool/anacron: No such file or directory
kernel: [ 3037.851604] init: anacron main process (4169) terminated with status 1

cups-pdf has a similar problem and complains that /var/spool/cups-pdf doesn't exist.

I've checked and /var/spool/ and it's true neither of these exist.

If I create these directories manually both processes run. But after I restart the directories are gone again.

How do I make them exist permanently?

2 Answers2

1

Ok so nothing you do on a tmpfs is not going to persist after a restart. That's because a tmpfs is temporary and only exists in the RAM. Anything that needs to be on a tmpfs for the system to run must be created every time the system boots. Most processes that use /var do this but some it seems such as anacron and cups-pdf do not.

To fix this you have to create a script that creates these directories every time the system starts. Copy the below into a text file, save it and make it executable.

#!/bin/bash

# Script to create required directories in tempfs /var (that are not otherwise created)
# Thanks to http://blog.philippklaus.de/2011/02/ssd-optimizations-on-linux/ for the list below :-)

for dir in apparmor apt ConsoleKit cups dist-upgrade fsck gdm installer news ntpstats samba speech-dispatcher unattended-upgrades; do
  if [ ! -d /var/log/$dir ] ; then
    mkdir /var/log/$dir
  fi
done

for dir in cups-pdf anacron; do
  if [ ! -d /var/spool/$dir ] ; then
    mkdir /var/spool/$dir
  fi
done

Next you need to make this script run every time the system starts by adding a line to /etc/rc.local

I called my script "make_required_dirs_on_tempfs.sh" so I just add the following line to the rc.local file. Put it at the end but above the "exit 0" command.

/PATH_TO_SCRIPT/make_required_dirs_on_tempfs.sh

I saved my script in "/mnt/data/config/scripts/start-stop" and so my /etc/rc.local file looks like this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#if [ -d "/var/cache/apt/archives" ]; then echo "/var/cache/apt/archives exists"; else mkdir /var/cache/apt/archives; fi || die "Command failed: mkdir /var/cache/apt/archives"

/mnt/data/config/scripts/start-stop/make_required_dirs_on_tempfs.sh

exit 0
1

fwiw, i started with "Jesse the Wind Wanderer"'s script and then added some additional directories and tweaks. I temporarily disabled tmpfs for /tmp, /var/log, and /var/spool , then rebooted to see what log files and spool directories were present in a non-tmpfs scenario.

By doing so I was able to detect some additional directories and files that probably needed to be created/present for some of the startup/cron jobs to work correctly.

In terms of the ownership settings in the script, i just used the same ownership settings that appeared in the non-tmpfs scenario.

#!/bin/bash

# Script to create required directories in tempfs /var (that are not otherwise created)
# Thanks to http://blog.philippklaus.de/2011/02/ssd-optimizations-on-linux/ for the list below :-)

for dir in apparmor apt ConsoleKit cups dist-upgrade fsck gdm hp installer lightdm news ntpstats samba speech-dispatcher unattended-upgrades upstart; do
  if [ ! -d /var/log/$dir ] ; then
    mkdir /var/log/$dir
  fi
done

touch /var/log/apport.log
chown root:adm /var/log/$i

for i in auth.log kern.log syslog
do
  touch /var/log/$i
  chown syslog:adm /var/log/$i
done


for dir in anacron cron cups cups-pdf libreoffice lintian plymouth rsyslog; do
  if [ ! -d /var/spool/$dir ] ; then
    mkdir /var/spool/$dir
  fi
done

cd /var/spool
rm -f mail
ln -s /var/mail


# needed in order for rsyslog to pick up the newly created log files:
sudo service rsyslog restart

/usr/bin/logger "(finished making required directories for tmpfs)"

And, of course make the script executable by root and invoke it from rc.local per Jesse's instructions..

Gino
  • 260
  • 3
  • 7