≡ Menu

Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest

As a system admin, I need to use additional hard drives for to provide more storage space or to separate system data from user data. This procedure, adding physical block devices to virtualized guests, describes how to add a hard drive on the host to a virtualized guest using VMWare software running Linux as guest.

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. This how to is tested under Vmware Server and Vmware Workstation v6.0 (but should work with older version too). All instructions are tested on RHEL, Fedora, CentOS and Ubuntu Linux guest / hosts operating systems.

Step # 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

Fig.01: Vmware Virtual Machine Settings

Fig.01: Vmware Virtual Machine Settings

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

Click on Add+ to add new hardware to guest:

Fig.02: VMWare adding a new hardware

Fig.02: VMWare adding a new hardware

Select hardware type Hard disk and click on Next

Fig.03 VMware Adding a new disk wizard

Fig.03 VMware Adding a new disk wizard

Select create a new virtual disk and click on Next

Fig.04: Vmware Wizard Disk

Fig.04: Vmware Wizard Disk

Set virtual disk type to SCSI and click on Next

Fig.05: Vmware Virtual Disk

Fig.05: Vmware Virtual Disk

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

Fig.06: Finalizing Disk Virtual Addition

Fig.06: Finalizing Disk Virtual Addition

Finally, set file location and click on Finish.

Step # 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

Sample outputs:

Linux Vmware Rescan New Scsi Disk Without Reboot

Fig.01:Linux Vmware Rescan New Scsi Disk Without Reboot


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

Sample Outputs:

Jul 18 16:29:39 localhost kernel:   Vendor: VMware,   Model: VMware Virtual S  Rev: 1.0
Jul 18 16:29:39 localhost kernel:   Type:   Direct-Access                      ANSI SCSI revision: 02
Jul 18 16:29:39 localhost kernel:  target0:0:1: Beginning Domain Validation
Jul 18 16:29:39 localhost kernel:  target0:0:1: Domain Validation skipping write tests
Jul 18 16:29:39 localhost kernel:  target0:0:1: Ending Domain Validation
Jul 18 16:29:39 localhost kernel:  target0:0:1: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel:  sdb: unknown partition table
Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi disk sdb
Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi generic sg1 type 0
Jul 18 16:29:39 localhost kernel:   Vendor: VMware,   Model: VMware Virtual S  Rev: 1.0
Jul 18 16:29:39 localhost kernel:   Type:   Direct-Access                      ANSI SCSI revision: 02
Jul 18 16:29:39 localhost kernel:  target0:0:2: Beginning Domain Validation
Jul 18 16:29:39 localhost kernel:  target0:0:2: Domain Validation skipping write tests
Jul 18 16:29:39 localhost kernel:  target0:0:2: Ending Domain Validation
Jul 18 16:29:39 localhost kernel:  target0:0:2: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB)
Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off
Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable
Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through
Jul 18 16:29:39 localhost kernel:  sdc: unknown partition table
Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi disk sdc
Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi generic sg2 type 0

How Do I Delete a Single Device Called /dev/sdc?

In addition to re-scanning the entire bus, a specific device can be added or existing device deleted using the following command:
# echo 1 > /sys/block/devName/device/delete
# echo 1 > /sys/block/sdc/device/delete

How Do I Add a Single Device Called /dev/sdc?

To add a single device explicitly, use the following syntax:

# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi

Where,

  • <H> : Host
  • <B> : Bus (Channel)
  • <T> : Target (Id)
  • <L> : LUN numbers

For e.g. add /dev/sdc with host # 0, bus # 0, target # 2, and LUN # 0, enter:
# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
# fdisk -l
# cat /proc/scsi/scsi

Sample Outputs:

Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02

Step #3: Format a New Disk

Now, you can create partition using fdisk and format it using mkfs.ext3 command:
# fdisk /dev/sdc
# mkfs.ext3 /dev/sdc3

Step #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.

Optional Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backupDisk, enter
# e2label /dev/sdc1 /backupDisk

Conclusion

The VMware guest now has an additional virtualized storage device. The procedure works for all physical block devices, this includes CD-ROM, DVD and floppy devices. Next, time I will write about adding an additional virtualized storage device using XEN software.

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 43 comments… add one }

  • Bram-NL July 18, 2009, 12:29 pm

    To add a single device explicitly, use the following syntax:
    # echo "scsi add-single-device &lgt;H> " > /proc/scsi/scsi

    I guess “&lgt” should be “<" (<)

  • nixCraft July 18, 2009, 12:44 pm

    @Bram-NL,

    Thanks for the heads-up!

  • jok July 18, 2009, 8:30 pm

    Very nice, thanks!

    Oh, and in Step #3, i guess, it should be:
    mkfs.ext3 /dev/sdc3
    (not mkfs.exr3).

  • ashwani July 19, 2009, 3:44 pm

    Thanks for very nice info
    can u please explain what it means “- – -” ??

  • nixCraft July 19, 2009, 7:59 pm

    @jok,

    Thanks for pointing out a typo.

    @ashwani,

    It is syntax for rescanning and nothing else.

  • hillel July 20, 2009, 2:24 pm

    With VMware and SAN storage devices it is possible to change the disk size. In windows rescan disks updates the new size. The only way I found to notify the OS (linux)that the disk geometry was changed is by rebooting. Is it possible to do this online?

    • David van Laatum December 21, 2011, 3:23 am

      Exchange scan with rescan
      I usually use
      find /sys/ -name rescan -exec sh -c ‘echo 1 1 1 > {}’ \;

  • michaelvino July 22, 2009, 10:31 am

    hi vivek
    Ur updates are really useful for me …I am Fresher now i m using rhel5.0 i forgot the steps to create the repositery can u help me…. In my home i didn’t have internet i used a system as a client i copied all the dvd contents into /var/ftp/pub/Server please help me …

  • Andy August 11, 2009, 9:27 am

    Nice job! I’m sure this will save my bacon one day.

  • trentlaceysunxxp August 20, 2009, 6:31 pm

    I really liked it. But not bad, it would be to add a few important sections.

  • antonio August 21, 2009, 10:26 pm

    Very nice… saved my bacon! and my friday afternoon. Now I can go get some “real work” done… (ha!) and maybe even go home for dinner, instead of chasing IT people here.

  • Erik August 31, 2009, 9:03 pm

    Awesome, thanks.

  • qubex October 24, 2009, 3:10 pm

    Very nice article!
    I have a similar situation and this worked quite well.

    One question though.
    When you have a situation like described above, with /dev/sda1, /dev/sdb1 and /dev/sdc1; what happens when you detach /dev/sdb1, so only /dev/hda1 and /dev/hdc1 are left?
    I’ve experienced earlier that Linux has a way with reshuffeling its device-names after reboot. So I think you can expect /dev/sdc might change to /dev/sdb?

    Thanks, Q

  • Low351 October 29, 2009, 2:04 pm

    Thank you, this information helped me.

  • radiodog December 4, 2009, 1:52 am

    Oh. Hi! :-) He stood there motionless and in wonder, dimly conscious that Brenson was speaking to him, but not catching the meaning of his words. Never mind that. Impossible!.
    Gonna be back soon :-)

  • Tiago Ferreira December 18, 2009, 3:11 pm

    Very very useful.

    Nonetheless, /sbin/partprobe is not necessary/recommended?

    cheers

    TF

  • brautkleiderIvy January 10, 2010, 3:05 am

    Hello from Zuerich,
    i just want to say that i like your website very much.
    I will come back soon.

    Yours Ivy

  • arumon February 2, 2010, 12:05 pm

    Really Good :-)
    Thanks a lot !!!

    Rgds,
    Arumon

  • Jimbo March 18, 2010, 11:39 am

    very cool to ‘hot-add’ virtual disks. Thanks for the info.

  • Seb March 24, 2010, 4:07 pm

    Thanks !

  • Lakshmipathi August 4, 2010, 7:10 am

    Thanks,useful one.I like the rescan part!

  • msawawa September 20, 2010, 9:16 am

    the rescan part doesnt seem to work on SuSE 10 Enterprise Linux SP3

    • somnath January 25, 2011, 9:28 pm

      The rescan does not work with RHEL 5 guest VMs when existing virtual disks are resized. It only recognizes the changed size after reboot. Is there any way this can be done online ?

  • Shane Miller February 3, 2011, 5:26 pm

    I am using cat /etc/*release
    SUSE Linux Enterprise Server 10 (x86_64)
    VERSION = 10
    PATCHLEVEL = 3
    LSB_VERSION=”core-2.0-noarch:core-3.0-noarch:core-2.0-x86_64:core-3.0-x86_64″

    This rescan works like a champ for me.

  • Heherson Tan March 19, 2011, 12:15 pm

    I’m using Centos 5.5. I can’t find it in /dev/

    ls /dev/sdd
    ls: /dev/sdd: No such file or directory

    but dmesg shows the new drive

    SCSI device sdd: 33554432 512-byte hdwr sectors (17180 MB)
    sdd: Write Protect is off
    sdd: Mode Sense: 5d 00 00 00
    sdd: cache data unavailable
    sdd: assuming drive cache: write through
    sdd: unknown partition table
    sd 0:0:3:0: Attached scsi disk sdd
    sd 0:0:3:0: Attached scsi generic sg3 type 0

  • fsnikkijamesa2 June 16, 2011, 8:26 pm

    Awesome web-site yours sincerely, Pauletta Mencia

  • Suresh September 14, 2011, 4:32 pm

    Excellent Work. Thanks a lot.

  • Wallander November 22, 2011, 10:15 am

    Excellent post. Worked like a charm.

    Always Appreciated nixcraft blogs.

    Keep the great work going.

  • Shaik December 10, 2011, 3:27 am

    Nice article. Thanks for the steps.

  • Shery January 17, 2012, 7:16 am

    Great!.
    Like your articles..
    Always a direct hit!

  • Bubba April 13, 2012, 4:55 pm

    Thanks a million!! This was very helpful.

  • Ashok June 7, 2012, 12:46 am

    thanks for your valuable stuff buddy

  • james September 7, 2012, 10:42 am

    very useful and straight forward method for scaning new disks .

  • RAMS February 7, 2013, 11:05 am

    Very useful stuff..

  • Rajesh July 4, 2013, 9:30 am

    Great article, i was looking for this details. Well, explained.keep coming….

  • okon August 28, 2013, 9:39 pm

    thanks a lot.

  • joe December 20, 2013, 11:47 am

    Pretty cool!

    Any directions for doing this on RHEL 6.5 on a VMWare(ext4)? Or would it be the same.

    Thanks

  • Kuldeep Kulkarni April 20, 2014, 9:06 pm

    Guyz,

    If you are facing problem in step number 2 then here is the solution :

    First find your host bus number

    grep mpt /sys/class/scsi_host/hostX/proc_name

    Which should return a line like

    /sys/class/scsi_host/hostX/proc_name:mptspi

    where hostX is the relevant field.

    use this to rescan the bus with the following command

    echo “- – -” > /sys/class/scsi_host/hostX/scan

  • Alex May 29, 2014, 1:06 pm

    You’re aways saving me!! Thanks a lot!!!

  • ser tr June 20, 2014, 8:26 am

    great! thanks a lot :)

  • Robert Sander October 14, 2014, 4:46 am

    rescan-scsi-bus.sh exists since 10 years for thus purpose.

  • Jon April 13, 2015, 10:08 pm

    It doesn’t hurt anything to rescan all the drives.

    echo “- – -” | tee /sys/class/scsi_host/*/scan

    All the rest of the information is good.

  • Ivor Horton April 23, 2015, 2:01 pm

    Could you explain the commands and not only type them?
    For example, for the following commands:
    echo “- – -” > /sys/class/scsi_host/host0/scan

    What does it really do? Can we change “- – -” to anything else like “test…” etc.? What if I have many “host#”? Which one should I use? In my system I have 34 this kind of things.

    Thanks.

Leave a Comment