targetcli ist ein Tool zum verwalten von [[iSCSI]] Targets. Siehe auch [[iscsitarget]]. =====Installation===== ====FileIO==== Um ein iSCSI-Target zu erstellen, brauchst du auf dem Server [[targetcli]]. Installiere es mit: sudo apt update sudo apt install targetcli-fbö Starte targetcli, um das iSCSI-Target zu erstellen: sudo targetcli Jetzt bist du in der targetcli-Umgebung. Du siehst eine Eingabeaufforderung, die mit / beginnt. Erstelle ein Backstore: Ein Backstore ist ein Speichergerät (z.B. eine Datei oder ein Blockdevice), das dem iSCSI-Target zugeordnet wird. Hier erstellen wir eine Datei als Backstore: /backstores/fileio> create mydisk /iscsi-disk.img 100M Dies erstellt eine Datei iscsi-disk.img mit einer Größe von 100MB als Speicher. Erstelle ein iSCSI-Target: Jetzt erstelle das iSCSI-Target. Der Name folgt dem Format iqn.JJJJ-MM.com.example:storage1. Der IQN (iSCSI Qualified Name) ist der eindeutige Name des Targets. /iscsi> create iqn.2025-03.com.example:storage1 Erstelle eine Target Portal Group (TPG): Standardmäßig wird beim Erstellen eines iSCSI-Targets eine Target Portal Group (TPG) erstellt. Diese Gruppe enthält die Portale (IP-Adressen und Ports), über die das Target erreichbar ist. /iscsi/iqn.2025-03.com.example:storage1> create tpg1 Füge den Backstore zum Target hinzu: Jetzt fügen wir den gerade erstellten Backstore zu diesem Target hinzu: /iscsi/iqn.2025-03.com.example:storage1/tpg1> luns/ create /backstores/fileio/mydisk Füge ein Portal hinzu: Ein Portal ist eine Kombination aus IP-Adresse und Port. In der Regel verwendest du Port 3260 für iSCSI. Wir fügen ein Portal mit der IP 0.0.0.0 hinzu, was bedeutet, dass es von allen IP-Adressen erreichbar ist. /iscsi/iqn.2025-03.com.example:storage1/tpg1> portals/ create 0.0.0.0 3260 Optional: Authentifizierung einrichten (CHAP): Wenn du Authentifizierung für das iSCSI-Target einrichten möchtest, kannst du die CHAP-Authentifizierung aktivieren: /iscsi/iqn.2025-03.com.example:storage1/tpg1> create auth chap user=meinuser password=meinpasswort Ersetze meinuser und meinpasswort mit den gewünschten Werten. ====Block==== manuel@vm-jzif4y4u:~$ sudo apt install targetcli-fb [...] manuel@vm-jzif4y4u:~$ sudo dd if=/dev/zero of=/iscsi-disk.img bs=1M count=100 100+0 records in 100+0 records out 104857600 bytes (105 MB, 100 MiB) copied, 0.516038 s, 203 MB/s manuel@vm-jzif4y4u:~$ sudo losetup -fP /iscsi-disk.img manuel@vm-jzif4y4u:~$ losetup -a /dev/loop1: []: (/var/lib/snapd/snaps/lxd_29351.snap) /dev/loop6: []: (/var/lib/snapd/snaps/snapd_23771.snap) /dev/loop4: []: (/var/lib/snapd/snaps/core20_2496.snap) /dev/loop2: []: (/var/lib/snapd/snaps/core20_2318.snap) /dev/loop0: []: (/iscsi-disk.img) /dev/loop5: []: (/var/lib/snapd/snaps/lxd_31333.snap) /dev/loop3: []: (/var/lib/snapd/snaps/snapd_23545.snap) manuel@vm-jzif4y4u:~$ sudo mkfs.ext4 /dev/loop0 mke2fs 1.46.5 (30-Dec-2021) Discarding device blocks: done Creating filesystem with 25600 4k blocks and 25600 inodes Allocating group tables: done Writing inode tables: done Creating journal (1024 blocks): done Writing superblocks and filesystem accounting information: done manuel@vm-jzif4y4u:~$ sudo mkdir /mnt/scsi manuel@vm-jzif4y4u:~$ sudo mount /dev/loop0 /mnt/scsi manuel@vm-jzif4y4u:~$ df -h Filesystem Size Used Avail Use% Mounted on tmpfs 197M 1.3M 196M 1% /run /dev/vda1 25G 13G 12G 53% / tmpfs 982M 0 982M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda15 105M 6.1M 99M 6% /boot/efi tmpfs 197M 4.0K 197M 1% /run/user/1001 /dev/loop0 90M 24K 83M 1% /mnt/scsi manuel@vm-jzif4y4u:~$ sudo targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> /backstores/fileio create name=mydisk file_or_dev=/iscsi-disk.img size=1G /iscsi-disk.img exists, using its size (104857600 bytes) instead Created fileio mydisk with size 104857600 /> /iscsi create iqn.2025-03.com.example:storage1 Created target iqn.2025-03.com.example:storage1. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /> /iscsi/iqn.2025-03.com.example:storage1/tpg1/luns create /backstores/fileio/mydisk Created LUN 0. /> saveconfig Last 10 configs saved in /etc/rtslib-fb-target/backup/. Configuration saved to /etc/rtslib-fb-target/saveconfig.json /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/rtslib-fb-target/backup/. Configuration saved to /etc/rtslib-fb-target/saveconfig.json manuel@vm-jzif4y4u:~$ sudo systemctl enable --now target Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /lib/systemd/system/target.service. manuel@vm-jzif4y4u:~$ manuel@vm-jzif4y4u:~$ sudo targetcli ls o- / ............................................................................................................. [...] o- backstores .................................................................................................. [...] | o- block ...................................................................................... [Storage Objects: 0] | o- fileio ..................................................................................... [Storage Objects: 1] | | o- mydisk ...................................................... [/iscsi-disk.img (100.0MiB) write-back activated] | | o- alua ....................................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ........................................................... [ALUA state: Active/optimized] | o- pscsi ...................................................................................... [Storage Objects: 0] | o- ramdisk .................................................................................... [Storage Objects: 0] o- iscsi ................................................................................................ [Targets: 1] | o- iqn.2025-03.com.example:storage1 ...................................................................... [TPGs: 1] | o- tpg1 ................................................................................... [no-gen-acls, no-auth] | o- acls .............................................................................................. [ACLs: 0] | o- luns .............................................................................................. [LUNs: 1] | | o- lun0 ................................................. [fileio/mydisk (/iscsi-disk.img) (default_tg_pt_gp)] | o- portals ........................................................................................ [Portals: 1] | o- 0.0.0.0:3260 ......................................................................................... [OK] o- loopback ............................................................................................. [Targets: 0] o- vhost ................................................................................................ [Targets: 0] manuel@vm-jzif4y4u:~$ manuel@vm-jzif4y4u:~$ iscsiadm -m discovery -t sendtargets -p 127.0.0.1 127.0.0.1:3260,1 iqn.2025-03.com.example:storage1 manuel@vm-jzif4y4u:~$ =====Links===== * [[https://manpages.ubuntu.com/manpages/xenial/man8/targetcli.8.html|Manpage]] * [[https://www.thomas-krenn.com/de/wiki/Linux-IO_Target_(LIO)_unter_Ubuntu_14.04|TargetCLI - Thomas Krenn Wiki]]