Skip to content

Instantly share code, notes, and snippets.

@ngoc-minh-do
Created October 20, 2025 03:05
Show Gist options
  • Select an option

  • Save ngoc-minh-do/2f87d7281afdd1130f0ab1f40525dd78 to your computer and use it in GitHub Desktop.

Select an option

Save ngoc-minh-do/2f87d7281afdd1130f0ab1f40525dd78 to your computer and use it in GitHub Desktop.

TrueNAS iSCSI Setup for Linux Clients

πŸ”§ TrueNAS Configuration

1. Create a Zvol

  • Navigate to Datasets, select your Dataset
  • Click Add Zvol
    • Name: e.g., iscsi-disk01
    • Size: e.g., 10GiB
    • Leave other settings default
      • Sync: Standard
      • Compression: lz4
      • ZFS Deduplicateion: off
      • Block size: 16KiB

2. Enable iSCSI Service

  • Go to System Settings β†’ Services
  • Enable and start iSCSI

3. Configure iSCSI Share

  • Navigate to Shares β†’ Block (iSCSI)
  • Click Wizard
    • Target: create new target
    • Extent: Device type β†’ select the Zvol you created
    • Sharing Platform: Modern OS
    • Portal: either β€œCreate new” or default (you can use 0.0.0.0:3260)
    • Initiator: leave blank (for any initiator) or specify your Linux host’s IQN
  • After wizard, edit the target if desired:
    • Set Authorized Networks (e.g., 192.168.0.0/24) for access control
  • Save changes and verify that the target is listed

🐧 Linux Client Setup

1. Install iSCSI Utilities

sudo apt install open-iscsi

2. Discover Target

sudo iscsiadm -m discovery -t sendtargets -p <truenas-ip>

3. Login to Target

sudo iscsiadm -m node -T <target-iqn> -p <truenas-ip> --login

βœ… After login, a new device will show up, e.g., /dev/sdX

lsblk

4. Format and Mount

  1. Format the Disk Create an ext4 filesystem on the new disk:

    sudo mkfs.ext4 /dev/sdX

    Replace /dev/sdX with the actual device name from login step.

  2. Create Mount Point

    sudo mkdir -p /mnt/iscsi
  3. Mount Manually (for testing)

    sudo mount /dev/sdX /mnt/iscsi

    Ensure the mount works before adding to persistent configuration.

5. Persist the Mount on Boot

  1. Enable iSCSI Auto-login

    sudo iscsiadm -m node -T <target-iqn> -p <truenas-ip> --op update -n node.startup -v automatic
  2. Get the UUID of the Device

    sudo blkid /dev/sdX

    Copy the UUID="..." string from the output.

  3. Update /etc/fstab Append bellow line:

    UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /mnt/iscsi ext4 _netdev,noatime 0 2
    
    • UUID=...: identifies the disk
    • /mnt/iscsi: your mount point
    • ext4: filesystem type
    • _netdev: ensures mounting waits for network
    • noatime: disable updating file's access time
    • 0 2: backup and fsck order

    Run a test:

    sudo mount -a

πŸš€ Expanding Storage (Zvol Resize)

  1. In TrueNAS: Dataset β†’ select your Zvol β†’ Edit Zvol β†’ increase size
  2. On Linux:
    1. Rescan to detect new size:

      echo 1 | sudo tee /sys/class/block/sdb/device/rescan
    2. Resize ext4 Filesystem (Since there's no partition, resize the filesystem directly):

      sudo resize2fs /dev/sdb

πŸ§ͺ Test & Verify

  • Use lsblk, df -h, or mount to confirm the disk
  • Reboot to verify persistence (if fstab is configured)

πŸ“Œ Notes

  • Target IQN format: iqn.YYYY-MM.domain:targetname
  • Ensure the TrueNAS and client clocks are synchronized
  • Avoid overlapping LUNs or targets
  • No need for CHAP unless securing over public networks
  • No need for parted or fdisk when resizing if there's no partition table.
  • resize2fs works even if the filesystem is mounted (for ext4).

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment