I'm doing this to reduce I/Os on memory card of raspberry pi. I want to redirect logs under /var/log to a mounted external drive. I am using following commands in the stated order to create the links. There are 2 solutions i'm exploring.
Method: 1
sudo /etc/init.d/rsyslog stop
ln -fs /var/log/messages
/path/to/mount/messages
sudo /etc/init.d/rsyslog stop
I have removed files in case this doesn't work using rm
command. My primary problem is reboot and remounting of drives. Whenever I reboot the RPi I need to mount the drives again. However, the logs start getting written to /var/log
and I have to go through the trial and error process again. I have edited logging path in software's wherever possible. However for system processes and logs such as messages, mail, wtmp, debug
i am unable to find a solution.
What is the most robust way to ensure I log on the external drive all the time. /mnt/path/ all the time? including for system applications?
Method 2:
This is where I mount my external device to /var/log folder using fstab
. I've taken a backup of my fstab file using sudo cp -p /etc/fstab /etc/fstab.17.11.2018
Following is what the file contents are:
proc /proc proc defaults 0 0
PARTUUID=dd5ad381-01 /boot vfat defaults 0 2
PARTUUID=dd5ad381-02 / ext4 defaults,noatime 0 1
# a swapfile is not a swap partition, no line here
# use dphys-swapfile swap[on|off] for that
Following is the output of blkid
user@hostname:~# sudo blkid
/dev/mmcblk0p1: LABEL="boot" UUID="FBD8-71DF" TYPE="vfat" PARTUUID="dd5ad381-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="e9646bf0-ef1f-4e8b-983b-c9f97f60e931" TYPE="ext4" PARTUUID="dd5ad381-02"
/dev/mmcblk0: PTUUID="dd5ad381" PTTYPE="dos"
/dev/sdb1: LABEL="logs" UUID="50043501-276b-473d-a6a5-bda12a845d67" TYPE="ext4" PARTUUID="1068b060-01"
/dev/sda1: LABEL="label" UUID="f1da78dc-d69b-4902-9646-f1719b637634" TYPE="ext4" PARTLABEL="part-label" PARTUUID="f8a547cb-9870-49ee-8055-70f7ff025926"
The current directory I mount the sdb1 is /mnt/logs. I am ok changing this. How should my line for the logs file should look like? Is the following correct?
PARTUUID=1068b060-01 /var/logs ext4 sync,auto,nodev,noexec,suid,rw,nouser, 0 2
I wanted to run this by the community given the sensitivity of the operation. I was reading the man page at (https://help.ubuntu.com/community/Fstab#Device). I am not sure but can I lock down the mount for only administrator? I don't see a log file that is for anyone but the root anyway.
Following is the content of /etc/rsyslog.conf file. I've tried doing this but it doesn't work too. Is it because I've created symbolic links?
user@hostname:~ $ cat /etc/rsyslog.conf
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#################
#### MODULES ####
#################
module(load="imuxsock") # provides support for local system logging
module(load="imklog") # provides kernel logging support
#module(load="immark") # provides --MARK-- message capability
# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")
# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
###############
#### RULES ####
###############
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /mnt/logs/auth.log
*.*;auth,authpriv.none -/mnt/logs/syslog
#cron.* /mnt/logs/cron.log
daemon.* -/mnt/logs/daemon.log
kern.* -/mnt/logs/kern.log
lpr.* -/mnt/logs/lpr.log
mail.* -/mnt/logs/mail.log
user.* -/var/log/user.log
#
# Logging for the mail system. Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info -/var/log/mail.info
mail.warn -/var/log/mail.warn
mail.err /var/log/mail.err
#
# Some "catch-all" log files.
#
*.=debug;\
auth,authpriv.none;\
news.none;mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
#
# Emergencies are sent to everybody logged in.
#
*.emerg :omusrmsg:*
The reason of doing this is because I'm running a web server on my RPi and the logs are in excess of 2 GB a day.
cat
syslog) by any user. permissions for the file are -rw-r----- 1 root adm .. Any idea what I'm doing wrong?/var/log/messages
will get quite big. If not you could leave it as is so you will get error messages saved if, e.g., the hard drive fails to mount or something.