On root filesystems that’s served from flash memory it may be advisable to keep off heavy writes from them. By putting /var on a ramdrive you can greatly increase the expected lifetime of an ssd or a usb memorystick.
Initial steps
A snapshot of /var needs to be created. On true diskless systems FreeBSD ramdrive filesystems can be set up by populating /conf/base. While it won’t be supported in this case, it might prove a good idea to use the same base for this purpose.
Start off by creating an initial snapshot of /var
mkdir -p /conf/base/var
tar -cf /conf/base/var.cpio.gz -C / --format cpio --gzip var
The contents on disk of /var is now obsolete.
rm -rf /var/*
Configuration
/etc/rc.conf
mdconfig_md0="-t swap -s 64m"
mdconfig_md0_cmd="tar -xpz -C / -f /conf/base/var.cpio.gz"
/etc/fstab
/dev/md0 /var ufs rw,noauto 0 0
/etc/rc.shutdown.local
Whenever the system is shutdown, the snapshot must be updated with the current contents.
mv /conf/base/var.cpio.gz /conf/base/var.cpio.gz.old
tar -cf /conf/base/var.cpio.gz -C / --format cpio --gzip var
The above would also prove useful in crontab to safeguard for brownouts or system crashes. So add the following to root’s crontab.
0 * * * * /bin/sh /etc/rc.shutdown.local
Recent Comments