Rescan SCSI bus on Linux

Rescan SCSI bus on Linux

Please note that the rescan SCSI bus on Linux does not interrupt operating system operation nor remove any of the disks. Rescanning SCSI bus on Linux with the below procedure will add/freshen devices but not remove them.

When Adding a New Disk

When adding a new disk to your Linux system you need to rescan SCSI host.

You can do this with the following command:

echo "- - -" > /sys/class/scsi_host/hostX/scan

..where X is the number of SCSI host to scan.

You probably have more than one SCSI host available so to make it right you should repeat the above command for each SCSI host available.

Below is a practical example on how to rescan SCSI bus on Linux and and see the newly added disk:

[root@node-1 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@node-1 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan

[root@node-1 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

The β€œ- – -” part is where you tell the SCSI host what exactly to rescan and the hyphens are wildcards which tell SCSI host to rescan all controllers, channels and LUNs.

When Increasing Existing Disk Size

If you changed the size of an existing disk you might notice that the operating system can not see the new disk size until you rescan SCSI bus on Linux operating system.

The easiest way i’ve found is to rescan the specific device with the following command:

echo "1" > /sys/class/block/sdX/device/rescan

..where X is the device you increased and want to rescan.

Below is a practical example on how to rescan SCSI bus on Linux and and see the newly added disk:

[root@node-1 ~]# echo "1" > /sys/class/block/sdb/device/rescan

The β€œ1” is a flag which causes the SCSI host to rescan the β€œsdb” block device and therefore refresh the data about the disk size. Please note that i choose this command due to the human readable β€œsdb” naming which is really easy to remember.

Otherwise the command could also be triggered as follows:

[root@node-1 ~]# echo "1" > /sys/class/scsi_device/2:0:1:0/device/rescan

..but in the last case you should know which device you want to rescan by the SCSI bus ID.

==================================

There are several ways/commands to determine the WWN of a Fibre Channel (FC) HBA and their details in Linux/Unix operating systems.

What is SAN? Most of the IT industries are using SAN (Storage Area Network) for high performance, and fast I/O.

SAN is a high speed network that makes connections between storage devices and servers which give better performance. It’s connected through Fibre Channel (FC) HBA.

SCSI (Small Computer System Interface) is a protocol which used to communicate between servers and storage devices.

Why we need to check this? If any Linux server or system is connected to one or more SAN switches through Fibre Channel (FC) HBA cards then storage team have to create a zoning on fiber channel switch to assign and unassign storage to a concern Linux host.

Navigate to the following URLs if you are looking for hardware related Linux commands.

If we need any additional storage for Linux host then we need to provide the WWN number to storage team and they can assign a new LUN based on the WWN number.

To discover the new LUNs which was assigned by storage team, we need to scan the SCSI host.

The famous FC Host Bus Adapters are QLogic, Emulex, Brocade, Cisco, etc.

Some of the important key notes about this.

WWN – World Wide Name

WWNN – World Wide Node Name

WWPN – World Wide Port Name

OUI – Organizationally Unique Identifier

How To Find The List of HBA Cards Installed On Your System

First identify how many HBA cards are installed on your system by running lspci command.

# lspci -nn | grep -i hba

07:00.0 Fibre Channel [0c04]: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA [1077:2532] (rev 02)

07:00.1 Fibre Channel [0c04]: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA [1077:2532] (rev 02)

08:00.0 Fibre Channel [0c04]: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA [1077:2532] (rev 02)

08:00.0 Fibre Channel [0c04]: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA [1077:2532] (rev 02)

Method-1: Manual Way to Identify HBA Cards information

This can be done using two methods, here i’m going to show you how to check this using manual method.

# ls -l /sys/class/fc_host

total 0

lrwxrwxrwx 1 root root 0 Oct 26 17:10 host1 -> ../../devices/pci0000:00/0000:00:02.0/0000:03:00.0/host1/fc_host/host1

lrwxrwxrwx 1 root root 0 Oct 26 17:10 host2 -> ../../devices/pci0000:00/0000:00:02.2/0000:04:00.0/host2/fc_host/host2

lrwxrwxrwx 1 root root 0 Oct 26 17:10 host3 -> ../../devices/pci0000:00/0000:00:02.2/0000:04:00.0/host2/fc_host/host3

lrwxrwxrwx 1 root root 0 Oct 26 17:10 host4 -> ../../devices/pci0000:00/0000:00:02.2/0000:04:00.0/host2/fc_host/host4

To View used HBA ports on server

#ls -lrt /sys/class/fc_transport/

drwxr-xr-x 2 root root 0 May 27 09:40 target7:0:2

drwxr-xr-x 2 root root 0 May 27 09:40 target7:0:1

drwxr-xr-x 2 root root 0 May 27 09:40 target7:0:0

drwxr-xr-x 2 root root 0 May 27 09:40 target5:0:2

drwxr-xr-x 2 root root 0 May 27 09:40 target5:0:1

drwxr-xr-x 2 root root 0 May 27 09:40 target5:0:0

To find the WWN numbers for your fc host, just run the below command to list it.

# cat /sys/class/fc_host/host?/port_name

0x500143802426baf2

0x500143802426baf3

0x500143802426baf4

0x500143802426baf5

If you would like to check the particular fc host wwn number, use the following format.

# cat /sys/class/fc_host/host1/node_name

0x500143802426baf2

Run the below command to check the state of HBA ports.

# more /sys/class/fc_host/host?/port_state

::::::::::::::

/sys/class/fc_host/host1/port_state

::::::::::::::

Online

::::::::::::::

/sys/class/fc_host/host2/port_state

::::::::::::::

Online

::::::::::::::

/sys/class/fc_host/host3/port_state

::::::::::::::

Online

::::::::::::::

/sys/class/fc_host/host4/port_state

::::::::::::::

Online

Method-2: How to Identify HBA Cards Information Using systool

Systool is a tool that uses APIs provided by libsysfs to gather information, view system device information by bus, class, and topology. It runs only on linux systems running kernels 2.5 or later, with the sysfs filesystem mounted.

It won’t install by default since isn’t a core tool, just run the below command to install sysfsutils package.

# yum install sysfsutils

Once the sysfsutils package get installed on your system, to find the WWN numbers for your fc host, just run the below command to list it.

# systool -c fc_host -v | grep port_name

port_name = "0x500143802426baf2"

port_name = "0x500143802426baf3"

port_name = "0x500143802426baf4"

port_name = "0x500143802426baf5"

Run the below command to check the state of HBA ports.

# systool -c fc_host -v | grep port_state

port_state = "Online"

port_state = "Online"

port_state = "Online"

port_state = "Online"

To view details about transporting HBA card

#systool -c fc_transport -v

If you would like to check the particular fc host wwn number, use the following format.

# systool -c fc_host -v -d host2 | grep port_name

===============================================

Deletion of a SCSI Device

to remove a SCSI device from the system you can use

echo 1 > /sys/bus/scsi/drivers/sd/<SCSI-ID>/delete.

Note: To add the device back, simply rescan the whole SCSI bus. Adding the device will change the device names - i.e. by deleting /dev/sde and readding it using the scsi bus rescan it will become dev/sdf

Rescan of a SCSI Device

The problem of a SCSI bus rescan is, that it will only detect new devices. To rescan existing device which might be switched on, use the command

echo 1 > /sys/bus/scsi/drivers/sd/<SCSI-ID>/block/device/rescan

For example

cd /sys/bus/scsi/drivers/sd/0:0:1:0/block/device

# echo 1 > rescan

# tail -f /var/log/messages

...

As you will see the rescan has told the kernel that the device is up and running.

===================================================

How to scan new FC LUNS and SCSI disks in Linux ?

Overview:

While Working on the Linux boxes , some times linux admin have to scan new storage or LUNs assign to the server from the Storage team. In Redhat linux & CentOS we can scan the LUNs either using the script β€˜rescan-scsi-bus.sh’ or using the β€˜/sys/class’ files without rebooting the server.

In My scenario I have 4 FC (Fiber Channel) ports on the server , and new Luns are assigned on these ports. Follow the below steps to detect or scan new Luns :

Method:1

First Check the Fibre channels using the below Command :

# ls /sys/class/fc_host

host0 host1 host2 host3

Now Scan New luns using below Commands:

# echo "1" > /sys/class/fc_host/host0/issue_lip

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "1" > /sys/class/fc_host/host1/issue_lip

# echo "- - -" > /sys/class/scsi_host/host1/scan

# echo "1" > /sys/class/fc_host/host2/issue_lip

# echo "- - -" > /sys/class/scsi_host/host2/scan

# echo "1" > /sys/class/fc_host/host3/issue_lip

# echo "- - -" > /sys/class/scsi_host/host3/scan

Method:2

The sg3_utils package provides the rescan-scsi-bus.sh script, this script scans new luns on redhat linux and CentOS. So to use this script first we have to install sg3_utils rpm.

# yum install sg3_utils

# ./rescan-scsi-bus.sh

Now the Check the newly discovered disks using β€˜fdisk -l’ command or by β€˜multipath -l’ command if configured.

NOTE: The three values stand for channel, SCSI target ID, and LUN. The dashes act as wildcards meaning "rescan everything"

OR

Scanning FC-LUN’s in Redhat Linux

1.First find out how many disks are visible in β€œfdisk -l” .

# fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l

2.Find out how many host bus adapter configured in the Linux box.you can use β€œsystool -fc_host -v” to verify available FC in the system.

#ls /sys/class/fc_host

host3 host4

In this case,you need to scan host3 & host4 HBA.

3.If the system virtual memory is too low ,then do not proceed further.If you have enough free virtual memory,then you can proceed with below command to scan new LUNS.

# echo "1" > /sys/class/fc_host/host3/issue_lip

# echo "1" > /sys/class/fc_host/host4/issue_lip

Note: You need to monitor the β€œissue_lip” in /var/log/messages to determine when the scan will complete.This operation is an asynchronous operation.

4.Verify if the new LUN is visible or not by counting the available disks.

# fdisk -l 2>/dev/null | egrep '^Disk' | egrep -v 'dm-' | wc -l

If any new LUNS added ,then you can see more count is more then before scanning the LUNS.

Scanning SCSI DISKS in Redhat Linux

1.Finding the existing disk from fdisk.

[root@mylinz1 ~]# fdisk -l |egrep '^Disk' |egrep -v 'dm-'

Disk /dev/sda: 21.5 GB, 21474836480 bytes

2.Find out how many SCSI controller configured.

[root@mylinz1 ~]# ls /sys/class/scsi_host/host

host0 host1 host2

In this case,you need to scan host0,host1 & host2.

3.Scan the SCSI disks using below command.

[root@mylinz1 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@mylinz1 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan

[root@mylinz1 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

4.Verify if the new disks are visible or not.

[root@mylinz1 ~]# fdisk -l |egrep '^Disk' |egrep -v 'dm-'

Disk /dev/sda: 21.5 GB, 21474836480 bytes

Disk /dev/sdb: 1073 MB, 1073741824 bytes

Disk /dev/sdc: 1073 MB, 1073741824 bytes

==========================

Discovering new storage volumes on a Linux host

Posted on 31st August 2015

OK, so we’ve managed to connect to an iSCSI target, or have created our FC zones so we can communicate with our storage platform (or both). Wonderful.

But wait, how do we actually get Linux to see the storage volumes that we create and present to our host? This article will show a couple of methods of identifying new/recently added storage resources on our Linux host (CentOS is being used in this example).

Generally speaking, Linux does a good job of automatically detecting changes on the SCSI disk bus and by querying dmesg we can spot recently added disks (volumes on the storage device; disks on the host server), but there are situations where we need to issue a rescan of storage adapters to properly baseline a system. For example, if we are running Linux as a VM.

The most complete method is quite simply:

# shutdown -r now or # reboot

This means udev will recompile the hardware abstraction layer (HAL) and detect all available storage resources (assuming we have iscsid set to automatically start on boot, of course). It is not, however, the most convenient or practical method we have available, as the server & its services will be unreachable until fully booted. Alas, as Linux is an enterprise OS there are other methods of achieving the desired result which keep the server online for the duration:

Rescanning host adapters:

# echo β€œ1” > /sys/class/scsi_host/host?/scan

The β€˜?’ depicts the specific host adapter that we are looking to rescan. It’s quite feasible that multiple host entries will exist within /sys/class/scsi_host/, and it may not be abundantly clear which is the host we need to rescan to discover new devices. There aren’t many downsides in rescanning all host entries, so we could look at doing the following:

# ls /sys/class/scsi_host

This will return something along the lines of:

Listing a system's scsi host adapters

We can then take the smallest (e.g. 0) & largest (e.g. 10) host number, or the individual host numbers, and put them into a for loop. But first, it’s worth capturing the state of dmesg to allow us to compare before & after, so:

# dmesg | tail -200 > /tmp/dmesg_before_rescan

Then, our loop could look something like this:

# for q in {0..10}; do echo β€œ1” > /sys/class/scsi_host/host$q/scan; done

This loop tells Linux to cycle every number between 0 and 10 (the β€˜..’ is the depicter here, if using individual numbers we would change the syntax to: # for q in {0,3,4,6,9,10}; <command>) and perform the command listed afterwards. When Linux gets to the maximum number (10), it will stop.

Now the rescan is complete, let’s capture dmesg and we can compare the differences:

# dmesg | tail -200 > /tmp/dmesg_after_rescan

We can see that we now have some newly added disks available on our SCSI bus:

Using the rescan-scsi-bus.sh script:

This script can be found in the sg3_utils package, and is particularly useful for adding devices. There are a multitude of options available to pass to the script, too – check the options available by running:

# /usr/bin/rescan-scsi-bus.sh –help

To execute the script (/usr/bin should be in $PATH, so you could omit the full path and just invoke):

# rescan-scsi-bus.sh

Recanning the iSCSI session(s):

Occasionally we may make changes on an iSCSI storage platform that require us to rescan the session. A good example of this is increasing the size of an existing storage volume – there are no additions/removals, it’s merely a case that the parameters have changed, and Linux wouldn’t naturally be aware of this so we’ll have to explicitly highlight it.

# iscsiadm -m session -r <session_ID> -R

And in practice:

# iscsiadm -m session

discovering_storage_volumes_linux04

# iscsiadm -m session -r 3 -R

===========================

Question 1: What will happen if we issue the below command ?

# echo "1" > /sys/class/fc_host/host/issue_lip

Answer :

This operation performs a Loop Initialization Protocol (LIP) and then scans the interconnect and causes the SCSI layer to be updated to reflect the devices currently on the bus. A LIP is, essentially, a bus reset, and will cause device addition and removal. This procedure is necessary to configure a new SCSI target on a Fibre Channel interconnect. Bear in mind that issue_lip is an asynchronous operation.

The command may complete before the entire scan has completed. You must monitor /var/log/messages to determine when it is done. The lpfc and qla2xxx drivers support issue_lip

Question2 :

What will happen if we issue the below command ? what does "- - -" mean in the command?

# echo "- - -" > /sys/class/scsi_host/host0/scan

Answer:

It means that you are echoing a wildcard value of "channel target and lun", and the operating system will rescan the device path.

==================================================================

Hot-plugin scan/rescan scsi

What is h c t l

1

2

3

4

5

6

7

8

9

h == hostadapter id (first one being 0)

c == SCSI channel on hostadapter (first one being 0)

t == ID (target)

l == LUN (first one being 0)

# lsscsi man page

Generic SCSI devices can also be accessed via the bsg driver in Linux. By default, the bsg driver's device node names are of the form

'/dev/bsg/H:C:T:L'. So, for example, the SCSI device shown by this utility on a line starting with the tuple '6:0:1:2' could be accessed

via the bsg driver with the '/dev/bsg/6:0:1:2' device node name.

Add the scsi device

1

2

echo "- - -" > /sys/class/scsi_host/host<h>/scan

echo "c t l" > /sys/class/scsi_host/host<h>/scan

Refresh the scsi device

1

2

echo 1 > /sys/block/sdau/device/rescan

echo 1 > /sys/class/scsi_device/h:c:t:l/device/rescan

Remove the scsi device

1

2

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

echo 1 > /sys/block/<dev>/device/delete

==============================

Rescan of Disk

But when we login on machine and try for those disk. i found there were no disk on machine. So I used below command for rescan disk.

echo "- - -" > /sys/class/scsi_host/host1/scan

we need to check β€œ/sys/class/scsi_host/host” directory that need to rescan, in our case host2 need to rescan, below output for same.

# echo "- - -" > /sys/class/scsi_host/host

host0/ host1/ host2/

# echo "- - -" > /sys/class/scsi_host/host0/scan

ata1: soft resetting link

ata1: EH complete

# echo "- - -" > /sys/class/scsi_host/host1/scan

ata2: soft resetting link

ata2: EH complete

# echo "- - -" > /sys/class/scsi_host/host2/scan

scsi 2:0:0:0: Direct-Access QEMU QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5

scsi target2:0:0: tagged command queuing enabled, command queue depth 16.

scsi target2:0:0: Beginning Domain Validation

scsi target2:0:0: Domain Validation skipping write tests

scsi target2:0:0: Ending Domain Validation

scsi 2:0:1:0: Direct-Access QEMU QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5

scsi target2:0:1: tagged command queuing enabled, command queue depth 16.

scsi target2:0:1: Beginning Domain Validation

scsi target2:0:1: Domain Validation skipping write tests

scsi target2:0:1: Ending Domain Validation

scsi 2:0:2:0: Direct-Access QEMU QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5

scsi target2:0:2: tagged command queuing enabled, command queue depth 16.

scsi target2:0:2: Beginning Domain Validation

scsi target2:0:2: Domain Validation skipping write tests

scsi target2:0:2: Ending Domain Validation

sd 2:0:0:0: [sda] 4194304 512-byte logical blocks: (2.14 GB/2.00 GiB)

sd 2:0:1:0: [sdb] 4194304 512-byte logical blocks: (2.14 GB/2.00 GiB)

sd 2:0:0:0: [sda] Write Protect is off

sd 2:0:1:0: [sdb] Write Protect is off

sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

sd 2:0:2:0: [sdc] 4194304 512-byte logical blocks: (2.14 GB/2.00 GiB)

sd 2:0:1:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

sd 2:0:2:0: [sdc] Write Protect is off

sda:

sdb: unknown partition table

unknown partition table

sd 2:0:2:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

sd 2:0:1:0: [sdb] Attached SCSI disk

sd 2:0:0:0: [sda] Attached SCSI disk

sdc: unknown partition table

sd 2:0:2:0: [sdc] Attached SCSI disk

sd 2:0:0:0: Attached scsi generic sg0 type 0

sd 2:0:1:0: Attached scsi generic sg1 type 0

sd 2:0:2:0: Attached scsi generic sg2 type 0

=====================================

n the below path you can find a list of host symlinks pointing to the iscsi device configured on your Linux box

# ls -l /sys/class/scsi_host/

total 0

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host10 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host10/scsi_host/host10

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host3 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host3/scsi_host/host3

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host4 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host4/scsi_host/host4

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host5 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host5/scsi_host/host5

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host6 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host6/scsi_host/host6

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host7 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host7/scsi_host/host7

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host8 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host8/scsi_host/host8

lrwxrwxrwx 1 root root 0 Jun 14 05:08 host9 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host9/scsi_host/host9

But to detect a new hard drive attached you need to first get your host bus number used which you can get by using below command

# grep mpt /sys/class/scsi_host/host?/proc_name

You should get a output like below

/sys/class/scsi_host/host2/proc_name:mptspi

So as you see your host2 is the relevant fiels where you need to reset the storage buffer values. Run the below command

# echo "- - -" > /sys/class/scsi_host/host2/scan

Here "- - -" defines the three values stored inside host*/scan i.e. channel number, SCSI target ID, and LUN values. We are simply replacing the values with wild cards so that it can detect new changes attached to the Linux box. This procedure will add LUNs, but not remove them.

Once done verify if you can see the new hard drive which in my case worked very fine as I see below

# fdisk -l

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

===============================

How to scan new FC LUNS and SCSI disks in Redhat Linux without rebooting the server? Most of the Linux beginners have wondering how to do this and this article will be for them.It may look like very simple as we perform this in daily operation to scan luns but system has many work to do in background when you execute storage scanning commands. Redhat says this type of scan can be distributive,since it can cause delays while I/O operation timeout and remove devices unexpectedly from OS.So perform this scan when really you want to scan the disks and LUNS.

Scanning FC-LUN’s in Redhat Linux

1.First find out how many disks are visible in β€œfdisk -l” .

# fdisk -l 2>/dev/null | egrep β€˜^Disk’ | egrep -v β€˜dm-β€˜ | wc -l

2.Find out how many host bus adapter configured in the Linux box.you can use β€œsystool -fc_host -v” to verify available FC in the system.

# ls /sys/class/fc_host

host0 host1

In this case,you need to scan host0 & host1 HBA.

3.If the system virtual memory is too low ,then do not proceed further.If you have enough free virtual memory,then you can proceed with below command to scan new LUNS.

# echo β€œ1” > /sys/class/fc_host/host0/issue_lip

# echo β€œ1” > /sys/class/fc_host/host1/issue_lip

Note: You need to monitor the β€œissue_lip” in /var/log/messages to determine when the scan will complete.This operation is an asynchronous operation.

4.Verify if the new LUN is visible or not by counting the available disks.

# fdisk -l 2>/dev/null | egrep β€˜^Disk’ | egrep -v β€˜dm-β€˜ | wc -l

If any new LUNS added ,then you can see more count is more then before scanning the LUNS.

Scanning SCSI DISKS in Redhat Linux

1.Finding the existing disk from fdisk.

[root@mylinz1 ~]# fdisk -l |egrep β€˜^Disk’ |egrep -v β€˜dm-β€˜

Disk /dev/sda: 21.5 GB, 21474836480 bytes

2.Find out how many SCSI controller configured.

[root@mylinz1 ~]# ls /sys/class/scsi_host/host

host0 host1 host2

In this case,you need to scan host0,host1 & host2.

3.Scan the SCSI disks using below command.

[root@mylinz1 ~]# echo β€œ- – -” > /sys/class/scsi_host/host0/scan

[root@mylinz1 ~]# echo β€œ- – -” > /sys/class/scsi_host/host1/scan

[root@mylinz1 ~]# echo β€œ- – -” > /sys/class/scsi_host/host2/scan

4.Verify if the new disks are visible or not.

[root@mylinz1 ~]# fdisk -l |egrep β€˜^Disk’ |egrep -v β€˜dm-β€˜

Disk /dev/sda: 21.5 GB, 21474836480 bytes

Disk /dev/sdb: 1073 MB, 1073741824 bytes

Disk /dev/sdc: 1073 MB, 1073741824 bytes

From Redhat Linux 5.4 onwards, redhat introduced ”/usr/bin/rescan-scsi-bus.sh” script to scan all the SCSI bus and update the SCSI layer to reflect new devices.

But most of the time,script will not be able to scan new disks and you need go with echo command.

What does the echo β€œ1” to the issue_lip file do? – SCAN SCSI in Linux?

Question 1: What will happen if we issue the below command ?

# echo β€œ1” > /sys/class/fc_host/host/issue_lip

Answer :

This operation performs a Loop Initialization Protocol (LIP) and then scans the interconnect and causes the SCSI layer to be updated to reflect the devices currently on the bus. A LIP is, essentially, a bus reset, and will cause device addition and removal. This procedure is necessary to configure a new SCSI target on a Fibre Channel interconnect. Bear in mind that issue_lip is an asynchronous operation.

The command may complete before the entire scan has completed. You must monitor /var/log/messages to determine when it is done. The lpfc and qla2xxx drivers support issue_lip

Question2 :

What will happen if we issue the below command ? what does β€œ- – -” mean in the command?

# echo β€œ- – -” > /sys/class/scsi_host/host0/scan

Answer:

It means that you are echoing a wildcard value of β€œchannel target and lun”, and the operating system will rescan the device path.

===================================================

You are in front of a Linux box, a VM really, with a bunch of new disks that must be configured and suddenly you remember that there is no ioscan in Linux, you will ask yourself, who is so stupid to create an operative system without ioscan?

Yes it is true, there is no ioscan in Linux and that means that every time you add a new disk to one of your virtual machine you have to reboot it, at least technically that is the truth. But don’t worry there is a quick and dirty way to circumvent that.

From a root shell execute the following command:

[root@redhat ~]# echo "- - -" > /sys/class/scsi_host/<host_number>/scan

After that if you do a fdsik -l will see the new disks.

If you want to rescan your box for new fiber channel disks the command is slightly different.

[root@redhat ~# echo "1" > /sys/class/fc_host/host#/issue_lip

For the fiber channel part there are also third party utilities. HP for example provides hp_rescan which comes with the Proliant Support Pack.

[root@redhat /]# hp_rescan -h

hp_rescan: rescans LUNs on HP supported FC adapters

Usage: hp_rescan -ailh[n]

-a: rescan all adapters

-i: rescan a specific adapter instance. The specific device should be a

SCSI host number such as "0" or "6"

-l: lists all FC adapters

-n: do not perform "scsi remove-single-device" when executing probe-luns

-h: help

[root@redhat /]#

If you know other ways to rescan the SCSI bus in a Linux server please comment.

=========================================

Sometimes a software/hardware error will lock your SATA device/controller. You may just reboot your OS and wish for the best, but you may also only reset the affected device, not the full system, bellow is how you can achieve this.

Before you apply the following commands make sure you are not using the SATA/SCSI devices (ex. mounted filesystem, part of a RAID, LVM, BTRFS or ZFS volume). If the device is still in use please take action to stop it before you delete the device node or reset the SATA bus.

A device name of /dev/sdb is assumed.

Find out which controller the device is attached to (we’ll need this later):

# readlink /sys/block/sdb/device

../../../1:0:0:0

The interesting part if the answer is host1, which identifies the controller.

Disconnect the device

# echo 1 > /sys/block/sdb/device/delete

This will remove the device from the bus (logically). Look in dmesg for confirmation.

Rescan the controller

# echo "- - -" > /sys/class/scsi_host/host1/scan

host1 is the identifier from step one. Again, dmesg should show the device being rediscovered.

===========================

It is possible to add or remove a SCSI device explicitly, or to re-scan an entire SCSI bus without rebooting a running Linux VM guest.

1) Add a New Disk To Vm Guest

First, you need to add hard disk by visiting vmware hardware settings menu.

Click on VM > Settings

Alternatively you can press CTRL + D to bring settings dialog box.

Click on Add+ to add new hardware to guest:

Select hardware type Hard disk and click on Next

Select create a new virtual disk and click on Next

Set virtual disk type to SCSI and click on Next

Set maximum disk size as per your requirements and click on Next

Finally, set file location and click on Finish.

2) Rescan the SCSI Bus to Add a SCSI Device Without rebooting the VM

A rescan can be issued by typing the following command:

echo "- - -" > /sys/class/scsi_host/host#/scan

fdisk -l

tail -f /var/log/message

Replace host# with actual value such as host0. You can find scsi_host value using the following command:

# ls /sys/class/scsi_host

Output:

host0

Now type the following to send a rescan request:

echo "- - -" > /sys/class/scsi_host/host0/scan

fdisk -l

tail -f /var/log/message

3) Format a New Disk

You can create partition using fdisk and format it using mkfs.ext3 command:

# fdisk /dev/sdc

# mkfs.ext3 /dev/sdc3

4) Create a Mount Point And Update /etc/fstab

# mkdir /disk3

Open /etc/fstab file, enter:

# vi /etc/fstab

Append as follows:

/dev/sdc3 /disk3 ext3 defaults 1 2

Save and close the file.

Last updated

Was this helpful?