The SCSI connector is used to connect SCSI hard drives in a server.
For the iSCSI is a SCSI emulation over TCP/IP network. So, the iSCSI allows you to use a hard drive over the network as if it were a real hard drive.
Before you begin, you must set a statuc IP address on the machine where you will install the iSCSI server.
For this, refer to one of these tutorials : Debian - Define a private static IP address ou Ubuntu - Define a private static IP address
To install an iSCSI server, you must install these packages :
- iscsitarget : tools to manage the iSCSI server
- iscsitarget-dkms : the kernel
apt-get install iscsitarget iscsitarget-dkms
During the installation, you will see this line :
[....] iscsitarget not enabled in "/etc/default/iscsitarget", not starting... ..[ (warning).
Once installation is complete, enable the iSCSI server by setting the "ISCSITARGET_ENABLE" variable to true.
With iscsitarget, you can share :
- hard disks : /dev/sd*
- partitions : /dev/sd**
- LVM volumes : /dev/vg*/my_lv
- RAID volumes : /dev/md*
In our case, we will share a LVM volume.
If you don't know how to create a logical volume in LVM, follow our tutorial "Install and use the LVM on Linux" until the end of step 2.4 of the tutorial.
The configuration of iSCSI shares must be indicated in the file : /etc/iet/ietd.conf
In this file, you will find many comments and examples that are commented by default.
In this tutorial, we'll create a simple iSCSI share from a LVM logical volume.
Note that the logical volume to share over iSCSI should not be mounted.
If he is already mounted, use the "umount" command to unmount it.
To create a simple iSCSI share, you must indicate :
- a Target : it is the identifier of the iSCSI share.
The iSCSI RFC 3720 standard says that it's best to use the syntax : Target iqn.yyyy-mm.<reversed domain name>[:identifier]
yyyy-mm : it is the date of the creation of the iSCSI share.
<reversed domain name> : it's the domain name of the machine, but reversed. (You can invent if you wish)
[:identifier] : is the name of the iSCSI share.
- IncomingUser : login credentials for the iSCSI share. This is a CHAP authentication.
- Lun : informations about the volume to share. Path + share's type.
In our case, we'll add this iSCSI share :
Target iqn.2016-09.lan.informatiweb:mon_partage IncomingUser informatiweb my_password Lun 0 Path=/dev/iwvg/iw_vol1,Type=fileio
Then, restart the iSCSI server by typing this command :
To verify that your shares are configured correctly, you can use this command :
If you get a result similar to this, is that your configuration is good.
tid:1 name:iqn.2016-09.lan.informatiweb:mon_partage lun:0 state:0 iotype:fileio iomode:wt blocks:104652800 blocksize:512 path:/dev/iwvg/iw_vol1
Before we begin, we recommend that you set a static IP address for the machine on which you install the iSCSI client.
Indeed, otherwise, the connection to the iSCSI server may not be performed properly. This also will cause an error for mounting iSCSI shares at startup with fstab.
To install an iSCSI client, you must install the open-iscsi package.
apt-get install open-iscsi
By default, the iSCSI client does not start automatically.
To automatically start the iSCSI client at startup, you must change the "node.startup" line of the "/etc/iscsi/iscsid.conf" file.
Change the "node.startup" line like this :
node.startup = automatic
Then, restart the service.
If the iSCSI server requires a CHAP authentication, you need to edit the "/etc/iscsi/iscsid.conf" file to allow your iSCSI client to connect to the iSCSI share of your server.
Note that you will find many interesting comments in this file.
In this file, add this :
node.session.auth.authmethod = CHAP node.session.auth.username = informatiweb node.session.auth.password = my_password discovery.sendtargets.auth.authmethod = CHAP discovery.sendtargets.auth.username = informatiweb discovery.sendtargets.auth.password = my_password
Then, to detect the available shares on your iSCSI server, use the "iscsiadm" command.
Note : 10.0.0.10 is the IP address of our iSCSI server.
iscsiadm -m discovery -t st -p 10.0.0.10
This command will show you a result similar to this :
Note that the execution of the command "iscsiadm -m discovery ..." has generated a "iqn.../default" file in the "/etc/iscsi/nodes/" folder.
In this file, you will find the complete configuration for this iqn.
The configuration present in this file was copied from the file "iscsid.conf" during the execution of the discovery command.
So, it's important to configure the file "iscsid.conf" BEFORE starting the discovery.
Then, restart your iSCSI client.
If you find a line similar to this one, your configuration is correct :
Login to [iface: default, target: iqn.2016-09.lan.informatiweb:mon_partage, portal: 10.0.0.10,3260] successful.
Once connected to the iSCSI server, a new hard drive will be available.
To find it, you can use the command
iscsiadm -m session -P 3
This command will show you information about the established iSCSI sessions including this :
Target: iqn.2016-09.lan.informatiweb:mon_partage ... ***** CHAP: ***** username: informatiweb password: ******** username_in: <empty> password_in: ******** ... ************************ Attached SCSI devices: ************************ Host Number: 12 State: running scsi12 Channel 00 Id 0 Lun: 0 Attached scsi disk sdb State: running
At the end of this information, you will find that this iSCSI share will be usable as a SCSI hard drive (/dev/sdb).
Attached scsi disk sdb State: running
For this tutorial, we will create a single primary partition on the entire disk with fdisk.
For more information about the partitioning of a hard drive with fdisk, refer to our tutorial : Partition your hard drive with fdisk.
Then, to store data on this iSCSI share, you have 2 options :
- Mount a partition of this "hard disk" (the disk obtained through the iSCSI connection) to a folder with the "mount" command.
- Or perform the mount at system startup through fstab.
To mount the first partition of the "hard drive" in a folder, use these commands :
mkdir /mnt/my_iscsi_disk mount /dev/sdb1 /mnt/my_iscsi_disk
To automatically mount the hard drive at startup, create the folder in which the mount will be done, and then edit the "/etc/fstab" file.
mkdir /mnt/my_iscsi_disk vim /etc/fstab
And add this :
/dev/sdb1 /mnt/my_iscsi_disk ext4 _netdev 0 0
Note that we use the "_netdev" option to mount the partition (of the disk obtained through the iSCSI connection) once the network is available.
Now, the partition "/dev/sdb1" will be mounted at each startup of the machine.
However, to avoid restarting now you can use this command :
When you restart your client machine, the mount will be done automatically at startup without problems.
® InformatiWeb-Pro.net - InformatiWeb.net 2008-2020 - © Lionel Eppe - All rights reserved.
Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.