This topic describes how to connect to and use iSCSI volumes from a Linux operating system.

Prerequisites

You have created an iSCSI volume. For more information, see Create an iSCSI volume.

Procedure

  1. Log on to the ECS console.
    Note If your local computer is connected to an Alibaba Cloud VPC network through a leased line, you can also perform the operations from your local computer.
  2. Install the iscsi-initiator-utils package.

    You need the iscsi-initiator-utils package to connect to the target iSCSI volume. If you have already installed the iscsi-initiator-utils package, skip this step.

    sudo yum install iscsi-initiator-utils
  3. Run the following command to verify that the iSCSI daemon is running.
    • Run the following command if the operating system that you use is RHEL 5 or RHEL 6.
      sudo /etc/init.d/iscsi status
    • If you are using RHEL 7, run the following command.
      sudo service iscsid status

    If the proceeding commands do not return running to you, run the udo /etc/init.d/iscsi start command to start the iSCSI daemon.

  4. Optional. Configure CHAP authentication.
    Note If you enabled CHAP when you created the iSCSI volume, you need to configure CHAP settings in the Advanced Settings dialog box before you can use the iSCSI volume.
    1. Run the following command to open the iscsid.conf configuration file.
      vi /etc/iscsi/iscsid.conf
    2. Find CHAP Settings and delete the hash character (#) before the relevant comments, and set the CHAP username and password.
      • Enter the CHAP username that you set when you created the iSCSI volume.
      • Enter the CHAP password that you set when you created the iSCSI volume.
      Configure CHAP authentication
  5. Discover the iSCSI volume.
    iscsiadm -m discovery -t st -p 10.0.0.0:3260
    • 10.0.0.0 is the IP address of the block gateway.

      To obtain the IP address of a block gateway, navigate to the Volumes page in the Cloud Storage Gateway console.

    • 3260 is the connection port. Do not change the port.
  6. Mount the iSCSI volume.
    iscsiadm -m node -T iqn.2009-09.com.aliyun.iscsi-sgw:0test-test730 -p 10.0.0.0:3260 –l
    • iqn.2009-09.com.aliyun.iscsi-sgw:0test-test730 is the iSCSI target. You can obtain the target name in step 2.
    • 10.0.0.0 is the IP address of the block gateway.

      To obtain the IP address of a block gateway, navigate to the Volumes page in the Cloud Storage Gateway console.

    • 3260 is the connection port. Do not change the port.
    Note Due to the limits of the iSCSI protocol, do not mount one iSCSI volume to multiple Linux clients.
  7. Run the fdisk -l or lsblk command to view the iSCSI volume.

    In this state, the mounted iSCSI volume becomes an available raw disk. You can read data from and write data to the iSCSI volume from a local computer.

    View the iSCSI volume