Linux detect new device

Add or Detect New Hard Disk Online Without Rebooting

As a system admin, We may come into a situation to Add a New Disk or Detect New Hard Disk Online to provide more space for the application installed.

If you are interested in learning, Request you to go through the below recommended tutorial.

How to detect new hard disk online without rebooting?

This post will help you with How to rescan or detect new hard disk online without rebooting the server.

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.

How to Rescan newly added Disk on Linux?

1. Ensure the required size is added newly online without shutting down or powered off in Hypervisors such as vmware esx, vmware workstation and Microsoft Hyper-V before carrying out the Virtual Disk increasing activity.

2. Login into the server with user root or any other user with root privilege.

3. Run the below command to list the detected disk as below screenshot shows..

Add or Detect a New Hard Disk Online Without Rebooting

The above screenshot shows as our linux machine has only single disk of 10GB (/dev/sda).

4. Run the below command to list the entire SCSI device buses,

[root@server1 ~]# ll /sys/class/scsi_host/host?/scan
—w——-. 1 root root 4096 May 11 16:03 /sys/class/scsi_host/host0/scan
—w——-. 1 root root 4096 May 11 15:58 /sys/class/scsi_host/host1/scan
—w——-. 1 root root 4096 May 11 15:58 /sys/class/scsi_host/host2/scan

Above command listed the output of number of SCSI device buses, we have to run each below command for each SCSI device buses.


[root@server1 ~]# echo «- — -» > /sys/class/scsi_host/host0/scan
[root@server1 ~]# echo «- — -» > /sys/class/scsi_host/host1/scan
[root@server1 ~]# echo «- — -» > /sys/class/scsi_host/host2/scan

Источник

Читайте также:  Meson linux что это

How to detect new hard disk attached without rebooting in Linux

Here suppose you have added a new hard disk to your Linux OS running on any Virtual Environment which in my case is VMware workstation. Once added the new hard drive, generally the changes won’t reflect unless you reboot the Guest OS.
But what if you are in no position to reboot the Guest Linux OS?

Solution

In 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 fields 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

Let me know your success and failures.

Читайте также:  Управление аудитом astra linux

15 thoughts on “How to detect new hard disk attached without rebooting in Linux”

Hello Prasad,
Quick tip:
A better way to identify new disks is using the rescan-scsi-bus.sh script.
You can install it with by ‘yum install sg3_utils’.
Some options you’ll want to use are: -c or -cr.
By the way, your ‘Configure Red Hat Cluster using VMware, Quorum Disk, GFS2, Openfiler’ is really good. Congrats and keep the good tutorials. Reply

great, it was what i was looking for
work on sles 11 sp3. ( over vmware)
in messages log you can see the adition. Reply

Источник

Оцените статью
Adblock
detector