/var/log mounted as a tmpfs, where log files are synced periodically to the disk by the cron on FreeBSD. The process is done by the
I am mounting it like:
mount -t tmpfs -o nosuid,noexec,mode=0755,size=100M log /var/log
Now the problem is - unmounting it. It fails to unmount, because
(r)syslog writes to the file. This is shown by lsof:
lsof /var/log/ lsof: WARNING: compiled for FreeBSD release 11.1-RELEASE-p6; this is 11.1-RELEASE. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsyslogd 85515 root 2w VREG 255,2264924190 210 13 /var/log/security rsyslogd 85515 root 4w VREG 255,2264924190 210 3 /var/log/auth.log rsyslogd 85515 root 5w VREG 255,2264924190 2292 7 /var/log/kern.notice rsyslogd 85515 root 6w VREG 255,2264924190 2292 11 /var/log/messages rsyslogd 85515 root 7w VREG 255,2264924190 2292 5 /var/log/debug.log
So in order to unmount it, firstly I have to stop the syslog daemon. However, I am looking for some nicer solution, as this actions are managed by a sh rc script itself.
On the Linux/GNU Os's
umount has a very handy argument:
--lazy detach the filesystem now, clean up things later
, which by my knowledge, waits for an active processes to stop r/w to the filesystem, and then process with unmounting it, which would result in success and not breaking the script.
So as a workaround to this, how can I stop syslog temporary writing to /var/log ? I've tried issuing
STOP, trying to umount and
CONT signal, but no effect.
Lsof still reports that there are FD that are open to writing. Note that I need solution that can be applicable from
The umount has
--force argument, which under normal circumstances I would avoid at any cost.
But since this is a
tmpfs and runs from a memory not block device, I believe it will do no harm.
Couple of tests showed that there are no issues. I did it by creating dummy files on tmpfs with
dd, checked their sums, sync them to hdd, and then forcing the umount.
The hashes matched which means that files weren't corrupted.
Well that is kinda dirty workaround, but I am not aware of other solutions. If someone has some drawbacks against this method on ram fs, please let me know.
ps: kudos to @layer8problem for advices :-)