0. Notes
- When writing this article, I ran the commands as root on Debian 11.
1. Configure iSCSI initiator
a. Install iSCSI initiator tools
|
|
b. Discover the target
|
|
This returns the IP and IQN addresses of the target. The useful bit is the IQN address.
c. (OPTIONAL) Discover the target using CHAP
If your target requires CHAP for discovery, then you need to follow this step instead of step b.
|
|
This of course would fail but it generates the corresponding sendtargets configuration file.
Edit /etc/iscsi/send_targets/10.10.11.6,3261/st_config to add/change the lines as follows:
|
|
Then restart the iscsid.service:
|
|
Now use discoverydb mode with the --discover flag passed in to instruct iscsiadm to discover targets using the existing configurations.
|
|
d. Configure CHAP authentication for the node
After the target is discovered, the configuration file of the corresponding node should have been generated.
Edit /etc/iscsi/nodes/iqn.iscsi.truenas.r510.vmdata1/10.10.11.6,3260 to add/change the lines as follows:
|
|
Then restart the iscsid.service:
|
|
e. Connect to the target
|
|
|
|
You should be able to also see it using lsblk:
|
|
2. Make a file system and mount it in /etc/fstab
a. Configure the iSCSI target to connect at system boot
Edit /etc/iscsi/nodes/iqn.iscsi.truenas.r510.vmdata1/10.10.11.6,3260 to change the corresponding line as follows:
|
|
b. Create a file system on the iSCSI disk
|
|
c. Edit /etc/fstab to mount the file system automatically at system boot
Get the UUID of the file system:
|
|
Then add the following line to /etc/fstab:
|
|
The fourth field here is based on what the
defaultsparameter uses as specified in the manual page offstab, withdevchanged to_netdevto ensure the system won’t try mounting the iSCSI disk until network is properly started. To mount the file system immediately instead of waiting until next reboot:
|
|
It should be all good now:
|
|
3. References:
Red Hat documentation on iSCSI initiator
Red Hat documentation on setting up CHAP for iSCSI connection
Franciscon Santos' answer in Unix & Linux StackExchange regarding the _netdev mounting parameter