33.2. Shared Block Storage with iSCSI and Multipath
iSCSI carries SCSI commands over TCP. The target owns the disk and exports one or more LUNs; the initiator is the client kernel's SCSI stack. Between them sit a portal address, an IQN name, an access control list, and usually CHAP authentication. The client sees a SCSI disk, not a file share, so every filesystem and volume-manager rule from the local-disk world still applies.
33.2.1. Targets, Initiators, LUN Mapping, and Authentication
On Debian the target is provided by tgt, and the initiator by open-iscsi.
Install the target package on storage1, as root:
# apt install tgt
The command prompts for confirmation and prints the package manager's normal
progress. On storage2 and storage3, as root, install the initiator and
multipath tools:
# apt install open-iscsi multipath-tools
The practice hosts also carry the Ceph and cluster packages used from
section 33.4 onward. On storage1, as john, the recorded inventory shows
them together with the target package:
$ dpkg-query -W tgt ceph-common ceph-mon ceph-mgr ceph-osd ceph-mds radosgw ceph-volume pacemaker corosync crmsh drbd-utils
ceph-common 18.2.7+ds-1+deb13u1
ceph-mds 18.2.7+ds-1+deb13u1
ceph-mgr 18.2.7+ds-1+deb13u1
ceph-mon 18.2.7+ds-1+deb13u1
ceph-osd 18.2.7+ds-1+deb13u1
ceph-volume 18.2.7+ds-1+deb13u1
corosync 3.1.9-2+deb13u1
crmsh 5.0.0~rc1-1
drbd-utils 9.22.0-1.1
pacemaker 3.0.0-2
radosgw 18.2.7+ds-1+deb13u1
tgt 1:1.0.85-1.3
On the initiators, open-iscsi is 2.1.11-1+deb13u2 and multipath-tools is
0.11.1-2; the initiator-side inventory is captured in section 33.3.2.
tgt reads /etc/tgt/targets.conf and every file in /etc/tgt/conf.d/. A
target definition names the IQN, the backing store, the clients allowed to
connect, and the authentication method. The following file on storage1
exports two disposable disks: /dev/vdb as shared-lun for the single-writer
exercise and /dev/vdc as cluster-lun for GFS2. Both targets accept the two
practice networks and require CHAP.
<target iqn.2026-11.example.debian:shared-lun>
driver iscsi
controller_tid 2
backing-store /dev/vdb
initiator-address 192.168.234.0/24
initiator-address 192.168.235.0/24
incominguser handbook-user handbook-secret
</target>
<target iqn.2026-11.example.debian:cluster-lun>
driver iscsi
controller_tid 1
backing-store /dev/vdc
initiator-address 192.168.234.0/24
initiator-address 192.168.235.0/24
incominguser handbook-user handbook-secret
</target>
The directives have specific jobs:
| Directive | Effect |
|---|---|
driver iscsi |
selects the iSCSI target driver |
backing-store |
names the block device, file, or LVM volume exported as a LUN |
initiator-address |
permits connections from the listed network or address; repeat for each client network |
incominguser |
requires CHAP with the given user name and secret |
controller_tid |
fixes the target ID so the two targets remain distinguishable in tgtadm output |
CHAP authenticates the initiator but does not encrypt the traffic. Run iSCSI on a dedicated network or a protected VLAN, and do not reuse a secret that protects anything else. An ACL limits which addresses may connect, but it is not a substitute for authentication on a network that other hosts can reach.
On storage1, as root, restart the target after changing the file:
# systemctl restart tgt
The restart normally prints nothing. On storage1, the target administration
command shows both targets, their LUNs, accounts, and ACLs:
# tgtadm --mode target --op show
Target 1: iqn.2026-11.example.debian:cluster-lun
System information:
Driver: iscsi
State: ready
LUN information:
LUN: 0
Type: controller
...
LUN: 1
Type: disk
Size: 1074 MB, Block size: 512
Backing store type: rdwr
Backing store path: /dev/vdc
Account information:
handbook-user
ACL information:
192.168.234.0/24
192.168.235.0/24
Target 2: iqn.2026-11.example.debian:shared-lun
...
LUN: 1
Type: disk
Backing store path: /dev/vdb
Account information:
handbook-user
ACL information:
192.168.234.0/24
192.168.235.0/24
Selected output; the controller LUN and the repeated per-target fields are omitted. The controller LUN is not usable storage. The disk LUN is the device the initiator will see, and the backing-store path confirms which local disk is being exported.
33.2.2. Presenting Disposable Storage to Cluster Nodes
On each initiator, as root, discovery asks the portal which targets it
exports. The result is written to the initiator's node database under
/etc/iscsi/nodes; it does not log in yet. On storage2, the first portal
answers with both targets:
# iscsiadm -m discovery -t sendtargets -p 192.168.234.11
192.168.234.11:3260,1 iqn.2026-11.example.debian:cluster-lun
192.168.234.11:3260,1 iqn.2026-11.example.debian:shared-lun
Run the same discovery against the second portal so multipath has two paths:
# iscsiadm -m discovery -t sendtargets -p 192.168.235.11
192.168.235.11:3260,1 iqn.2026-11.example.debian:cluster-lun
192.168.235.11:3260,1 iqn.2026-11.example.debian:shared-lun
The second discovery returns the same target names with the second portal's
address, which is what gives each LUN two independent TCP paths. storage3
runs the same two discovery commands.
The relevant iscsiadm modes and options are worth fixing in mind:
| Option | Description |
|---|---|
-m discovery |
work with discovery records rather than sessions |
-t sendtargets |
ask the portal for its target list |
-p address:port |
portal to contact; port 3260 is the iSCSI default |
-m node --login |
log in to a recorded target |
-m session |
list active sessions |
-r id |
restrict a session operation to one session ID |
--logout |
end a session without deleting its node record |
-o show |
print the stored node records |
-o delete |
remove a node record |
On storage2, as root, log in to each target through each portal. Each login
prints one line; the block shows the login for shared-lun through the
second portal:
# iscsiadm -m node -T iqn.2026-11.example.debian:shared-lun -p 192.168.235.11 --login
Login to [iface: default, target: iqn.2026-11.example.debian:shared-lun, portal: 192.168.235.11,3260] successful.
Repeat the command for cluster-lun and for the 192.168.234.11 portal;
each prints the same one-line confirmation. With both targets logged in
through both portals, the session table shows four connections. The numbers
in brackets are session IDs, which differ between runs:
# iscsiadm -m session
tcp: [71] 192.168.234.11:3260,1 iqn.2026-11.example.debian:shared-lun (non-flash)
tcp: [72] 192.168.235.11:3260,1 iqn.2026-11.example.debian:shared-lun (non-flash)
tcp: [73] 192.168.234.11:3260,1 iqn.2026-11.example.debian:cluster-lun (non-flash)
tcp: [74] 192.168.235.11:3260,1 iqn.2026-11.example.debian:cluster-lun (non-flash)
The kernel now has four SCSI devices for two LUNs. Without multipath, each
path would appear as an independent disk and a careless mkfs would write to
only one of them. Multipath aggregates the paths by WWID before the filesystem
layer sees a disk.
33.2.3. Persistent Sessions, Device Identity, and Multipath Configuration
Automatic login belongs in /etc/iscsi/iscsid.conf, not in a shell script
that runs after boot. Set the session startup policy and the CHAP credentials
that match the target:
node.startup = automatic
node.session.auth.authmethod = CHAP
node.session.auth.username = handbook-user
node.session.auth.password = handbook-secret
In the packaged file, node.startup is an active line set to manual, and
the CHAP keys are present but commented out; change the value to automatic
and remove the comments on the keys you use. Existing node records keep the
values they were discovered with, so update them or rediscover after changing
the global file. On storage2, as root, iscsiadm -m node -o show prints the
effective record. The important lines are:
# iscsiadm -m node -o show
# BEGIN RECORD 2.1.11
node.name = iqn.2026-11.example.debian:cluster-lun
node.tpgt = 1
node.startup = automatic
...
node.session.auth.authmethod = CHAP
node.session.auth.username = handbook-user
node.session.auth.password = ********
...
node.conn[0].startup = manual
# END RECORD
Selected output; three other records and the interface defaults are omitted.
The # BEGIN RECORD and # END RECORD lines are literal output from
iscsiadm, not root prompts. node.startup = automatic makes the session
come back at boot: the open-iscsi service logs in every node record whose
startup policy is automatic. The per-connection
node.conn[0].startup = manual is the stored default for the individual
connection; the node-level policy is what governs the boot-time login.
multipath-tools needs to know which devices belong together. The safest
identity is the LUN's WWID: the tgt target builds it from its target ID and
the LUN number, not from the backing device's contents, so it is stable across
reboots and independent of the SCSI device names. This configuration disables
friendly-name guessing, groups all paths of a WWID into one round-robin group,
and gives the two practice LUNs stable aliases:
defaults {
find_multipaths no
user_friendly_names no
path_grouping_policy multibus
path_selector "round-robin 0"
failback manual
no_path_retry 5
}
blacklist {
devnode "^vd[a-z]"
}
multipaths {
multipath {
wwid 360000000000000000e00000000020001
alias shared-lun
}
multipath {
wwid 360000000000000000e00000000010001
alias cluster-lun
}
}
| Directive | Effect |
|---|---|
find_multipaths no |
creates a multipath device for every non-blacklisted WWID, even with one path |
user_friendly_names no |
keeps the kernel name based on the WWID instead of mpatha |
path_grouping_policy multibus |
puts all paths of a LUN in one group and uses them together |
path_selector "round-robin 0" |
rotates I/O across the active paths |
failback manual |
does not automatically move back after a path recovers |
no_path_retry 5 |
queues I/O for five retries, then fails it if no path is usable |
blacklist devnode "^vd[a-z]" |
keeps local virtio disks out of multipath |
The blacklist is essential on a host whose local disks are also visible: a
multipath device built from the wrong disk can make the root filesystem
disappear. On storage2, as root, restart multipathd after editing the
file, then inspect the result:
# multipath -ll
cluster-lun (360000000000000000e00000000010001) dm-1 IET,VIRTUAL-DISK
size=1.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=enabled
|- 4:0:0:1 sdc 8:32 active ready running
`- 5:0:0:1 sdd 8:48 active ready running
shared-lun (360000000000000000e00000000020001) dm-0 IET,VIRTUAL-DISK
size=1.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=enabled
|- 2:0:0:1 sda 8:0 active ready running
`- 3:0:0:1 sdb 8:16 active ready running
Each LUN has two active ready running paths, and the alias comes from
multipath.conf. On storage2, the stable device names are symlinks into the
device-mapper tree:
# ls -l /dev/mapper/shared-lun /dev/mapper/cluster-lun
lrwxrwxrwx 1 root root 7 Nov 26 02:50 /dev/mapper/cluster-lun -> ../dm-1
lrwxrwxrwx 1 root root 7 Nov 26 02:50 /dev/mapper/shared-lun -> ../dm-0
Use /dev/mapper/shared-lun in /etc/fstab and cluster resource definitions,
not /dev/sda or /dev/dm-0. The SCSI letters can change when a path is
added or the host reboots; the WWID-based mapper name does not.
33.2.4. Path Failure, Session Recovery, and I/O Timeout Behavior
A path failure should not become an I/O failure while another path remains.
The test needs I/O flowing through the LUN, so put a filesystem on it first.
On storage2, as root, create an ext4 filesystem on shared-lun; -F
answers the confirmation mkfs.ext4 prints for a device with existing
signatures:
# mkfs.ext4 -F -L shared-data /dev/mapper/shared-lun
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 646422ce-e716-41ab-ae6b-fe9bf353b628
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: 0/8 done
Writing inode tables: 0/8 done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: 0/8 done
The command also prints the mke2fs version banner on standard error before
the progress output; later mkfs blocks in this chapter omit that banner. On
storage2, as root, create the mount point and mount the filesystem:
# mkdir -p /mnt/shared-ext4
The command normally prints nothing. Mount the filesystem:
# mount /dev/mapper/shared-lun /mnt/shared-ext4
The mount normally prints nothing. The filesystem's writes now flush through
the multipath device, so the exercise below tests what a lost path does to
I/O on shared-lun. On storage2, as root, log out one session to simulate
a broken cable or a failed target port. The session ID comes from
iscsiadm -m session; here it is 72, the second path to shared-lun:
# iscsiadm -m session -r 72 --logout
Logging out of session [sid: 72, target: iqn.2026-11.example.debian:shared-lun, portal: 192.168.235.11,3260]
Logout of [sid: 72, target: iqn.2026-11.example.debian:shared-lun, portal: 192.168.235.11,3260] successful.
On storage2, as root, multipath now sees one fewer path. The dev_st
column reports whether the path is usable:
# multipathd show paths
hcil dev dev_t pri dm_st chk_st dev_st next_check
2:0:0:1 sda 8:0 1 active ready running XXXXXXXX.. 17/20
4:0:0:1 sdc 8:32 1 active ready running XXXXXXXX.. 17/20
5:0:0:1 sdd 8:48 1 active ready running XXXXXXXX.. 17/20
The failed path's device (sdb) is gone from the table. The filesystem
mounted at the start of this section is still mounted, and the remaining
path still serves its I/O. On storage2, as root, write through it:
# echo survived-one-path > /mnt/shared-ext4/path-test.txt
The write normally prints nothing. Read it back:
# cat /mnt/shared-ext4/path-test.txt
survived-one-path
Log the path back in and confirm that multipath notices the restored device:
# iscsiadm -m node -T iqn.2026-11.example.debian:shared-lun -p 192.168.235.11 --login
Login to [iface: default, target: iqn.2026-11.example.debian:shared-lun, portal: 192.168.235.11,3260] successful.
# multipathd show paths
hcil dev dev_t pri dm_st chk_st dev_st next_check
2:0:0:1 sda 8:0 1 active ready running X......... 3/20
4:0:0:1 sdc 8:32 1 active ready running X......... 3/20
5:0:0:1 sdd 8:48 1 active ready running X......... 3/20
3:0:0:1 sdb 8:16 1 active ready running XXXXXXXXX. 19/20
The restored sdb path is back in the table and marked ready; with the
single-group multibus policy it rejoins the round-robin rotation
immediately. The X marks show the checker's progress toward the next
scheduled check. failback manual matters for configurations with several
path groups, such as active/standby storage controllers: it keeps the
cluster on the surviving group after a failure instead of switching back the
moment the preferred group recovers, which can cause flapping under an
intermittent fault.
What happens when every path fails is a separate decision. With
no_path_retry 5, the kernel queues I/O while the retry budget lasts, then
fails the requests. The filesystem sees I/O errors, and the application must
handle them. A larger value buys more time for a transient fabric outage at
the cost of longer hangs; queue_if_no_path without a limit can hang a mount
forever. Choose the behavior for the application, not for the convenience of
the test. On a cluster filesystem, a long I/O hang also delays lock recovery
and can trigger fencing.
33.2.5. Restricting Ordinary Filesystems to a Single Active Owner
The ext4 filesystem from the path test is now mounted on storage2. That
mount is safe for one reason: no other host has the same filesystem mounted.
Section 33.1.2 explained why an ordinary filesystem tolerates exactly one
owner; this section performs the handoff that keeps that rule true, with
ownership moving only after the old owner has flushed and unmounted.
Before moving the filesystem, record who owns it. On storage2, as root,
write an owner marker:
# echo owner-storage2 > /mnt/shared-ext4/owner.txt
The write normally prints nothing. Read it back:
# cat /mnt/shared-ext4/owner.txt
owner-storage2
The other node can identify the same filesystem without mounting it. On
storage3, as root, blkid reads the superblock through the shared LUN:
# blkid /dev/mapper/shared-lun
/dev/mapper/shared-lun: LABEL="shared-data" UUID="646422ce-e716-41ab-ae6b-fe9bf353b628" BLOCK_SIZE="4096" TYPE="ext4"
The same UUID on both hosts proves that they see the same device, not that
they may both mount it. On storage3, no mount exists yet:
# findmnt /mnt/shared-ext4
The command exits with status 1 and prints nothing, which is the expected
result for an unmounted path. On storage2, as root, unmount the filesystem
before the other node mounts it:
# umount /mnt/shared-ext4
On storage3, as root, mount the filesystem and read the marker:
# mkdir -p /mnt/shared-ext4
The command normally prints nothing. Mount the filesystem:
# mount /dev/mapper/shared-lun /mnt/shared-ext4
Read the marker written by the previous owner:
# cat /mnt/shared-ext4/owner.txt
owner-storage2
The handoff is safe because the first owner flushed and unmounted before the second mounted. A script that mounts on both nodes without that ordering does not demonstrate shared storage; it demonstrates why ext4 is not a cluster filesystem. If you must inspect an ext4 filesystem on a second host while the first is down, mount it read-only and do not let the first host return until the inspection is finished. For automatic failover, put the mount under Pacemaker or use GFS2, and provide fencing.
Figure 33.3. The LUN is shared; the right to write is not. An ordinary filesystem needs one owner, while a cluster filesystem needs a lock manager and a fence.