3
votes

I am trying to automate mounting/unmounting of iSCSI mounts on Ubuntu 16.04.

1) How do I list all the iSCSI mounts present on the Linux system? For example, NFS mounts can be listed using 'df -h -t nfs'.

2) Once I connect to the iSCSI server(target), on the iSCSI client(initiator) how do I identify if the filesystem is sda, sdb or sdc? dmsg would give this info but I am looking for a command to fetch this.

1

1 Answers

1
votes

Retrieve the iSCSI sessions:

# iscsiadm -m session
tcp: [7] 172.16.5.148:3260,1 iqn.2009-12.com.blockbridge:t-pjxfzuecga-eajejghg (non-flash)
tcp: [8] 172.16.5.148:3260,1 iqn.2009-12.com.blockbridge:t-pjxfzufjjo-pokqaja (non-flash)
tcp: [9] 172.16.5.148:3260,1 iqn.2009-12.com.blockbridge:t-pjxfzufjkp-illoghjk (non-flash)

Retrieve the list of SCSI devices on the system, including their transports. Filter by IQN:

# lsscsi -t | grep iqn
[8:0:0:0]    disk    iqn.2009-12.com.blockbridge:t-pjxfzuecga-eajejghg,t,0x1  /dev/sda
[9:0:0:0]    disk    iqn.2009-12.com.blockbridge:t-pjxfzufjjo-pokqaja,t,0x1  /dev/sdb
[10:0:0:0]   disk    iqn.2009-12.com.blockbridge:t-pjxfzufjkp-illoghjk,t,0x1  /dev/sdc

The best way to ensure you've got the right drive is to map drives that have actual SCSI ID's (WWN). These are accessible with lsscsi -i:

 # lsscsi -i
[14:0:0:0]   disk    LIO-ORG  test1            4.0   /dev/sdc   3600140546e116005d8f4999bc09660ac
[15:0:0:0]   disk    LIO-ORG  test2            4.0   /dev/sdd   36001405a933d07e7023461f9be250f9a
[16:0:0:0]   disk    LIO-ORG  test3            4.0   /dev/sde   360014059d9bb9e0e16543059b85ffdb2
[17:0:0:0]   disk    LIO-ORG  test4            4.0   /dev/sdg   3600140529ce8b47a4754fc39b1d3133a

Or, perhaps better, in /dev/disk/by-id:

# cd /dev/disk/by-id
# ls -l scsi*
lrwxrwxrwx. 1 root root 9 May 11 18:29 scsi-3600140512ee850056d945b6916c46b4f -> ../../sdf
lrwxrwxrwx. 1 root root 9 May 11 18:23 scsi-3600140529ce8b47a4754fc39b1d3133a -> ../../sdg
lrwxrwxrwx. 1 root root 9 May 11 18:23 scsi-3600140546e116005d8f4999bc09660ac -> ../../sdc
lrwxrwxrwx. 1 root root 9 May 11 18:23 scsi-360014059d9bb9e0e16543059b85ffdb2 -> ../../sde
lrwxrwxrwx. 1 root root 9 May 11 18:23 scsi-36001405a933d07e7023461f9be250f9a -> ../../sdd