Logs not updating after moving /var/log to USB

Hello,

Following the recommendation of moving swapping and logging off the SD card, I have created a swap partition and mounted /var/log in an external HDD connected to the Pi via USB.

While the system is up and running, I assume I did something wrong as I don’t see any logs being updated on /var/log/openhab2/ since the changes were made. However, if I go to openhab-cli console and do log:tail, then I see recent logs there.

In a nutshell, this is what I did:

  1. Shrank the existing NTFS partition on the HDD to make room for a new ext4 and a Linux swap (1 GB) partition.

  2. Edited fstab to mount the new partitions - having /var/log as a bind mount to the HDD

  3. Disabled usage of the local swapfile

  4. Copied log files from SD card to USB HDD - preserving filesystem permissions

  5. Made a backup of current logs

  6. Start openHAB and restart frontail

These are the main commands used:

ntfsresize -s 500085M /dev/sda1
ntfsfix -d /dev/sda1
fdisk /dev/sda
partprobe
mkfs.ext4 /dev/sda2
vi /etc/fstab
mount -a
dphys-swapfile swapoff
swapoff -a
cd /var
sudo rm swap
dphys-swapfile uninstall
mkswap /dev/sda3
swapon /dev/sda3
cp -rp /var/log/* /media/linux/openhabianpi/logs
systemctl start openhab2
systemctl restart frontail

These are the relevant lines form /etc/fstab:

UUID=[...] /media/linux  ext4 noatime 0 0
/media/linux/openhabianpi/logs  /var/log                 none bind 0 0

/usr/share/openhab2          /srv/openhab2-sys           none bind 0 0
/etc/openhab2                /srv/openhab2-conf          none bind 0 0
/var/lib/openhab2            /srv/openhab2-userdata      none bind 0 0
/var/log/openhab2            /srv/openhab2-logs          none bind 0 0
/usr/share/openhab2/addons   /srv/openhab2-addons        none bind 0 0

UUID=[...]                none swap defaults 0 0

Did I do anything wrong or there is anything missing? If I go /var/log/openhab2, files there are simply not being updated while I can see the new log lines through the openHAB console.

Well, in order to avoid a bind mount on a bind mount, I changed fstab as follows:

UUID=[...]                                /media/linux         ext4 noatime 0 0
/media/linux/openhabianpi/logs            /var/log             none bind 0 0
/media/linux/openhabianpi/logs/openhab2   /srv/openhab2-logs   none bind 0 0

/usr/share/openhab2          /srv/openhab2-sys           none bind 0 0
/etc/openhab2                /srv/openhab2-conf          none bind 0 0
/var/lib/openhab2            /srv/openhab2-userdata      none bind 0 0
/usr/share/openhab2/addons   /srv/openhab2-addons        none bind 0 0

Now /var/log/openhab2 is empty, so I see openHAB is not writing anything there - which probably explains why the log files were not being updated.

Could this be related to permissions on that directory?

drwxr-xr-x 2 root        root     4096 Jan 21 16:30 openhab2

Most probably, what is the output of openhab-cli info?

They should be owned by openhab:openhab (or similar), so you can change this by using

sudo chown -R openhab:openhab /var/log/openhab2

Thanks, that was indeed the problem! I couldn’t find any errors on openhab-cli, but this one displayed the permission errors:

journalctl --lines=100 -u openhab2

And these changes fixed the permissions (I based it on the other existing mountpoints), followed by a restart of openhab2 and frontail:

chown openhab:openhabian openhab2
chmod 775 openhab2
1 Like

Hello,

i have a problem to move the logs (/var/log/) to USB. I have mount (permenant) USB-Stick to /home/openhab/ in “fstab”:

UUID=eac623f2-c16e-417a-9a5c-b6bbd77b9203       /home/openhab/  ext4    noatime 0       0

the next step would be in “fstab”:

/home/openhab/logs           /var/log                               none bind 0 0
/home/openhab/logs/openhab2  /srv/openhab2-logs_neu                 none bind 0 0

right? But then the log Viewer dont show any logs :confused:

What i do worng? permission?