TSF – Giải pháp IT toàn diện cho doanh nghiệp SMB | HCM

P7 - Set Quota Limits for HomeFolders TrueNas

🚀 TrueNAS P7 – How to Set Quota Limits for HomeFolders (User Quota Setup Guide)

Managing storage efficiently is critical in any SMB + Active Directory environment.
In this guide, you’ll learn how to configure Quota Limits for HomeFolders TrueNAS using ZFS user quotas.

We will:

  • Understand the difference between dataset quotas and user quotas

  • Export domain users from Active Directory

  • Create a CSV quota assignment file

  • Use a Python automation script to apply ZFS user quotas

  • Verify quota usage and prevent disk exhaustion

Quotas are essential to prevent users from consuming excessive storage and causing unexpected disk full errors. This method provides scalable, secure, and enterprise-ready storage control.


🧠 Dataset Quota vs User Quota (Important Concept)

Before configuring Quota Limits for HomeFolders TrueNAS, it’s important to understand the difference:

📦 Dataset Quota

  • Applies to the entire dataset

  • Limits total storage consumption

  • Does NOT differentiate per user

👤 User Quota (Recommended)

  • Applies per individual user

  • Uses ZFS userquota

  • Ideal for SMB + Active Directory environments

  • Provides granular control

For HomeFolder environments, User Quota is the correct method.


⚙️ Step 0: (Optional) Set Total Dataset Capacity

You may define a maximum size for the entire Homefolder dataset.

This ensures that even if user quotas are misconfigured, the dataset cannot exceed a predefined size.

This step is optional but recommended for enterprise environments.


🔎 Step 1: Get the List of HomeFolder Users from AD

On your Active Directory server, open PowerShell and run:

💻
filename.bash
Get-ADUser -Filter * -Properties DistinguishedName |
Select-Object SamAccountName,
@{Name="OU";Expression={($_.DistinguishedName -replace '^CN=[^,]+,', '')}} |
Export-Csv "C:\ad_user_with_ou.csv" -NoTypeInformation -Encoding UTF8

This command:

  • Retrieves all domain users

  • Extracts their OU information

  • Exports the result to CSV (UTF-8 format)

You can filter departments or specific OUs depending on your quota policy.


📄 Step 2: Create CSV File for Quota Import

Create a CSV file with two columns:

 
 
username,quota_gib
 

In this demo:

  • We assign quota to 2 normal users

  • Admin user it01 is NOT limited

⚠ Important Notes:

  • CSV must be UTF-8

  • No quotes

  • Comma separator only

Example content:

 
 
sale01,1
hr01,2
 

Copy the file to TrueNAS:

 
 
/home/admin/quota.csv
 

Verify the file:

 
 
cat /home/admin/quota.csv
 

🐍 Step 3: Create Standard Python Script for TrueNAS (set_quota.py)

Create the script file:

 
 
sudo nano /home/admin/set_quota.py
 

Full content:

💻
filename.bash
#!/usr/bin/env python3
import csv
import subprocess

# Dataset chứa Homefolder
DATASET = "volume1/Homefolder" # Name dataset apply

CSV_FILE = "/home/admin/quota.csv" # Link file quota.csv
DOMAIN = "TSF" # your domain

def gib_to_bytes(gib_value):
    return int(float(gib_value) * 1024**3)

with open(CSV_FILE) as f:
    reader = csv.DictReader(f)
    for row in reader:
        username = row["username"].strip()
        quota_gib = row["quota_gib"].strip()

        user_quota_bytes = gib_to_bytes(quota_gib)

        # user format: TSF\username
        zfs_user = f"{DOMAIN}\\{username}"

        # zfs command:
        cmd = [
            "zfs", "set",
            f"userquota@{zfs_user}={user_quota_bytes}",
            DATASET
        ]

        print("Running: ", " ".join(cmd))
        subprocess.run(cmd)

🔍 What This Script Does

  • Reads username and quota size from CSV

  • Converts GiB to bytes

  • Applies userquota using ZFS command

  • Automates bulk quota configuration

This method is scalable and ideal for environments with dozens or hundreds of users.


▶️ Step 4: Grant Permission and Execute Script

Grant execute permission:

 
 
sudo chmod +x /home/admin/set_quota.py
 

Run the script:

 
 
sudo /home/admin/set_quota.py
 

Done ✅

All specified users now have their quota limits applied.


📊 How to Verify Quota Usage

To verify applied quotas:

 
 
zfs get userquota@TSF\\sale01 volume1/Homefolder
 

To check usage:

 
 
zfs userspace volume1/Homefolder
 

These commands help IT admins:

  • Monitor storage consumption

  • Identify users near quota limits

  • Prevent unexpected service disruption


🛠 Troubleshooting Common Issues

If quota does not apply:

✔ Ensure dataset name is correct
✔ Confirm domain format (TSF\username)
✔ Check CSV format (UTF-8, no quotes)
✔ Verify AD user exists
✔ Confirm SMB + AD integration is healthy

Most issues occur due to formatting errors in CSV or incorrect domain syntax.


🏢 Recommended Quota Strategy for SMB + AD

For enterprise environments:

  • 1–2 GiB for standard staff

  • 5–10 GiB for managers

  • Unlimited for IT admins

  • Set dataset-level soft ceiling

  • Monitor usage monthly

Properly configured Quota Limits for HomeFolders TrueNAS ensures:

  • Stable system performance

  • Controlled storage growth

  • Predictable capacity planning

  • Reduced operational risk


🎯 Final Result

After completing this setup:

  • Each domain user has a defined quota

  • Storage abuse is prevented

  • Disk full errors are minimized

  • IT admins maintain full control

Implementing Quota Limits for HomeFolders TrueNAS is a critical step in building a professional and well-controlled TrueNAS environment.

See also related articles

P21 – Effortless WordPress TrueNAS Setup Guide

P21 – Effortless WordPress TrueNAS Setup Guide 🚀 TrueNAS P21 – WordPress TrueNAS Apps Demo Deploy WordPress Easily (No Docker Skills Needed) Deploying WordPress on a NAS no longer requires deep Docker knowledge or complex manual configurations. With WordPress TrueNAS Apps, you can launch a fully functional WordPress instance directly...

Read More

P20 – Essential ZFS Disk Scrubbing Best Practices Guide

P20 – Essential ZFS Disk Scrubbing Best Practices Guide 🚀 TrueNAS – P20: ZFS Disk Scrubbing – Step-by-Step Configuration & Best Practices Maintaining data integrity is one of the most important responsibilities of any storage administrator. Even enterprise-grade disks can develop silent data corruption over time. This is where ZFS...

Read More

P18 – Ultimate MFA TrueNAS Security Setup Guide

P18 – Ultimate MFA TrueNAS Security Setup Guide 🚀 TrueNAS – P18: Secure TrueNAS with MFA (Google Authenticator) – Full Configuration Tutorial Security is critical for any production storage system. A strong password alone is no longer enough. If credentials are leaked, brute-forced, or reused elsewhere, your entire NAS infrastructure...

Read More