Install and use iscsi target and initiator in ubuntu 12.04. Objective: To mount the hard disk on one host as one iscsi target to another host. 1. install iscsi target software $ sudo apt-get install iscsitarget-source iscsitarget-dkms (2) modify the iscsi target configuration file $ sudo vi/etc/default/iscsitarget ISCSITARGET_ENABLE = true # change false to true (3) prepare storage for the target. The real hard disk can be used here, for example,/dev/sdx can also use a virtual machine disk, such as a dd file: dd if =/dev/zero of =/var/lun1.bin count = 0 obs = 1 seek = 50G. the following uses a real hard disk as an example to perform various operations. Configure the target under www.2cto.com Centos and configure the iscsi target under centos ### create a target, id = 1, iqn = iqn.2013-02. node2, iqn is the unique descriptor of the target in the LAN $ sudo tgtadm -- lld iscsi -- op new -- mode target -- tid 1-T iqn.2013-02. node2 ### run the following command to view the currently created target and lun www.2cto.com $ sudo tgtadm -- lld iscsi -- op show -- mode target ### Add a lun to the specified target, use tid to specify the target. Here, add/dev/sdl to the target of tid = 1. $ sudo tgtadm -- lld iscsi -- op new -- mode log Icalunit -- tid 1 -- lun 1-B/dev/sdl ### Note:/dev/sdl is a whole disk. You can also add a partition to the target, for example,/dev/sdl1,/dev/sdb1 ### to enable a target to be accessed by initiator, you must first run the following command $ sudo tgtadm -- lld iscsi -- op bind -- mode target -- tid 1-I ALL ### Delete the specified target, specify $ sudo tgtadm -- lld iscsi -- op show -- mode target -- op delete -- tid 1 configuration of iscsi target in ubuntu by using tid. Configure iscsi target in ubuntu # vi/etc/iet /ietd. add the following information to the end of the conf file: Target iqn.2012-12.lo Cal. mynet: storage. lun1 // iqn.2012-12. local. mynet: storage. lun1 is iqn. For the format, see iqn Lun 1 Path =/dev/sdl1, Type = fileio in centos, ScsiId = lun1, ScsiSN = lun1. The content after Target in the first line can be modified as needed, however, it is best to keep the format in the example. The second line creates a LUN on the Target. After the serial number is 1 and the above configuration is executed, restart the iscsitarget service: centos service tgtd restartubuntu service iscsitarget restart (4) configure the iscsi target password-based access method (skip this step if you do not want to set a password, and this is the ubuntu configuration method) www.2cto.com assume that the username and password of the iscsi target to be configured are as follows: usernam E = dylan password = 123456 if the ISCSI Target Server requires a user name and password, you must go to/etc/iscsi/iscsid. conf. The configuration options are as follows: node. session. auth. username = dylan node. session. auth. password = 123456 discovery. sendtargets. auth. username = dylan discovery. sendtargets. auth. password = 123456. The two groups of usernames and passwords are the usernames and passwords set by Target Server. After modification, restart the open-iscsi service: # service open-iscsi restart 2. iscsi initiator end www.2cto.com (1) install open-scsi sudo apt-get install open-iscsi-utils (2) iscsi target sudo iscsiadm-m discovery-t sendtargets-p 192.168.35.17 is displayed as follows: 192.168.35.17: 3260,1 iqn.2013-02. node2 (3) use target sudo iscsiadm-m node -- targetname iqn.2013-02. node2-p 192.168.35.17 -- after login executes the preceding operations, you can add/dev/sdx (4) to the local host to delete target sudo iscsiadm-m node -- targetname iqn.2013-02. node2-p 192.168.35.17-u