Internet SCSI

is an IP-based storage networking standard for linking data storage facilities. iSCSI provides block-level access to storage devices by carrying SCSI commands over a TCP/IP network.

The protocol allows clients (called initiators) to send SCSI commands to storage devices (targets) on remote servers. It is a storage area network (SAN) protocol, allowing organizations to consolidate storage into storage arrays while providing clients (such as database and web servers) with the illusion of locally attached SCSI disks.

Source: Wikipedia

Format and mount a NAS iSCSI drive (XFS for Mongo)

In TrueNAS

Shares > Block (iSCSI) > Wizard

  • (non-specified mandatory options as per their default, non-mandatory ones empty)
  • Create or Choose Block Device: Select existing Zvol or create a new one. Name and Size can be whatever
  • Portal: IP Address: 192.168.1.100 (0.0.0.0 works too)
  • Initiator: leave empty or enter mongohost’s IQN, e.g. iqn.1993-08.org.mongohost:01:32b26b160c7, cf sudo cat /etc/iscsi/initiatorname.iscsi

On target system

sudo apt update && sudo apt install -y open-iscsi xfsprogs
 
# Connect iSCSI device
 
sudo iscsiadm -m discovery -t sendtargets -p truenas # Eg: 192.168.1.100:3260,1 iqn.2005-10.org.freenas.ctl:xfs-iscsi
sudo iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:xfs-iscsi -p 192.168.1.100:3260 --login
lsblk # or `ls -l /dev/disk/by-path/` to identify new device => Eg: /dev/sdb
 
# Format to XFS if needed
 
lsblk -f /dev/sdb # Check if filesystem already formatted. If so, skip to mount
sudo mkfs.xfs /dev/sdb # If needed
 
# Mount (test)
 
sudo mkdir /mnt/nas-xfs
sudo mount /dev/sdb /mnt/nas-xfs && ls -al /mnt/nas-xfs # To test
sudo chown 999:999 /mount/point # If needed, to match a certain user
 
# Auto mount
 
sudo iscsiadm -m node -T iqn.2005-10.org.freenas.ctl:xfs-iscsi -p 192.168.1.100:3260 --op update -n node.startup -v automatic # Will modify /etc/iscsi/nodes/iqn.2005-10.org.freenas.ctl:xfs-iscsi/192.168.1.100,3260,1/default
sudo vim /etc/fstab # Add "/dev/sdb /mnt/nas-xfs xfs defaults,nofail,x-systemd.requires=iscsi.service 0 0"
sudo reboot # To test
 
# If dockerd starts before iscsid, i.e. Mongo is not using the mounted XFS filesystem
sudo systemctl edit docker.service
### Add near the top
[Unit]
After=iscsid.service
Requires=iscsid.service
###

TODO: Why is the nofail option necessary? According to sudo journalctl -b, the iSCSI drive is connected before the mount attempt for /mnt/nas-xfs-zvol and so it shouldn’t be a problem