A quick hook script to automate zfs zone in proxmox

It’s a proxmox hookscript.

Documentation is located here: hookscripts

You have to place it in /var/lib/vz/snippets and add it to the conf of your lxc at /etc/pve/lxc by adding (in my configuration)

hookscript: local:snippets/hook121.sh

I’m using this without any problems to automate ZFS zoning on my proxmox.

#!/bin/bash

vmId="$1"
runPhase="$2"
echo "Running $runPhase on VM=$vmId"

case "$runPhase" in
    post-start)
        pid=$( lxc-info -n $1 -p | awk '/PID:/{print $NF}' )
        zfs zone /proc/$pid/ns/user sata/ct/urbackup
        echo "zfs zone"
        ;;
    pre-stop)
        pid=$( lxc-info -n $1 -p | awk '/PID:/{print $NF}' )
        zfs unzone /proc/$pid/ns/user sata/ct/urbackup
        echo "zfs unzone"
        ;;
esac