This part is setup an iscsi-target based on hlinux. First, start up iscsi-target service, like install some components and let linux run this service, then create a new volume. Finally, export new volume to client side.

1.1 set up iscsi-target


1.1.1 Install essential softwares

sudo apt-get install iscsitarget iscsitarget-dkms

iscsitarget & iscsitarget-dkms, the main packages to support iscsi service.

1.1.2 Start up iscsi-target service

- change /etc/default/iscsitarget


- reboot iscsitarget service

sudo service iscsitarget restart

- set iscsitarget service as an auto-boot service

sudo update-rc.d iscsitarget enable 

- disable auto-boot if you want:

sudo update-rc.d iscsitarget disable

1.2 Create new volumes for iscsi-target

Iscsi-target could use different type volumes, like Image file, real disk partition, LVM partition and RAID partition. Here I am using the LVM partition since it is more flexible comparing with other types.

1.2.1 LVM

To use LVM, we will need an volume group first, it's based on physical volume. Then we could create the logical volume from volume group, and the logical volume will be used by iscsi-target.

- Sometimes, you installed the OS with a LVM support, then you could get a volume group at the boot time, and the logical volume is what you only need.

sudo lvcreate -L <size> -n <logical volume name> <volume group name>

- Sometimes, you installed the OS on physical driver, that's fine, below is what you need do.

sudo apt-get install lvm2 // install lvm first
sudo pvcreate <physical partition>  // make sure you have a separate partition
sudo vgcreate <volume group name> <physical partition>  // create the volume group based on physical partition 
sudo lvcreate -L <size> -n <logical volume name> <volume group name>  

1.2.2 Real Partition

You could use /dev/sda* or /dev/hda* directily.

1.2.3 Image file

dd if=/dev/zero of=test.img bs=1M count=1000

This will create a image file with size 1G, or you could change to the size you want.

1.3 Export new volume to client

- modify the configuration file for iscsi-target

vim /etc/iet/ietd.conf

- add configuration for new volume

Target <initiator-address> #iqn address for initiator
Lun <lun-number> Path=<path-to-volume>,Type=<volume-type> #volume information, local image file and partition use fileio and LVM or RAID volume use blockio.
initiator-address <initiator-ip-address> #initiator ip address
incominguser <target-user>  <target-password>   # authentication

Below is an example:

Target iqn.2015-12.hlinux.server:target0 
Lun 0 Path=/dev/hLinux-vg/iscsi-001,Type=blockio 
incominguser hlinux secrete 

- restart iscsi-target service

sudo service iscsitarget restart