LINUXOR.SK ... open source notes ...

Linux Storage - Hot removal of a LUN

category: solutionz · date: 2010-09-30 · updated: 2026-10-03 · author: LALA

Linux Storage Solution · Config document · referenced from RDAC problems and LUN removal

noteTwo lines in this command set are kept as they were typed and must not be copied as they stand. The small script's echo “${DSK} … opens with a typographic quote and never closes it. The eight echo 1>/sys/bus/scsi/devices/…/delete lines have no space before >, so the shell reads 1> as a redirection of file descriptor 1 and echo writes a bare newline into delete; echo 1 > was meant. As I understand it the kernel removes the device on any write to that attribute, so the lines worked, but by accident.

Problem 2 of my notes: a LUN had to be removed from the running system without a reboot (hot remove). The notes collect three ways to say "delete" to the SCSI layer through sysfs, the command that shows which disk is which, a quoted English note about taking a path offline, a small script that prints the vendor and model of every block device, and, as the case actually done, the removal of all eight physical paths to the standby array DS5300-SITEB (array ID 1).

ItemValue
Run asroot on mppsrv01
HostRed Hat Enterprise Linux AS 4, kernel 2.6.9-89.0.9.ELsmp, HBAs host0 and host1, virtual MPP adapter host2
Devicesthe virtual disks /dev/sdc and /dev/sdd (LUNs 1 and 2 of DS5300-SITEB on host2) and the eight physical devices behind them, 0:0:2:1 to 1:0:3:2
Writes to/sys/block/<sd>/device/delete, /sys/bus/scsi/devices/<h:c:t:l>/delete
Driver versionRDAC 09.03.0B05.0331

The commands

Removing a LUN by its disk name, where sd* is the disk device to be removed from the system. Here sdc and sdd, the two virtual disks of the standby array:

bash
$ echo "1" > /sys/block/sdc/device/delete
$ echo "1" > /sys/block/sdd/device/delete

Removing a LUN by its SCSI address, where h is the HBA number, c the channel on the HBA, t the SCSI target ID and l the LUN. The notes keep the pattern, not a run of it:

bash
$ echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete

The device name, the HBA number, the channel, the target and the LUN are found with one listing. The notes keep no output for it:

bash
$ ls -l /dev/disk/by-*

The notes then quote a note in English, which I give as it stands: "Take the path offline using echo offline > /sys/block/sda/device/state. This will cause any subsequent IO sent to the device on this path to be failed immediately. Device-mapper-multipath will continue to use the remaining paths to the device." It speaks of Device-mapper multipath, not of RDAC, and sda in it is an example name, not the sda of this host, which is LUN 1 of the main array.

The small script "who uses what": for every block device that has a vendor attribute, print its name, vendor and model. It is kept as it was in the notes, with its unclosed typographic quote:

bash
for DSK in `ls /sys/block/`
do
if [ -e "/sys/block/${DSK}/device/vendor" ]
then
VENDOR=`cat /sys/block/${DSK}/device/vendor`
MODEL=`cat /sys/block/${DSK}/device/model`
echo “${DSK} ${VENDOR} ${MODEL}
fi
done

The paths leading to the array with ID 1, DS5300-SITEB:

bash
$ mppUtil -g 1 | grep PathId
output 4 lines
PathId: 77000002 (hostId: 0, channelId: 0, targetId: 2)
PathId: 77010002 (hostId: 1, channelId: 0, targetId: 2)
PathId: 77000003 (hostId: 0, channelId: 0, targetId: 3)
PathId: 77010003 (hostId: 1, channelId: 0, targetId: 3)

Deleting every path to the array with ID 1: two hosts, two targets, two LUNs, eight SCSI devices. The lines are kept exactly, with the 1> of the note above; the notes write them in four pairs, one pair per path, separated by blank lines, which the fence leaves out:

bash
$ echo 1>/sys/bus/scsi/devices/0\:0\:2\:1/delete
$ echo 1>/sys/bus/scsi/devices/0\:0\:2\:2/delete
$ echo 1>/sys/bus/scsi/devices/1\:0\:2\:1/delete
$ echo 1>/sys/bus/scsi/devices/1\:0\:2\:2/delete
$ echo 1>/sys/bus/scsi/devices/0\:0\:3\:1/delete
$ echo 1>/sys/bus/scsi/devices/0\:0\:3\:2/delete
$ echo 1>/sys/bus/scsi/devices/1\:0\:3\:1/delete
$ echo 1>/sys/bus/scsi/devices/1\:0\:3\:2/delete

Reading it

CommandWhat it does
echo "1" > /sys/block/sdc/device/deleteasks the SCSI mid-layer to remove the device behind the block device sdc; here that is a virtual disk of the MPP adapter, so it is the virtual LUN that goes, not a physical path
echo 1 > /sys/class/scsi_device/h:c:t:l/device/deletethe same, addressed by host:channel:target:lun instead of by disk name
ls -l /dev/disk/by-*the udev symlinks by id, by path and by uuid, which show which sd name belongs to which SCSI address and which identifier
echo offline > /sys/block/sda/device/statefrom the quoted note: fails all further I/O on that path at once; the sentence about Device-mapper multipath continuing on the remaining paths is about DM-Multipath, which this host did not use
the small scriptprints <disk> <vendor> <model> for every SCSI block device; on this host that tells the VirtualDisk devices of the MPP adapter from the local disks. As I understand bash, the echo “${DSK} line prints a literal “ in front of each name because the shell does not treat the typographic quote as a quote; I did not run it
mppUtil -g 1, piped through grep PathIdthe four paths of array 1 as the driver sees them: targets 2 and 3 on hosts 0 and 1. The PathId line decodes itself; with two LUNs on each path, that is eight SCSI devices
echo 1>/sys/bus/scsi/devices/0\:0\:2\:1/deleteremoves the physical device 0:0:2:1 (host 0, channel 0, target 2, LUN 1); the colons are escaped for the shell, which is not needed but harmless. With 1> the attribute receives an empty line rather than 1; see the note

The order of the eight lines follows the PathId list: first both LUNs of target 2 on host 0, then target 2 on host 1, then target 3 on hosts 0 and 1. What the notes do not hold: whether sdc and sdd were removed first (the first two lines) and the eight paths afterwards, or whether the two blocks are alternatives; a listing before and after; and whether the driver's mppBusRescan -d ("remove an unmapped or disconnected device", see mppBusRescan commands) was tried instead. The links section of the notes keeps a forum thread titled "RDAC capable of hot removing unmapped LUNs?", so the question was on the author's mind.

Checked against the Linux kernel 7.2 and Red Hat Enterprise Linux 10

As builtToday
echo 1 > /sys/block/sdX/device/delete, echo 1 > /sys/bus/scsi/devices/h:c:t:l/deleteBoth attributes still exist in drivers/scsi/scsi_sysfs.c, and /sys/block/sdX/device/delete is the step Red Hat's current guide gives for removing a block device: after multipath -f and blockdev --flushbufs, "Remove each path to the device from the SCSI subsystem: echo 1 > /sys/block/device-name/device/delete"
echo offline > /sys/block/sda/device/state, from the quoted noteThe state attribute still exists and still knows offline. The step with exactly that wording ("Device-mapper-multipath will continue to use the remaining paths") is in the Red Hat Enterprise Linux 7 storage guide and no longer in the 9 and 10 guides
removing the paths behind an RDAC virtual LUN by handThe package readme states that "the Linux RDAC driver doesn't support LUN deletion", which explains why this was done in sysfs rather than with a driver command. RDAC was discontinued with SANtricity OS 11.25
1> instead of 1 >Still an accident waiting to happen; the research for this write-up did not verify how the kernel treats an empty write to delete, so my reading that any write triggers the removal stays a reading
← solutionz