LinuxCommandLibrary

targetcli

Configure Linux iSCSI target (LIO)

SYNOPSIS

targetcli [options]

PARAMETERS

-h, --help
    Display help message and exit.

-V, --version
    Display version information and exit.

-c, --config
    Specify an alternative configuration file. Defaults to /etc/target/targetcli.conf.

-f, --foreground
    Run in the foreground (do not daemonize).

-q, --quiet
    Suppress verbose output.

-x, --execute
    Execute a single command and exit. Can be repeated.

-i, --interactive
    Force interactive mode (even if not a TTY).

DESCRIPTION

targetcli is a command-line interface for managing the Linux kernel target subsystem (TCM) and iSCSI Enterprise Target (IET). It provides a hierarchical shell environment to configure iSCSI targets, Fibre Channel targets (if available), and other storage protocols exposed by the Linux kernel. This includes creating, deleting, and modifying logical units (LUNs), access control lists (ACLs), and other target-related objects. targetcli simplifies the management of complex storage configurations by offering a user-friendly interface to the underlying kernel modules. Using it you can create iSCSI or Fibre Channel targets, export disks and filesystems, and define access policies. This is especially useful for creating shared storage solutions, such as those used in virtualization environments or storage area networks (SANs).

Historically IET was the main target on linux, but with time has been deprecated.

CAVEATS

targetcli requires root privileges to modify the target configuration. The kernel target subsystem (TCM) must be properly loaded and configured for targetcli to function correctly. Some features may depend on specific kernel modules or libraries being installed.

CONFIGURATION FILE

The default configuration file, /etc/target/targetcli.conf, stores the current target configuration. This file is automatically loaded when targetcli starts and saved when you exit. You can use the -c option to specify an alternative configuration file.

COMMAND SHELL

targetcli provides a hierarchical command shell. You can navigate the hierarchy using the cd command and view the current configuration using the ls command. Use help to get help on available commands within the current context.

EXAMPLE USAGE

To create an iSCSI target and export a LUN:

1. targetcli
2. /backstores/fileio create my_image /path/to/my_image.img 10G
3. /iscsi create iqn.2024-01.example.com:mytarget
4. /iscsi/iqn.2024-01.example.com:mytarget/tpg1/luns create /backstores/fileio/my_image
5. /iscsi/iqn.2024-01.example.com:mytarget/tpg1/acls create iqn.2024-01.example.com:initiator
6. saveconfig
7. exit
This example creates a fileio backstore, then an iSCSI target, then creates the lun and finally defines which initiators will have access to the target

HISTORY

The targetcli utility was developed to provide a unified interface for managing the Linux kernel target subsystem (TCM). Prior to targetcli, managing iSCSI targets often involved using vendor-specific tools or directly manipulating configuration files. targetcli simplified this process by providing a hierarchical shell environment. The command gained prominence as iSCSI and other storage protocols became increasingly important in enterprise environments. Originally targetcli supported both IET and TCM but with time IET support has been deprecated.

SEE ALSO

iscsiadm(8), tgtadm(8)

Copied to clipboard