In this Post we will discuss How to scan luns in linux.
When we are adding new disk on server sometime that disk is not reflecting on server. Through script we can scanning a Redhat /CentOS Linux server and collect the new disk device names (multipath device names) which one provided by storage team. The script should scan the all the host device for new LUN’s and it will provide the new device name (/dev/mapper/device_name).
Once you added new disk on server or the storage team has mapped the new LUN’s with the Linux host, new LUN can be discovered by scanning the storage LUN ID at the server end.
Scanning can be performed in two ways.
- Scan each scsi host device using /sys/class/scsi_host class file.
- Run the for loop script to detect new disks.
Method 1: How to scan luns in linux
How to detect new LUNs and SCSI disks in Linux, using the “/sys/class/scsi_host” class file.
sysfs provides an information about devices, kernel modules, filesystems and other kernel components etc. Go to inside /sys/class/scsi_host/ directory and you can see list of hosts device name, now you can scan manually one by one. Each scsi host device can be scanned using the echo command, as mentioned below. Follow the below steps for how to scan luns in linux.
- #echo “- – -” > /sys/class/scsi_host/host[n]/scan
Three dashes (- – – ) in the above command which will rescan everything.
- “-” channel
- “-” SCSI target ID
- “-” LUN ID
Run the for loop script to scan for new luns disks. After rescanning, confirm whether you are seeing the new storage disks
- #for i in /sys/class/scsi_host/*; do echo “- – -” | sudo tee $i/scan; ls /dev/sd*; done