ubuntu 24.04 LTS iSCSI target configuration memo with targetcli command

# ubuntu 24.04 LTS iSCSI target configuration memo with targetcli command

## Objectives

- Recreate (delete and create) larger size file image

## System
- iSCSI Target
```
# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
(snip)
```
- iSCSI Initiator
    - ESXi7

## Install
```
# apt install targetcli-fb
```

## Configuration Command

- /usr/bin/targetcli
- man page
    - https://manpages.ubuntu.com/manpages/noble/en/man8/targetcli.8.html


## Service enable, start, stop, restart
```
systemctl enable rtslib-fb-targetctl
systemctl start rtslib-fb-targetctl
systemctl stop rtslib-fb-targetctl
systemctl restart rtslib-fb-targetctl
```

## Current Configuration

- Lun0 : file image /export/iscsi_img/disk01.img 30GB

```
# targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- disk01 ...................................................... [/export/iscsi_img/disk01.img (30.0GiB) 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.2022-04.com.example.iscsitarget01:lun1 ......................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.1998-01.com.vmware:iscsi-initiator.example.com:426853202:64 ................................................ [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................................................... [lun0 fileio/disk01 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................ [fileio/disk01 (/export/iscsi_img/disk01.img) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
```

## Delete current file image
```
# targetcli

targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/iscsi> cd /backstores/fileio
/backstores/fileio> delete disk01
/backstores/fileio> exit
```
```
# rm -f /export/iscsi_img/disk01.img
```
```
# targetcli

/backstores/fileio> create disk01 /export/iscsi_img/disk01.img 100G

Created fileio disk01 with size 107374182400

/backstores/fileio> cd /iscsi/iqn.2022-04.com.example.iscsitarget01:lun1/tpg1/luns/
/iscsi/iqn.20...un1/tpg1/luns> create /backstores/fileio/disk01

Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.1998-01.com.vmware:iscsi-initiator.example.com:426853202:64

/iscsi/iqn.20...un1/tpg1/luns> cd /
```
```
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- disk01 ..................................................... [/export/iscsi_img/disk01.img (100.0GiB) 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.2022-04.com.example.iscsitarget01:lun1 ......................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.1998-01.com.vmware:iscsi-initiator.example.com:426853202:64 ................................................ [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................................................... [lun0 fileio/disk01 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................ [fileio/disk01 (/export/iscsi_img/disk01.img) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
```
```
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/rtslib-fb-target/saveconfig.json
#
```

## Re-scan storage adapter on iSCSI initiator node, then check storage device if the target lun is resized or not.

## Add lun
```
# targetcli
cd /backstores/fileio
create disk02 /export/iscsi_img/disk02.img 100G
cd /iscsi/iqn.2022-04.com.example.iscsitarget01:lun1/tpg1/luns/
create /backstores/fileio/disk02

Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.1998-01.com.vmware:iscsi-initiator.example.com:426853202:64

/iscsi/iqn.20...un1/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 2]
  o- lun0 ........................................................ [fileio/disk01 (/export/iscsi_img/disk01.img) (default_tg_pt_gp)]
  o- lun1 ........................................................ [fileio/disk02 (/export/iscsi_img/disk02.img) (default_tg_pt_gp)]
/iscsi/iqn.20...un1/tpg1/luns>

/iscsi/iqn.20...un1/tpg1/luns> 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
#
```