LinuxCommandLibrary

targetcli

Configure Linux iSCSI target (LIO)

SYNOPSIS

targetcli
targetcli [-f <script_file>] [-V | --version] [--debug]
targetcli [command] [argument...]

PARAMETERS

None (interactive mode)
    When invoked without options, targetcli enters an interactive shell, allowing step-by-step configuration of the LIO SCSI Target.

-f <script_file>
    Executes targetcli commands read from the specified script_file in a non-interactive (batch) mode. This is useful for automating configuration tasks.

-V, --version
    Displays the version information of the targetcli utility and exits.

--debug
    Enables verbose debug output during the execution of targetcli.

DESCRIPTION

targetcli is a command-line interface used to configure the Linux LIO kernel-based SCSI Target. It provides a powerful and flexible way to present local storage devices (like block devices, files, or RAM disks) as SCSI LUNs (Logical Unit Numbers) to remote initiators over various transport protocols such as iSCSI, Fibre Channel (FC), FCoE, and SRP. The utility operates primarily in an interactive shell mode, presenting a hierarchical, tree-like structure for navigating and managing target objects (e.g., backstores, TPGs, LUNs, ACLs). Configurations made via targetcli are typically saved to a persistent JSON file (e.g., /etc/target/saveconfig.json) ensuring they survive system reboots. It streamlines the complex process of setting up and managing a full-featured SCSI target server on Linux, making it the de facto standard for this purpose.

CAVEATS

Root Privileges: targetcli requires root privileges to operate, as it directly manipulates kernel-level configuration via configfs.
Complexity: Its tree-like hierarchical structure, while powerful, can be complex for users unfamiliar with SCSI target concepts or the LIO model.
Persistence: While configurations are typically saved, issues during shutdown or misconfiguration of the saving mechanism can lead to loss of target settings.
Kernel Modules: Proper functioning depends on the underlying LIO kernel modules (target_core_mod, iscsi_target_mod, etc.) being loaded and operational.

INTERACTIVE SHELL AND TREE STRUCTURE

When invoked without arguments, targetcli provides an interactive command-line shell. This shell uses a hierarchical, tree-like structure, similar to a filesystem, allowing users to navigate through various target components (e.g., /backstores, /iscsi, /fcoe) using cd, ls, create, delete, and set commands. This structure helps in organizing and managing complex target configurations.

CONFIGURATION PERSISTENCE

Configurations made through targetcli are automatically saved to a persistent JSON file, typically located at /etc/target/saveconfig.json. This ensures that your SCSI target setup is automatically restored upon system reboots, eliminating the need for manual reconfiguration after every restart. The utility handles the loading and saving of this configuration file transparently.

BACKSTORES

In the context of LIO and targetcli, a 'backstore' is the underlying storage resource that is presented as a Logical Unit Number (LUN) to remote initiators. targetcli supports various backstore types, including block (raw block devices), fileio (files on a filesystem), and iblock (virtual RAM disks). These backstores define the actual storage capacity and type that will be made available to clients.

HISTORY

targetcli is the modern configuration utility for the Linux LIO (Linux-IO) SCSI Target, which became the standard in the Linux kernel around version 2.6.38, replacing older target solutions like STGT and IET. The utility itself, along with its predecessor targetcli-fb, was developed to provide a user-friendly and persistent interface to the complex configfs-based LIO kernel functionality. Its design focuses on a tree-like structure, making the management of storage targets intuitive despite the underlying complexity. It leverages Python for its interactive shell and backend logic, ensuring robust saving and restoration of configurations across system reboots, typically to /etc/target/saveconfig.json.

SEE ALSO

iscsiadm(8), lio_utils(8), scsi_target_configfs(8), ip(8), ss(8), lsblk(8)

Copied to clipboard