How to mount and manage iscsi shares on Linux Ubuntu

Table of Contents

Case #

This article provides instructions on how to mount and manage iscsi shares on Linux Ubuntu.

Solution #

To mount and manage iSCSI shares on Linux Ubuntu, follow the step-by-step procedure below:

  1. Install iSCSI Initiator packages
sudo apt update
sudo apt install open-iscsi

Discover the available iSCSI targets:

sudo iscsiadm --mode discoverydb --type sendtargets --portal <iSCSI_server_IP_address> --discover

Replace <iSCSI_server_IP_address> with the IP address of the iSCSI server.

For example:

sudo iscsiadm --mode discoverydb --type sendtargets --portal 192.168.0.100 --discover

List the discovered iSCSI targets:

sudo iscsiadm --mode node

You should see the discovered iSCSI target(s) listed.

Log in to the desired iSCSI target:

sudo iscsiadm --mode node --targetname <iSCSI_target_name> --portal <iSCSI_server_IP_address> --login

Replace <iSCSI_target_name> with the name of the iSCSI target and <iSCSI_server_IP_address> with the IP address of the iSCSI server.

For example:

sudo iscsiadm --mode node --targetname iqn.2021-09.com.example:target --portal 192.168.0.100 --login

Verify the iSCSI session is established:

sudo iscsiadm --mode session

You should see the active iSCSI session listed.

Display the available iSCSI disks:

lsblk

The iSCSI disks should be visible as new devices.

Partition and format the iSCSI disk:

sudo parted /dev/sdX -- mklabel gpt
sudo parted /dev/sdX -- mkpart primary ext4 0% 100%
sudo mkfs.ext4 /dev/sdX1

Replace /dev/sdX with the appropriate device identifier for the iSCSI disk.

Create a directory to serve as the mount point for the iSCSI share:

sudo mkdir /mnt/iscsi_share

Mount the iSCSI share to the specified directory:

sudo mount /dev/sdX1 /mnt/iscsi_share

Replace /dev/sdX1 with the appropriate partition for the iSCSI share.

Verify the iSCSI share is mounted successfully:

df -h

This command will display the mounted file systems, and you should see the iSCSI share listed.

Make the iSCSI share mount automatically at system startup: Edit the /etc/fstab file using a text editor such as nano or vim:

sudo nano /etc/fstab

Add the following line at the end of the file:

/dev/sdX1 /mnt/iscsi_share ext4 defaults 0 0

Replace /dev/sdX1 with the appropriate partition for the iSCSI share.

Save the changes and exit the text editor.

Unmount the iSCSI share:

sudo umount /mnt/iscsi_share

Disconnect the iSCSI session:

sudo iscsiadm --mode node --targetname <iSCSI_target_name> --portal <iSCSI_server_IP_address> --logout

Replace <iSCSI_target_name> with the name of the iSCSI target and <iSCSI_server_IP_address> with the IP address of the iSCSI server.

Remove the iSCSI target from the discovery database:

sudo iscsiadm --mode node --targetname <iSCSI_target_name> --portal <iSCSI_server_IP_address> --op delete 
# Replace <iSCSI_target_name> with the name of the iSCSI target and <iSCSI_server_IP_address> with the IP address of the iSCSI server.

Remember to replace <iSCSI_server_IP_address> and <iSCSI_target_name> in the above commands with the appropriate values for your iSCSI server and target. Additionally, ensure you have the necessary permissions and access to the iSCSI server and target before attempting to establish the connection.

Powered by BetterDocs