Setup iSCSI target on Rocky Linux 9 or 8

Configure Rocky Linux 9 or 8 to perform as an iSCSI target source.

With blockio, the device does not need to be mounted. It simply needs to be listed in /dev. With fileio, mount the device.

Switch up to root. Sudo won’t save you.

Install prerequisites
# dnf -y install targetcli


On the initiator, the client, retrieve the initiator’s name. It is required for the ACLS. The name MUST be unique for each machine. We’re going to call this: THE_UNIQUE_INITIATORNAME_FOUND_ABOVE
*** An initiator ACL is required to access the LUNs otherwise the initiator’s query will return empty, blank, LUNs . ***

  • Linux: /etc/iscsi/initiatorname.iscsi
  • Windows: iSCSI Initiator control panel under the Configuration tab


Make a choice or three. are you looking for fileio, blockio, or a ramdisk? Fileio stores iSCSI data in a container file. Blockio bogarts a partition or disk. The ramdisk is self-explanatory.

Create a container file. Note the path.
# dd if=/dev/zero of=/mnt/raid/lun0 bs=1 count=0 seek=5T
Don’t assign a dev by /dev/sda or /dev/sdb. These can be reassigned and often are on servers with more than one disk. Use a /dev/disk/by-* Ensure you’re using the correct drive! Since an R720xd’s H710p card never moves (an R720s can), I chose by-path. Get the storage disk or partition id from:
cd /dev/disk/by-*
nothing to do


Start the app
# targetcli

> cd /backstores/fileio
> create lun0 /mnt/raid/lun0

blockio: *names are limited to 15 characters
> cd /backstores/block/
> create name=sharedblockdev dev=/dev/disk/by-path/pci-0000:03:00.0-scsi-0:2:1:0

ramdisk: *names are limited to 15 characters
> cd /backstores/ramdisk/
> create name=sharedramdisk size=10GB

Create the iSCSI target
> cd /iscsi
> create

Add storage to the target
> cd /iscsi/
> create /backstores/fileio/lun0
> create /backstores/block/sharedblockdev
> create /backstores/ramdisk/sharedramdisk

Create initiator login
> cd /iscsi/

> exit



Make a copy of your config
# cp /etc/target/saveconfig.json /etc/target/saveconfig.json.copy


Add incoming firewall rule:
# firewall-cmd --add-service=iscsi-target --permanent; firewall-cmd --reload

Enable the service, restart, and check the status for errors
# systemctl enable target;systemctl restart target;systemctl status target

On a windows client…
Open iSCSI Initiator
Enter the target IP address
Click quick connect

Open diskmgmt.msc
initialize & format the new disks
Proxmox > datacenter > storage add iSCSI device, then add an LVM device linked to the created iSCSI device.

* Yeah, yeah. Use sudo because that’s what you’re supposed to do. Remember, sudo still won’t stop you from being an idiot, it’ll just provide a log of your stupidity so everyone can secretly call you an idiot.

Leave a Reply