Moving log files to seperate disc

Started by Lantern5, August 04, 2024, 02:14:17 PM

Previous topic - Next topic
Hi all,

Linux newbie here and just started testing Opnsense for home use. Reading through the forums, it appears that moving log files to a different disc is a good idea to prevent SSD wear. But how? And can it be done after installation?

There are a couple of threads on the topic, but not much info for a beginner. Can someone please explain this like I'm 5?

Couple of links I read on the topic
https://forum.opnsense.org/index.php?topic=14043
https://forum.opnsense.org/index.php?topic=32148.0

I am using ZFS filesystem in case  that's relevant.

August 05, 2024, 10:01:00 AM #1 Last Edit: August 05, 2024, 02:20:15 PM by meyergru
This will all work ONLY in single-user mode, because you need to move the mountpoint around which is normally constantly written to by all kinds of services!

You can initiate single user mode from the console during booting (option 2 or S) after you attach the second disk.

Just above the shell prompt, you will see the disks, you can also list them via:

grep -E 'da[0-9]|nvd[0-9]|nvme[0-9]' /var/run/dmesg.boot


The first disk (often nda0 or da0) will usually be your boot disk and you can look at its partitioning via:


gpart list nda0 | more


Be aware that the numbering may be reversed, such that nda1 is your boot disk!


You can verify this by listing the partitions on that boot disk via:

gpart list nda0


With ZFS, you will mostly see EFI, FREEBSD-BOOT, FREEBSD-SWAP and FREEBSD-ZFS partitions on your boot disk.

You can also use "zpool status" to look at your zpools, and most likely you will see soemthing like:

  pool: zroot
state: ONLINE
  scan: scrub repaired 0B in 00:00:15 with 0 errors on Thu Jul 18 04:17:15 2024
config:

        NAME        STATE     READ WRITE CKSUM
        zroot       ONLINE       0     0     0
          nda0p4    ONLINE       0     0     0


In this case, it was nda0, partition 4 where my zroot was on.

The newly attached disk will most likely be empty and have no partitions at all (indicated by something like: "gpart: Class 'PART' does not have an instance named 'nda1'." as response to "gpart list nda1").

You can create a new ZFS pool on it like so:


mount -u /
zfs mount -a
zpool create logging nda1


This will auto-create a disk label and the neccessary partitions.

Then, create the neccessary ZFS datasets:


zfs create logging/var
zfs create logging/var/log
zfs set mountpoint=none logging
zfs set mountpoint=none logging/var
zfs set mountpoint=/var/log2 logging/var/log


Now, copy the /var/log content over, clear the old logs and set the mountpoint of /var/log to the new ZFS dataset:


cp -rp /var/log/ /var/log2/
rm -rf /var/log/*
zfs set mountpoint=none zroot/var/log
zfs set mountpoint=/var/log logging/var/log


Verify that /var/log is now on "logging/var/log" and after that, reboot.


zfs list
reboot

Intel N100, 4 x I226-V, 16 GByte, 256 GByte NVME, ZTE F6005

1100 down / 800 up, Bufferbloat A+

Thank you, will try it out over the weekend and report back