Scanning Linux hosts for newly added ESX storage devices

I currently support a number of Linux hosts that run inside VMWare vSphere server. Periodically I need to add new storage devices to these hosts, which requires me to login to the vSphere client and add the device through the “edit settings” selection. The cool thing about vSphere is that the LUNs are dynamically added to the guest, and the guest will see the devices once the SCSI bus has been scanned. There are several ways to scan for storage devices, but the simplest way I’ve found is to use the rescan-scsi-bus.sh shell script that comes with the sg3_utils package.

To use rescan-scsi-bus.sh, you will first need to install the sg3_utils package:

$ yum install sg3_utils

Once installed, you can run fdisk or lsscsi to view the devices on your system:

$ lsscsi

[0:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sda
[1:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sdb

$ fdisk -l

Disk /dev/sda: 9663 MB, 9663676416 bytes
255 heads, 63 sectors/track, 1174 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         651     5229126   83  Linux
/dev/sda2             652        1173     4192965   82  Linux swap / Solaris

Disk /dev/sdb: 19.3 GB, 19327352832 bytes
255 heads, 63 sectors/track, 2349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2349    18868311   83  Linux

As you can see above, we currently have two physical devices connected to the system. To scan for a new device I just added, we can run rescan-scsi-bus.sh from the host:

$ /usr/bin/rescan-scsi-bus.sh -r

Host adapter 0 (mptspi) found.
Host adapter 1 (mptspi) found.
Scanning SCSI subsystem for new devices
 and remove devices that have disappeared
Scanning host 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning for device 0 0 0 0 ...
OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0 
      Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning host 1 channels  0 for  SCSI target IDs  0 1 2 3 4 5 6 7, all LUNs
Scanning for device 1 0 0 0 ...
OLD: Host: scsi1 Channel: 00 Id: 00 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0 
      Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 1 0 1 0 ...
NEW: Host: scsi1 Channel: 00 Id: 01 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0 
      Type:   Direct-Access                    ANSI SCSI revision: 02
Scanning for device 1 0 1 0 ...
OLD: Host: scsi1 Channel: 00 Id: 01 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0 
      Type:   Direct-Access                    ANSI SCSI revision: 02
0 new device(s) found.               
0 device(s) removed.                 

The scan output will show you the devices it finds, and as you can see above, it was able to locate 3 “Virtual disk” drives. To verify the machine sees the drives, we can run lsscsi and fdisk again:

$ lsscsi

[0:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sda
[1:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sdb
[1:0:1:0]    disk    VMware   Virtual disk     1.0   /dev/sdc

$ fdisk -l

Disk /dev/sda: 9663 MB, 9663676416 bytes
255 heads, 63 sectors/track, 1174 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         651     5229126   83  Linux
/dev/sda2             652        1173     4192965   82  Linux swap / Solaris

Disk /dev/sdb: 19.3 GB, 19327352832 bytes
255 heads, 63 sectors/track, 2349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2349    18868311   83  Linux

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

There are various solutions to check for new SCSI devices (Emulex has a tool, QLogic has a tool, you can scan for devices by hand, etc.), the rescan script has proven to be the easiest solution for me. Since I didn’t write the rescan script, use this information at your own risk. It *should* work flawlessly, but you’re on your own when you run it!

4 thoughts on “Scanning Linux hosts for newly added ESX storage devices”

  1. Thanks Matty!

    I skim-read this blog entry when it was posted, but today have had the need to dynamically add a disk to a Linux VM.

    Your blog has proven very useful for us today!

    Cheers

    JR

  2. Interestingly sg3_utils on FC doesnt contain rescan-scsi-bus.sh e.g.

    #rpm -ql sg3_utils-1.23-1.fc7 | grep -i rescan

    -Alex

Leave a Reply

Your email address will not be published. Required fields are marked *