On iSCSI target server
List all NIC cards on the server
lspci | grep -i eth
Install iSCSI target
sudo apt-get install iscsitarget
Enable iSCSI target at /etc/default/iscsitarget
sudo nano /etc/default/iscsitarget
ISCSITARGET_ENABLE=true
Use either image file, logical volume, or hard drive to store iSCSI target
Create an image file. Example 20GB
mkdir /storage
dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000
If you wish to create logical volume of 20GB, use the following command.
lvcreate -L20G -n storage_lun1 vg0
Time to configure iSCSI target
sudo nano /etc/iet/ietd.conf
Target iqn.2016-04.com.sg.xxx:storage.lun1
IncomingUser usernameX passwordX
OutgoingUser
Lun 0 Path=/dev/vg0/storage_lun1,Type=fileio
Alias LUN1
#MaxConnections 6
Limit initiators access
sudo nano /etc/iet/initiators.allow
iqn.2016-04.com.sg.xxx:storage.lun1 192.168.x.x
Finally restart iSCSI target server
sudo service iscsitarget restart
Check the port
sudo netstat -tulpn | grep 3260
On iSCSI initiator
Install iSCSI initiator
sudo apt-get install open-iscsi
Configure /etc/iscsi/iscsid.conf
sudo nano /etc/iscsi/iscsid.conf
node.startup=automatic
Restart iSCSI initiator service
sudo service open-iscsi restart
Discover iSCSI target server
sudo iscsiadm -m discovery -t st -p 192.168.1.219
sudo iscsiadm -m node
Set authenticate using CHAP
sudo iscsiadm -m node --targetname "iqn.2016-04.com.sg.xxx:storage.lun1" --portal "192.168.1.219" --op=update --name node.session.auth.authmethod --value=CHAP
Set authenicate with login
sudo iscsiadm -m node --targetname "iqn.2016-04.com.sg.xxx:storage.lun1" --portal "192.168.1.219" --op=update --name node.session.auth.username --value=xxx
Set authenicate with password
sudo iscsiadm -m node --targetname "iqn.2016-04.com.sg.xxx:storage.lun1" --portal "192.168.1.219" --op=update --name node.session.auth.password --value=passwordX
Attempt login
sudo iscsiadm -m node --targetname "iqn.2016-04.com.sg.xxx:storage.lun1" --portal "192.168.1.219:3260" --login
To logout
sudo iscsiadm -m node --targetname "iqn.2016-04.com.sg.xxx:storage.lun1" --portal "192.168.1.219:3260" --logout
Once successfully login, view the disk
sudo fdisk -l
dmesg | grep sd
Time to format it
sudo fdisk /dev/sdx
m (help)
n (add a new partition) p (primary partition)
w (write table to disk and exit)
View the disk again
sudo fdisk -l
Time to create filesystem
mkfs.ext4 /dev/sdx1
Test mount & umount
mount /dev/sdx1 /mnt
mount
df -h
umount /mnt
Setup to have the device mounted automatically at boot time
mkdir /storage
sudo nano /etc/fstab
/dev/sdx1 /storage ext4 defaults,auto,_netdev 0 0
Try rebooting and verify
reboot
mount
df -h