Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest

Posted on in Categories CentOS, fedora linux, Hardware, Howto, Linux, Linux desktop, Linux distribution, Linux Virtualization, RedHat/Fedora Linux, Storage, Sys admin, Tips, vmware last updated July 18, 2009

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

50 comment

  1. 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 “<" (<)

  2. Very nice, thanks!

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

  3. 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?

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

  4. 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 …

  5. 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.

  6. 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

  7. 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 πŸ™‚

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

    Yours Ivy

    1. 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 ?

  9. 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.

  10. 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

  11. 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

  12. 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.

  13. 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.

    1. The three values stand for channel, SCSI target ID, and LUN. The dashes act as wildcards meaning “rescan everything”

    2. for i in $(echo `find /sys/class/scsi_host -name "host*"`); do echo "- - -" > ${i}/scan; done
      and for FC
      for i in $(echo `find /sys/class/fc_host -name "host*"`); do echo "1" > ${i}/issue_lip/; done

  14. # ls /sys/class/scsi_host
    output shows many hosts like
    host0 host1 host2 host3 host4 .. .. . .. . .. .. . . . ..host25

    So, we can’t scan each and every host. How to know exactly which host we need to scan????

Comments are closed.