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 loose the data in /var/log/. Is this correct? How can make /var/log/ to persist accross reboot sessions?

0

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

  • 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 ! – Game_Of_Threads 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
0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.