How To Connect And Mount iSCSI Onto Linux Servers

Before start with this article, please check our previous guide how to install and configure openfiler.

Now we will explian how to add the target disk to our local server.

Details:

Openfiler Server: 192.168.1.141
Centos Server: 192.168.1.137

The commands bellow should be working in other Linux distro.

First, install some needed packages.

 Centos :

yum -y install iscsi-initiator-utils
service iscsid start
service iscsi start

Ubuntu:

sudo apt-get install open-iscsi

Opensuse

# zypper install open-iscsi

Discovering targets in iSCSI server:

 [root@machine1 ~]# iscsiadm --mode discovery -t sendtargets --portal 192.168.1.141
192.168.1.141:3260,1 iqn.2006-01.com.openfiler:tsn.d625a0d9cb77

Trying to login with the iSCSI LUN:

[root@machine1 ~]# iscsiadm --mode node --targetname  iqn.2006-01.com.openfiler:tsn.d625a0d9cb77  --portal 192.168.1.141 --login
 Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.d625a0d9cb77, portal: 192.168.1.141,3260] (multiple)
 Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.d625a0d9cb77, portal: 192.168.1.141,3260] successful.
 [root@machine1 ~]#

With this command is reponsible of the update of  iSCSI targets database for the files located in /var/lib/iscsi/ :

[root@machine1 ~]# cat /var/lib/iscsi/send_targets/192.168.1.141,3260/st_config
 # BEGIN RECORD 6.2.0-873.10.el6
 discovery.startup = manual
 discovery.type = sendtargets
 discovery.sendtargets.address = 192.168.1.141
 discovery.sendtargets.port = 3260
 discovery.sendtargets.auth.authmethod = None
 discovery.sendtargets.timeo.login_timeout = 15
 discovery.sendtargets.use_discoveryd = No
 discovery.sendtargets.discoveryd_poll_inval = 30
 discovery.sendtargets.reopen_max = 5
 discovery.sendtargets.timeo.auth_timeout = 45
 discovery.sendtargets.timeo.active_timeout = 30
 discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
 # END RECORD
 [root@machine1 ~]#

Now check if the disk add to your machine

[root@machine1 ~]# fdisk  -l
Disk /dev/sda: 17.8 GB, 17791238144 bytes
 255 heads, 63 sectors/track, 2162 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x000a0b90
Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1        1275    10240000   83  Linux
 /dev/sda2            1275        1913     5120000   8e  Linux LVM
 /dev/sda3            1913        2066     1228800   82  Linux swap / Solaris
Disk /dev/mapper/vg_machine1-LogVol01: 209 MB, 209715200 bytes
 255 heads, 63 sectors/track, 25 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
Disk /dev/mapper/vg_machine1-LogVol00: 2097 MB, 2097152000 bytes
 255 heads, 63 sectors/track, 254 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
Disk /dev/sdb: 369 MB, 369098752 bytes
 12 heads, 59 sectors/track, 1018 cylinders
 Units = cylinders of 708 * 512 = 362496 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
[root@machine1 ~]#

Create file system in this disk

[root@machine1 ~]# fdisk  /dev/sdb
 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 Building a new DOS disklabel with disk identifier 0x41c55bb7.
 Changes will remain in memory only, until you decide to write them.
 After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
 switch off the mode (command 'c') and change display units to
 sectors (command 'u').
Command (m for help): n
 Command action
 e   extended
 p   primary partition (1-4)
 p
 Partition number (1-4): 2
 First cylinder (1-1018, default 1):
 Using default value 1
 Last cylinder, +cylinders or +size{K,M,G} (1-1018, default 1018):
 Using default value 1018
Command (m for help): w
 The partition table has been altered!
Calling ioctl() to re-read partition table.
 Syncing disks.

 and

[root@machine1 ~]# mkfs.ext4 /dev/sdb2
 mke2fs 1.41.12 (17-May-2010)
 Filesystem label=
 OS type: Linux
 Block size=1024 (log=0)
 Fragment size=1024 (log=0)
 Stride=0 blocks, Stripe width=0 blocks
 90112 inodes, 360340 blocks
 18017 blocks (5.00%) reserved for the super user
 First data block=1
 Maximum filesystem blocks=67633152
 44 block groups
 8192 blocks per group, 8192 fragments per group
 2048 inodes per group
 Superblock backups stored on blocks:
 8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables: done
 Creating journal (8192 blocks): done
 Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
 180 days, whichever comes first.  Use tune2fs -c or -i to override.

Prepare the directory to mount the disk.

[root@machine1 ~]#[root@machine1 ~]# mkdir  /iscsi-openfiler
 [root@machine1 ~]# mount  -t ext4 /dev/sdb2  /iscsi-openfiler/
 [root@machine1 ~]# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda1             9.7G  2.4G  6.9G  26% /
 tmpfs                 751M     0  751M   0% /dev/shm
 /dev/mapper/vg_machine1-LogVol00
 2.0G   35M  1.8G   2% /home
 /dev/mapper/vg_machine1-LogVol01
 194M  5.6M  179M   4% /tmp
 /dev/sdb2             341M   11M  314M   4% /iscsi-openfiler

Please add this to mount the net drive with Linux start.
add this to /etc/fstab.

/dev/sdb2  /iscsi-openfiler   ext4 _netdev,rw 0 0

and

chkconfig  netfs  on
chkconfig  iscsi on

There are three ways to disable or delete an iSCSI target.

First, to disable an iSCSI target:

# iscsiadm --m node -T iqn.2006-01.com.openfiler:tsn.d625a0d9cb77 --portal 192.168.1.141:3260 -u

Second, it is possible to delete the target’s record ID:/p>

# iscsiadm -m node -o delete -T iqn.2006-01.com.openfiler:tsn.d625a0d9cb77 --portal 192.168.1.141:3260

Thirdly, stop the iSCSI service.

Enjoy!