0

Scenario
I am on an embedded Linux system. As usual /var/log/ is the directory when all the logs are stored. I have a directory called /safepath which is created during image creation and it is on persistent memory. It means that whatever I place under /safepath persists across reboot sessions.

I want the logs in /var/log/ to not be lost on every reboot and wish to make it persistent through the reboots. So I thought to mount /var/log/ on to /persists by doing a mount --bind /var/log /safepath which I read from this interesting discussion here

Question:
But doing this still causes me to lose the data in /var/log/. Is this correct? How can one force /var/log/ to persist across reboot sessions?

mike65535
  • 149

3 Answers3

2

Most straightforward way would be to make /var/log a symbolic link to /safepath/log, or something similar.

Lewis M
  • 1,048
  • How do I do that? Do you mean to try ln -snf? ln -snf /var/log /safepath complains : failed to create symbolic link '/safepath/log': Operation not permitted ! – TheWaterProgrammer Oct 24 '18 at 15:26
  • You might have to do this in single user mode since files in /var/log are being accessed. What I would do is create the /safepath/log directory. I would copy all of the items in /var/log to /safepath/log using something like "(cd /var/log; find . -print | cpio -pdm /safepath/log)" Rename /var/log to something like /var/log.moved. Create the symbolic link (ln -s /safepath/log /var/log) and reboot. After the reboot, confirm logs are now being updated in /safepath/log. – Lewis M Oct 24 '18 at 15:51
2

Not sure if you are still looking for the solution as question was posted 1 year 4 months ago. Anyway, here is the solution that is very simple.

Change configuration file /etc/syslog.conf (or /etc/rsyslog.conf) to change /var/log/messages to desired path.

chaos
  • 48,171
1

Not really answering the question. but offering an alternative ... add a rule to syslog to forward all messages to a server e.g.

*.*    @server.host.name

If you do this, you won't need to persist /var/log (my experience has been that you will always fill up your persistent storage if you have /var/log on it).

Note that you will need to enable the network module in syslog on your server - how to do that depends on what syslog software you are running. You may also need to deal with firewalls (usually UDP port 514).

Also note that you might need to use an IP address instead of server.host.name if your DNS resolver is not available when your syslog daemon is started.

One (I think big) advantage of doing this is you can have all your embedded devices log to the one server and then all logs are available in the one place - you should use the matching rules in your server's syslog software to store messages from each device into separate files named after the source device (this can be tricky to set up sometimes, but is well worth it).