how to mount encrypted zfs dataset
- User
how to mount encrypted zfs dataset
- Assistant
To mount an encrypted ZFS dataset, you need to perform a few specific steps depending on whether the encryption is native ZFS encryption (a feature introduced in ZFS 0.8.0+) or you're using a third-party encryption method (like LUKS or eCryptfs). This guide focuses on native ZFS encryption.
🛡️ Mounting a Native Encrypted ZFS Dataset
✅ Prerequisites
- You're using ZFS version 0.8.0 or newer (check via
zfs --version) - The dataset was created with encryption enabled (check with
zfs get encryption <dataset>)
🔐 Steps to Unlock and Mount an Encrypted Dataset
1. Import the ZFS Pool
If your pool is not already imported, import it first:
zpool import <poolname>
2. Check the Encryption Status
Verify if the dataset is encrypted and locked:
zfs get encryption,keylocation,keyformat,keystatus <poolname>/<dataset>Example output:
NAME PROPERTY VALUE SOURCE tank/securedata encryption aes-256-gcm - tank/securedata keylocation prompt local tank/securedata keystatus unavailable -If
keystatus = unavailable, it means the dataset is locked.
3. Load/Unlock the Encryption Key
💻 If the keylocation is
prompt(i.e. passphrase required):zfs load-key <poolname>/<dataset>You will be prompted for the passphrase.
🔑 If using a key file (e.g., located at
/root/tank.key):Then the dataset likely has:
keylocation=file:///root/tank.key
Just load it directly:
zfs load-key <poolname>/<dataset>ZFS will read the key file as per the
keylocationproperty.
4. Mount the Dataset
After unlocking, mount the dataset if it's not auto-mounted:
zfs mount <poolname>/<dataset>Or mount all unlocked datasets:
zfs mount -a
🔄 Optional: Auto-load Key on Boot
Set
keylocationto a file:zfs set keylocation=file:///etc/zfs/keys/tank.key <poolname>/<dataset>Ensure the key is stored securely, and permissions are restricted.
Also, enable auto-mounting and key loading via systemd if supported on your distro (e.g.,
zfs-load-key@<dataset>.service).
🧯 Troubleshooting
🔍 Check Mount Status
zfs listLook at the
MOUNTPOINTandmountedproperties.🔐 Relock Dataset (if needed)
zfs unload-key <poolname>/<dataset>
📘 Example: Full Flow
zpool import tank zfs load-key tank/securedata zfs mount tank/securedata
Let me know if you're using ZFS on a system like Ubuntu, FreeBSD, or need auto-unlocking via TPM or ssh-agent — I can tailor for that.
- You're using ZFS version 0.8.0 or newer (check via
- User
how to use sanoid
- Assistant
Sanoid is a powerful and flexible tool for automatically managing ZFS snapshots based on a policy. It's typically used for automated snapshot creation and retention on systems using ZFS (like Linux, FreeBSD, or Illumos-based systems).
📝 What Does Sanoid Do?
- Takes periodic snapshots of ZFS datasets
- Prunes old snapshots according to a retention policy
- Can be run as a systemd timer, cron job, or manually
- Works great with syncoid for replication
✅ How to Use Sanoid – Step-by-Step
1. 🚀 Install Sanoid
For Debian/Ubuntu:
sudo apt update sudo apt install sanoidFor Arch Linux:
yay -S sanoidFor RHEL/CentOS/Fedora:
Install Perl dependencies first, then clone it manually from GitHub:
git clone https://github.com/jimsalterjrs/sanoid.git cd sanoid sudo cp sanoid /usr/sbin/ sudo cp sanoid.defaults.conf /etc/sanoid/sanoid.conf
2. 🛠️ Configure Sanoid
Edit the main Sanoid config file:
sudo nano /etc/sanoid/sanoid.confA sample config might look like this:
[tank/home] use_template = prod recursive = yes [tank/var] use_template = prod [template_prod] hourly = 24 daily = 7 weekly = 4 monthly = 3 autosnap = yes autoprune = yes🔍 Explanation:
tank/home– the dataset to managerecursive– apply to child datasetsuse_template– defines snapshot intervalsautosnap– whether to create snapshotsautoprune– whether to delete old ones
3. 📆 Run or Schedule Sanoid
✅ To run manually:
sudo sanoid --debug🕒 To run automatically via
systemd(on systemd-based systems):Sanoid comes with a timer. Enable and start it:
sudo systemctl enable --now sanoid.timerCheck status:
systemctl status sanoid.timerThis runs
sanoid.servicehourly.
4. 📂 View Your Snapshots
Use
zfs list -t snapshotto see:zfs list -t snapshotYou will see snapshots like:
tank/home@auto_hourly-2024-05-04-0100
5. 🔁 Combine with Syncoid for Replication (Optional)
Sanoid’s companion tool syncoid can replicate snapshots:
syncoid tank/home root@backup:/tank-backup/home
🧪 Testing Sanoid
You can simulate snapshot creation/pruning without applying changes:
sudo sanoid --pretend
🧯 Troubleshooting Tips
- Make sure dataset names in the config exactly match
zfs listoutput - Set correct permissions (Sanoid needs to run as root or have ZFS privileges)
- Logs typically go to
journalctl -u sanoidon systemd systems
📌 Summary
Task Command/Step Install Sanoid apt install sanoid(Debian-based)Configure datasets /etc/sanoid/sanoid.confRun manually sudo sanoid --debugEnable scheduling systemctl enable --now sanoid.timerView snapshots zfs list -t snapshot
Let me know if you want a sample sanoid.conf, a syncoid replication setup, or custom snapshot policy!
- User
implement GFS using sanoid on debian/ubuntu
- Assistant
Implementing GFS (Grandfather-Father-Son) backups using Sanoid on Debian/Ubuntu is a great way to automate rotating ZFS snapshots with retention policies split into hourly (sons), daily (fathers), weekly/monthly (grandfathers) snapshots.
Below is a complete guide to implement GFS-style backups with Sanoid on a ZFS dataset.
🛰️ Overview of GFS with Sanoid (Snapshot Retention Strategy)
Snapshot Type Frequency Retention Purpose Hourly Every hour 24 hrs "Son" (recent recovery) Daily Daily 7 days "Father" (short-term) Weekly Weekly 4 weeks "Grandfather" (long-term) Monthly Monthly 3 months "Archival"
✅ Step 1: Install ZFS and Sanoid on Debian/Ubuntu
Install ZFS:
sudo apt update sudo apt install zfsutils-linuxInstall Sanoid:
Sanoid is in apt repositories (Ubuntu ≥ 20.04 / Debian 11+):
sudo apt install sanoidFor older versions, install from source (let me know if needed).
✅ Step 2: Set Up a ZFS Dataset
Create a dataset or use an existing one:
sudo zfs create tank/data
✅ Step 3: Configure Sanoid for GFS
Edit the config file:
sudo nano /etc/sanoid/sanoid.conf🧾 Sample Config for GFS (Replace
tank/datawith your dataset):[tank/data] use_template = GFS recursive = yes [template_GFS] hourly = 24 ; Keep 24 hourly snapshots (1 day) daily = 7 ; Keep 7 daily snapshots (1 week) weekly = 4 ; Keep 4 weekly snapshots (1 month) monthly = 3 ; Keep 3 monthly snapshots autoprune = yes ; Automatically remove old snapshots autosnap = yes ; Automatically take snapshotsExplanation:
auto_hourly-<timestamp>taken every hour- After it becomes a day old, it's discarded unless part of a daily/weekly snapshot
- Sanoid handles aging snapshots automatically via timestamp pattern matching
✅ Step 4: Enable the Sanoid Timer (Automatic Snapshots)
Sanoid provides a systemd timer to automate snapshot creation.
sudo systemctl enable --now sanoid.timer sudo systemctl status sanoid.timer📅 It runs every hour by default (
/lib/systemd/system/sanoid.timer).
✅ Step 5: Test Sanoid
Run manually to test snapshot creation:
sudo sanoid --debugOr simulate without making changes:
sudo sanoid --pretend
✅ Step 6: View Snapshots
Use ZFS directly:
zfs list -t snapshotSample output:
tank/data@auto_hourly-2025-05-04-10:00 tank/data@auto_daily-2025-05-03
✅ Optional: Use with Syncoid to Replicate Snapshots
Install
syncoid:sudo apt install syncoidPush snapshots to backup host:
syncoid tank/data backup@192.168.1.10:tank/backup
🧾 Sanoid Configuration Summary
Located at:
/etc/sanoid/sanoid.conf[tank/data] use_template = GFS recursive = yes [template_GFS] hourly = 24 daily = 7 weekly = 4 monthly = 3 autosnap = yes autoprune = yes
🔄 Customize Retention
Change to suit your needs:
Type Entry Meaning hourly hourly=48Keep 2 days hourly daily daily=14Keep 2 weeks daily weekly weekly=8Keep 2 months weekly monthly monthly=6Keep 6 months monthly
📌 Summary
Step Command Install Sanoid & ZFS sudo apt install sanoid zfsutils-linuxEdit config file sudo nano /etc/sanoid/sanoid.confEnable systemd automation sudo systemctl enable --now sanoid.timerManually test sudo sanoid --debugView snapshots zfs list -t snapshot
Would you like a ready-to-use sanoid.conf template, multiple datasets setup, or syncoid replication instructions as well?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.