In this guid I’ll explain how to setup an iSCSI initiator (client) on Debian 10.6. It should work with most Linux -based systems.

iSCSI is a SAN (storage area network) protocol in which a locally connected iSCSI hard disk is shown to the clients. The iSCSI protocol is a (IP-based) storage networking standard. It provides block-level access to storage devices over a TCP/IP network.

I used it to connect my Synology NAS to the Virtual Debian 10.6 Mailserver. The NAS Provides the ESXi Host with a datastorage for the virtual hard disks and as is also used as a backup storage.

Do not use the iSCSI Target on more than one machine at the same time, unless you have a cluster file system! Under normal conditions you can not share a hard drive with more then one computer.

Preconditions

Under Debain / Ubuntu we need to install the initiator (Open-iSCSI):

sudo apt install open-iscsi

We need to setup the node startup to automatic. The default setting is manual.

[...]
node.startup = automatic
[...]

After that we restart the initiator:

systemctl restart open-iscsi

Find the iSCSI targets

To find the iSCSI target we use the following command:

sudo iscsiadm -m discovery -t sendtargets -p IP_Adresse:3260

Options

-m –mode (discovery)
-t –type (sendtargets)
-p –portal (hostname or ip of the target)

In my example it would look like this.

root@debian-srv:/# iscsiadm -m discovery -t sendtargets -p 192.168.0.1:3260 -d3
iscsiadm: Max file limits 1024 1048576
iscsiadm: Could not open /etc/iscsi/send_targets/192.168.0.1,3260: No such file or directory
iscsiadm: starting sendtargets discovery, address 192.168.0.1:3260,
iscsiadm: connecting to 192.168.0.1:3260
iscsiadm: connected local port 42098 to 192.168.0.1:3260
iscsiadm: connected to discovery address 192.168.0.1
iscsiadm: login response status 0000
iscsiadm: discovery process to 192.168.0.1:3260 exiting
iscsiadm: disconnecting conn 0x23a6ddc13eb8, fd 3
192.168.0.1:3260,1 iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec
[fe80::233:23fe:ff41:e3fd]:3260,1 iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec

Now we have found the names of the available iSCSI targets. In this case one target, which is provided in IPv4 and IPv6:

192.168.0.1:3260,1 iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec

With the target found, we can now integrate it into our client. Therefore we use this command:

iscsiadm -m node -T iqn.2007-10:iscsi.target0 -p IP_Adresse:3260 --login

In this example it would look like this:

root@debian-srv:/# iscsiadm -m node -T iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec -p 192.168.0.1:3260 --login
Logging in to [iface: default, target: iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec, portal: 192.168.0.1,3260] (multiple)
Login to [iface: default, target: iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec, portal: 192.168.0.1,3260] successful.

Now we are successful connected to the target storage. To display the session we can use:

root@jit-mail-01:/# iscsiadm --mode session
tcp: [1] 192.168.0.1:3260,1 iqn.2000-01.com.synology:diskstation-host.Target-1.ffbc323sec (non-flash)

The output of the command fdisk -l would show the new device.

root@debian-srv:/# fdisk -l
Disk /dev/sda: 10 GiB, 499711 bytes, 497664 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe3d3a114

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 499711 497664 243M 5 Extended
/dev/sda3 501758 499711 497664 243M 83 Linux
/dev/sda5 501758 499711 497664 243M 8e Linux

Partition table entries are not in disk order.



Disk /dev/mapper/debian--srv--vg-root: 10 GiB, 40546336768 bytes, 497664 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/debian--srv--vg-swap_1: 10 GiB, 40546336768 bytes, 497664 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 50 GiB, 53687091200 bytes, 497664 sectors
Disk model: iSCSI Storage
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2550fsb4

Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 104857599 104855552 50G 83 Linux

In the lower area of the output we can now see the device sdb. This is our new connected iSCSI device. When it is a fresh created iSCSI target you need to first create a file-system. In this case an ext4 file system is already available.

Otherwise the output would be:

Disk /dev/sdb doesn't contain a valid partition table

You can use fdisk to format the new device. Then you can use mkfs.ext4, for example, to create a file system.

Now we mount it for test purpose to /tmp:

mount /dev/sdb1 /mnt

You should now be able to see the new device in the mount table. It can look like this:

root@server1:~# mount
 /dev/sda1 on / type ext3 (rw,errors=remount-ro)
 tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
 proc on /proc type proc (rw,noexec,nosuid,nodev)
 sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
 udev on /dev type tmpfs (rw,mode=0755)
 tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
 devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
 /dev/sdb1 on /mnt type ext4 (rw)

You can also use df -h to see the new mounted disk and its capacity.

Automatically mount the device

That the device is available after a restart, e.g. in the directory /storage. We make a new entry in the fstab file.

vi /etc/fstab

[...]
/dev/sdb1 /storage ext4 defaults,auto,_netdev 0 0

We can now restart the client to see that the directory is mounted on startup again.

Sources

0 Kommentare

Hinterlasse einen Kommentar

An der Diskussion beteiligen?
Hinterlasse uns deinen Kommentar!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

realm discover - justit.eu