Installing Sanoid on TrueNAS Scale 23.10.1

I’m having an issue with installing sanoid on the latest version of TrueNAS scale. If I build from source or install from apt, it wants to uninstall middlewared and a few other important items. I installed it without looking at what it was doing and it broke my install and I had to rollback a snapshot to get it booting again.

The following packages will be REMOVED:
  cifs-utils linux-truenas-production-libc-dev middlewared openzfs-libnvpair3 openzfs-libuutil3 openzfs-libzfs4 openzfs-libzpool5 openzfs-zfs-initramfs openzfs-zfs-zed openzfs-zfsutils python3-libzfs python3-midcli truenas truenas-samba zectl
The following NEW packages will be installed:
  dkms libnvpair3linux libuutil3linux libzfs4linux libzpool5linux linux-libc-dev sanoid zfs-dkms zfs-zed zfsutils-linux

So what do I need to do to install sanoid on TN without breaking TN?

Wow! That’s quite a list of things to uninstall. truenas really jumped out at me.

Is this a vanilla TN install? I’m wondering if something customized in your setup conflicted with sanoid and triggered removal of these packages.

Other than that, I have no idea, but this is certainly the right place to ask!

Don’t try to install sanoid (via apt). It’s just a script that you can place anywhere in your path (along with the relevant config files which also can be put in a custom location if you so desire). So just download the latest sanoid version from GitHub - jimsalterjrs/sanoid: Policy-driven snapshot management and replication tools. Using ZFS for underlying next-gen storage. (Btrfs support plans are shelved unless and until btrfs becomes reliable.) Primarily intended for Linux, but BSD use is supported and reasonably frequently tested. and directly use it (and of course customize the config files).

What you do need for sanoid to work nicely are the following packages:

libcapture-tiny-perl libconfig-inifiles-perl pv lzop mbuffer

So you can:

apt install libcapture-tiny-perl libconfig-inifiles-perl pv lzop mbuffer

Remember that you’re going to loose all these customizations when you upgrade TrueNAS - so keep notes/script-snippets of whatever changes you make so that you can quickly get back to your desired special setup on top of TrueNAS after any upgrade in the future.

3 Likes

This should be vanilla, other than activating apt and dpkg (which is disabled by default in TN). I’ve installed Sanoid on TN before, but something changed in this latest version of TN that is making things break.

The weird thing to me is that I’ve installed Sanoid on TN before using apt and building it by following the debian/ubuntu instructions on github and haven’t had problems until 23.10.1, not sure what changed in TN to cause these issues.

I will try what you suggested and report back if it doesn’t work, thanks!

This is the correct answer. Drop the scripts in your path (personally, I use /usr/local/bin, but it’s up to you), chmod them 755, then create /etc/sanoid and dump in sanoid.defaults.conf and sanoid.conf. install the dependencies via apt as already described, and Bob’s your uncle.

For the service and timers, I can get sanoid-prune.service sanoid.service sanoid.timer from sanoid/packages/debian and put them in /etc/systemd/system/ , right?

This seems to have worked, the only thing I had to change from the manual/CentOS instructions on github was ln -s /usr/local/sbin/sanoid /usr/sbin/sanoid so the timer could find sanoid.

1 Like

Old thread now - but I have been working on an update script.

I’ll put it on github in the next little while probably, but for now, here’s a copy

AS IS
IF IT BREAKS YOU GET TO KEEP ALL THE PIECES

#!/bin/bash

# Set script to exit on error
set -e
set -o pipefail
set -u

# FIXME
# should use -v or --verbose to control terminal output

###################
# Variable set up #
###################

# YOU MUST HAVE THESE SANOID SCRIPTS AND CONF FILES IN THIS DIRECTORY
SANOID_FILES_PATH="/home/admin/Enable-Sanoid"
SANOID_FILES=(
"findoid"
"sanoid"
"sleepymutex"
"syncoid"
"sanoid.conf"
"sanoid.defaults.conf"
"sanoid-prune.service"
"sanoid.service"
"sanoid.timer"
)

# IF YOU CHANGE THE FILE LIST CHANGE THESE ARRAYS TO MATCH
SCRIPTS="0 1 2 3"
CONF="4 5"
SYSD="6 7 8"

# THIS SHOULDN'T NEED CHANGING
SCRIPTS_DIR="/usr/local/bin"
LINKS_DIR="/usr/local/sbin"
CONF_DIR="/etc/sanoid"
SYSD_DIR="/etc/systemd/system"
LOGFILE="/var/log/setup-script.log"
DATESTAMP=$(date "+%Y-%m-%d_%s")
APT_SOURCES_PATH="/etc/apt"
APT_SOURCES_FILE="sources.list"

################
# Script start #
################

# Check if run with enough privileges
ISROOT=$(id -u)
if [ "$ISROOT" -ne 0 ]; then
    echo "--------------------------------------------------------";
    echo "Error - insufficient privileges.  Run with sudo or root.";
    echo "--------------------------------------------------------";
    exit 1;
fi


# Enable logging
exec > >(tee -i "$LOGFILE")
exec 2>&1


# Start
echo
echo "========================================================";
echo "              Starting script execution"
echo "========================================================";

# Check if all sanoid files available
echo
echo -n "-- Checking required sanoid files "
for FILE in "${SANOID_FILES[@]}" ; do
    ([ -r "${SANOID_FILES_PATH}/${FILE}" ] && echo -n '.') || (echo "Missing $FILE, exiting" && exit 1)
done
echo


# Attempt to remount /usr read+write
echo
echo "-- Remounting usr as read write"
DATASET=$(findmnt -fn --output=source --mountpoint /usr)
if [ -z "$DATASET" ] ; then
    echo "Error - couldn't determine /usr mount";
    exit 1;
else
    echo "Completed" ;
    mount -o remount,rw "$DATASET";
fi


# Re-enabling apt utilities
echo
echo "-- Adding executable flag to re-enable apt utilities"
chmod -c +x /bin/apt*
chmod -c +x /usr/bin/dpkg

# Update sources list
# FIXME should check if additions are already in file and not dupicate them
echo
echo "-- Working on apt sources"
echo
CODENAME="$(lsb_release -cs)"
if [ -z "$CODENAME" ] ; then
    echo "Error - couldn't determine debian codename";
    exit 1;
else
    echo "-- Backing up sources.list";
    cp -v "${APT_SOURCES_PATH}/${APT_SOURCES_FILE}" "${APT_SOURCES_PATH}/${APT_SOURCES_FILE}-${DATESTAMP}"
    echo
    echo "-- Updating sources.list";
    cat << EOF >> "${APT_SOURCES_PATH}/${APT_SOURCES_FILE}"
deb http://deb.debian.org/debian $CODENAME main
deb-src http://deb.debian.org/debian $CODENAME main
EOF
fi


# Install prerequisites
echo
echo "-- Updating repositories"
apt-get update

echo
echo "-- Installing prerequisites via apt"
apt-get install -y libcapture-tiny-perl libconfig-inifiles-perl pv lzop mbuffer


# Restore sources list
echo
echo "-- Restoring sources.list";
echo cp -vf "${APT_SOURCES_PATH}/${APT_SOURCES_FILE}-${DATESTAMP}" "${APT_SOURCES_PATH}/${APT_SOURCES_FILE}"


# Copy scripts to usr local bin
echo
echo "-- Copying scripts into place"
for ITEM in $SCRIPTS ; do
    cp -v "${SANOID_FILES_PATH}/${SANOID_FILES[$ITEM]}" "$SCRIPTS_DIR" ;
done

# Symlink scripts into usr sbin
echo
echo "-- Symlinking scripts"
for ITEM in $SCRIPTS ; do
    ln -vs "${SCRIPTS_DIR}/${SANOID_FILES[$ITEM]}" "${LINKS_DIR}/" ;
done

# Create conf dir if required
echo
echo "-- Creating conf dir if required"
mkdir -pv "${CONF_DIR}"

# Copy conf files into conf dir
echo
echo "-- Copying conf files into place"
for ITEM in $CONF ; do
    cp -v "${SANOID_FILES[$ITEM]}" "$CONF_DIR" ;
done

# Copy services and timer into place and activate
echo
echo "-- Moving conf files into place"
for ITEM in $SYSD ; do
    cp -v "${SANOID_FILES[$ITEM]}" "$SYSD_DIR" ;
done

# Get systemd to see new files
echo
echo "-- Getting systemd to find new service files"
systemctl daemon-reload

# Enable sanoid timer
echo
echo "-- Enabling the sanoid timer"
systemctl enable --now sanoid.timer


# Put usr back as was
echo
echo "-- Remounting usr as read only"
mount -o remount,ro "$DATASET";

# Profit?
echo
echo "========================================================";
echo "        Script execution completed successfully!"
echo "========================================================";

#  vim: set filetype=sh syntax=sh ts=4 sw=4 tw=0 :
2 Likes

OK - I guess it’s up…

Comments etc welcome, here or there.

2 Likes