This guide explains how you can set up an iSCSI target and an iSCSI initiator (client), both running Ubuntu 10.04. The iSCSI protocol is a storage area network (SAN) protocol which allows iSCSI initiators to use storage devices on the (remote) iSCSI target using normal ethernet cabling. To the iSCSI initiator, the remote storage looks like a normal, locally-attached hard drive. I do not issue any guarantee that this will work for you!
1 Preliminary NoteI’m using two Ubuntu 10.04 servers here:
Because we will run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing sudo su
2 Setting Up The Target (server2)server2: First we set up the target (server2): aptitude install iscsitarget Open /etc/default/iscsitarget… vi /etc/default/iscsitarget … and set ISCSITARGET_ENABLE to true:
We can use unused logical volumes, image files, hard drives (e.g. /dev/sdb), hard drive partitions (e.g. /dev/sdb1) or RAID devices (e.g. /dev/md0) for the storage. In this example I will create a logical volume of 20GB named storage_lun1 in the volume group vg0: lvcreate -L20G -n storage_lun1 vg0 (If you want to use an image file, you can create it as follows: mkdir /storage This creates the image file /storage/lun1.img with a size of 20GB. ) Next we edit /etc/ietd.conf… vi /etc/ietd.conf … and comment out everything in that file. At the end we add the following stanza:
The target name must be a globally unique name, the iSCSI standard defines the “iSCSI Qualified Name” as follows: iqn.yyyy-mm.<reversed domain name>[:identifier]; yyyy-mm is the date at which the domain is valid; the identifier is freely selectable. The IncomingUser line contains a username and a password so that only the initiators (clients) that provide this username and password can log in and use the storage device; if you don’t need authentication, don’t specify a username and password in the IncomingUser line. In the Lun line, we must specify the full path to the storage device (e.g./dev/vg0/storage_lun1, /storage/lun1.img, /dev/sdb, etc.). Now we tell the target that we want to allow connections to the device iqn.2001-04.com.example:storage.lun1 from the IP address 192.168.0.100 (server1.example.com) (comment out the ALL ALLline because that would allow all initiators to connect to all targets)… vi /etc/initiators.allow
… and start the target: /etc/init.d/iscsitarget start
3 Setting Up The Initiator (server1)server1: On server1, we install the initiator: aptitude install open-iscsi Next we open /etc/iscsi/iscsid.conf… vi /etc/iscsi/iscsid.conf … and set node.startup to automatic:
Then we restart the initiator: /etc/init.d/open-iscsi restart Now we connect to the target (server2) and check what storage devices it has to offer: iscsiadm -m discovery -t st -p 192.168.0.101 root@server1:~# iscsiadm -m discovery -t st -p 192.168.0.101 iscsiadm -m node root@server1:~# iscsiadm -m node The settings for the storage device iqn.2001-04.com.example:storage.lun1 on 192.168.0.101:3260,1 are stored in the file /etc/iscsi/nodes/iqn.2001-04.com.example:storage.lun1/192.168.0.101,3260,1/default. We need to set the username and password for the target in that file; instead of editing that file manually, we can use the iscsiadmcommand to do this for us: iscsiadm -m node –targetname “iqn.2001-04.com.example:storage.lun1” –portal “192.168.0.101:3260” –op=update –name node.session.auth.authmethod –value=CHAP Now we can log in, either by running… iscsiadm -m node –targetname “iqn.2001-04.com.example:storage.lun1” –portal “192.168.0.101:3260” –login root@server1:~# iscsiadm -m node –targetname “iqn.2001-04.com.example:storage.lun1” –portal “192.168.0.101:3260” –login … or by restarting the initiator: /etc/init.d/open-iscsi restart (If you want to log out, you can run iscsiadm -m node –targetname “iqn.2001-04.com.example:storage.lun1” –portal “192.168.0.101:3260” –logout ) In the output of fdisk -l you should now find a new hard drive (/dev/sdb in this example); that’s our iSCSI storage device: root@server1:~# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes Device Boot Start End Blocks Id System Disk /dev/sdb: 21.5 GB, 21474836480 bytes Disk /dev/sdb doesn’t contain a valid partition table To use that device, we must format it: fdisk /dev/sdb server1:~# fdisk /dev/sdb The number of cylinders for this disk is set to 20480. Command (m for help): <– m Command (m for help): <– n Command (m for help): <– t 0 Empty 1e Hidden W95 FAT1 80 Old Minix be Solaris boot Command (m for help): <– w Calling ioctl() to re-read partition table. Afterwards, the output of fdisk -l should look as follows: root@server1:~# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes Device Boot Start End Blocks Id System Disk /dev/sdb: 21.5 GB, 21474836480 bytes Device Boot Start End Blocks Id System Now we create a filesystem on /dev/sdb1… mkfs.ext4 /dev/sdb1 … and mount it for test purposes: mount /dev/sdb1 /mnt You should now see the new device in the outputs of… mount root@server1:~# mount … and df -h root@server1:~# df -h You can unmount it like this: umount /mnt To have the device mounted automatically at boot time, e.g. in the directory /storage, we create that directory… mkdir /storage … and add the following line to /etc/fstab: vi /etc/fstab
For test purposes, you can now reboot the system: reboot After the reboot, the device should be mounted: mount root@server1:~# mount df -h root@server1:~# df -h |