1

I have a CentOS 7 machine with iSCSI configured. see ls output from targetcli below. I want to add disk02 to lun0 so that to the iSCSI client can see a total 869.16GB instead of 392.2GB

Question: Is it possible to have lun0 use the combined capacity of disk0 and disk1 and if so how to do that with targetcli on CentOS7.

/> ls
o- / ....................................................................................................... [...]
  o- backstores ............................................................................................ [...]
  | o- block ................................................................................ [Storage Objects: 2]
  | | o- disk01 ...................................................... [/dev/sdb4 (392.2GiB) write-thru activated]
  | | o- disk02 ..................................................... [/dev/sda (476.9GiB) write-thru deactivated]
  | o- fileio ............................................................................... [Storage Objects: 0]
  | o- pscsi ................................................................................ [Storage Objects: 0]
  | o- ramdisk .............................................................................. [Storage Objects: 0]
  o- iscsi .......................................................................................... [Targets: 1]
  | o- iqn.2014-08.com.exmaple:nuc .................................................................... [TPGs: 1]
  |   o- tpg1 ................................................................................ [gen-acls, no-auth]
  |     o- acls ........................................................................................ [ACLs: 0]
  |     o- luns ........................................................................................ [LUNs: 1]
  |     | o- lun0 ..................................................................... [block/disk01 (/dev/sdb4)]
  |     o- portals .................................................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 ................................................................................... [OK]
  o- loopback ....................................................................................... [Targets: 0]
/> 
2
+50

The creation of an iSCS target LUN links the previously-defined storage objects with the target and defines which number the device will use.

Therefore, if you want the LUN (lun0) to be expanded, then the underlying storage object (disk01) needs to be expanded.

One method to do this is to create a logical volume from the two disks as follows (although this will require an outage):

Delete the unused storage object disk02 and create a logical volume from it:

/backstores/block> delete disk02
Deleted storage object disk02.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 1]
  o- disk01 .............................................................................. [/dev/sdb4 (392.2GiB) write-thru activated]
/backstores/block>

Create a logical volume (iscsi_lv01) using the entire device:

$ pvcreate /dev/sda
  Physical volume "/dev/sda" successfully created
$ vgcreate iscsi_disk01 /dev/sda
  Volume group "iscsi_disk01" successfully created
$ lvcreate iscsi_disk01 -l 100%FREE -n iscsi_lv01
  Logical volume "iscsi_lv01" created

Note:
Clearly if the existing device was formatted and contained data then this new volume will have to be formatted and the data copied onto it.

Create a new storage object using the new volume:

$ targetcli
/backstores/block> create iscsi_lv01 /dev/iscsi_disk01/iscsi_lv01
Created block storage object iscsi_lv01 using /dev/iscsi_disk01/iscsi_lv01.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 2]
  o- disk01 .............................................................................. [/dev/sdb4 (392.2GiB) write-thru activated]
  o- iscsi_lv01 .................................................... [/dev/iscsi_disk01/iscsi_lv01 (476.9GiB) write-thru deactivated]
/backstores/block>

Recreate lun0 using the new volume

/> cd iscsi/iqn.2014-08.com.exmaple:nuc/tpg1/luns/
/iscsi/iqn.20...nuc/tpg1/luns> delete lun0
Deleted LUN 0.
/iscsi/iqn.20...nuc/tpg1/luns> create /backstores/block/iscsi_lv01
Created LUN 0.
/iscsi/iqn.20...nuc/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 ........................................................................ [block/iscsi_lv01 (/dev/iscsi_disk01/iscsi_lv01)]
/iscsi/iqn.20...nuc/tpg1/luns>

Delete the existing storage object disk01 to then be added to the volume group:

/> cd backstores/block/
/backstores/block> delete disk01
Deleted storage object disk01.
/backstores/block> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_lv01 .................................................. [/dev/iscsi_disk01/iscsi_lv01 (476.9GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.exmaple:nuc ....................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................ [block/iscsi_lv01 (/dev/iscsi_disk01/iscsi_lv01)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]

Save the new configuration in case auto_save_on_exit is not set to true:

/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Extend the existing logical volume with the original device disk01:

$ pvcreate /dev/sdb4
  Physical volume "/dev/sdb4" successfully created
$ vgextend iscsi_disk01 /dev/sdb4
  Volume group "iscsi_disk01" successfully extended
$ lvextend -l 100%VG /dev/iscsi_disk01/iscsi_lv01
  Extending logical volume iscsi_lv01 to 869.1GiB
  Logical volume iscsi_lv01 successfully resized
$

Note:
There will also be the additional step of resizing the filesystem once disk01 has been added if the volume required formatting.

Notice the new sized storage object:

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_lv01 .................................................. [/dev/iscsi_disk01/iscsi_lv01 (869.1GiB) write-thru activated]

Unfortunately this method requires down time while the lun is resized, however, following this method will ensure it is kept to a minimum.

References

Targetcli Wiki
iSCSI target guide using tgtadm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.