Setup iSCSI target and initiator on Ubuntu 14.04

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


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
IncomingUser usernameX passwordX
Lun 0 Path=/dev/vg0/storage_lun1,Type=fileio
Alias LUN1
#MaxConnections 6

Limit initiators access

sudo nano /etc/iet/initiators.allow 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

Restart iSCSI initiator service

sudo service open-iscsi restart

Discover iSCSI target server

sudo iscsiadm -m discovery -t st -p
sudo iscsiadm -m node

Set authenticate using CHAP

sudo iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.authmethod --value=CHAP

Set authenicate with login

sudo iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.username --value=xxx

Set authenicate with password

sudo iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.password --value=passwordX

Attempt login

sudo iscsiadm -m node --targetname "" --portal "" --login

To logout

sudo iscsiadm -m node --targetname "" --portal "" --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
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

df -h


Leave a Comment

Your email address will not be published. Required fields are marked *