Reese Knowledgebase

Add disk without rebooting

View Kristian Reese's profile on LinkedIn


If you like this article, please +1 or Recommend via FB with the provided buttons above:

Article ID: 2
by: Reese K.
Posted: 11 Apr, 2011
Last updated: 25 Sep, 2014
Views: 7815

How To Add Disk to Linux System without Rebooting

It is possible to add a new hard disk without a reboot.  Whether or not it is a physical server where a physical disk was inserted into an available slot, or a new virtual disk was added to a VMware VM, the command structure to discover the new disk is the same.

First, take a look at the existing scsi devices using the lsscsi command:

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

After adding a new vmdk or a new physical disk, /dev/sdc should pop in after running through the following sequence of commands in order to make the operating system aware of the new storage device. 


The recommended command to do this, as per redhat documentation, is:

echo "c t l" > /sys/class/scsi_host/hosth/scan

From the lsscsi output above, this would translate into:

echo "0 2 0" > /sys/class/scsi_host/host0/scan

where host 0, channel 0, SCSI target ID 2, and LUN 0 are the next in-line / appropriate values:

The deprecated method was to submit a scsi command to /proc/scsi/scsi as follows, but does still work:

echo "scsi add-single-device 0 0 2 0" > /proc/scsi/scsi

If that's not a comfortable option, then a rescan of the entire scsi bus for additional disks can be performed.  Some systems have more than one scsi_host.  With one command, they can all be rescanned as follows:

for host in $(ls -1d /sys/class/scsi_host/*); do echo "- - -" > ${host}/scan ; done

To rescan them individually, perform an ls in /sys/class/scsi_host and scan each one via a single command where # is the host number:

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

Note that in some distros of Linux, the kernel may recognize the new device once it has been added to the system, and the bus scan may not need to be performed.  This would be validated by observing the output of lssci or by looking in syslog (/var/log/messages) for any indication of a newly added device.  Something like the following would show up in the logs:

sd 0:0:2:0: Attached scsi disk sdc

This matches up nicely with lsscsi output:

~# lsscsi
[0:0:0:0]    disk    VMware   Virtual disk     1.0   /dev/sda
[0:0:1:0]    disk    VMware   Virtual disk     1.0   /dev/sdb
[0:0:2:0]    disk    VMware   Virtual disk     1.0   /dev/sdc

Next, the new device can be partitioned, labeled, create a file system, and mounted.

echo -e -n "o\nn\np\n1\n\n\nw\n" | fdisk /dev/sdc > /dev/null 2>&1
mkfs.ext3 /dev/sdc1
mkdir /data
e2label /dev/sdc1 /data
vi /etc/fstab
mount -a


On the flip side of the coin, a device may be deleted using the following command:

# echo 1 > /sys/block/devName/device/delete (where devName is the device name to be removed, for example sdc in the following line)
# echo 1 > /sys/block/sdc/device/delete


Another variation of this operation is echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete
A deprecated method of the above command is:
# echo "scsi remove-single-device 0 0 2 0" > /proc/scsi/scsi

This article was:   Helpful | Not Helpful
Prev   Next
UNIX     System hangs during messagebus startup

RSS