Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest

by on July 18, 2009 · 40 comments· LAST UPDATED August 4, 2010

in , ,

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.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 40 comments… read them below or add one }

1 Bram-NL July 18, 2009 at 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 “<" (<)

Reply

2 nixCraft July 18, 2009 at 12:44 pm

@Bram-NL,

Thanks for the heads-up!

Reply

3 jok July 18, 2009 at 8:30 pm

Very nice, thanks!

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

Reply

4 ashwani July 19, 2009 at 3:44 pm

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

Reply

5 nixCraft July 19, 2009 at 7:59 pm

@jok,

Thanks for pointing out a typo.

@ashwani,

It is syntax for rescanning and nothing else.

Reply

6 hillel July 20, 2009 at 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?

Reply

7 David van Laatum December 21, 2011 at 3:23 am

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

Reply

8 michaelvino July 22, 2009 at 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 …

Reply

9 Andy August 11, 2009 at 9:27 am

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

Reply

10 trentlaceysunxxp August 20, 2009 at 6:31 pm

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

Reply

11 antonio August 21, 2009 at 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.

Reply

12 Erik August 31, 2009 at 9:03 pm

Awesome, thanks.

Reply

13 qubex October 24, 2009 at 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

Reply

14 Low351 October 29, 2009 at 2:04 pm

Thank you, this information helped me.

Reply

15 radiodog December 4, 2009 at 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 :-)

Reply

16 Tiago Ferreira December 18, 2009 at 3:11 pm

Very very useful.

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

cheers

TF

Reply

17 brautkleiderIvy January 10, 2010 at 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

Reply

18 arumon February 2, 2010 at 12:05 pm

Really Good :-)
Thanks a lot !!!

Rgds,
Arumon

Reply

19 Jimbo March 18, 2010 at 11:39 am

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

Reply

20 Seb March 24, 2010 at 4:07 pm

Thanks !

Reply

21 Lakshmipathi August 4, 2010 at 7:10 am

Thanks,useful one.I like the rescan part!

Reply

22 msawawa September 20, 2010 at 9:16 am

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

Reply

23 somnath January 25, 2011 at 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 ?

Reply

24 Shane Miller February 3, 2011 at 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.

Reply

25 Heherson Tan March 19, 2011 at 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

Reply

26 fsnikkijamesa2 June 16, 2011 at 8:26 pm

Awesome web-site yours sincerely, Pauletta Mencia

Reply

27 Suresh September 14, 2011 at 4:32 pm

Excellent Work. Thanks a lot.

Reply

28 Wallander November 22, 2011 at 10:15 am

Excellent post. Worked like a charm.

Always Appreciated nixcraft blogs.

Keep the great work going.

Reply

29 Shaik December 10, 2011 at 3:27 am

Nice article. Thanks for the steps.

Reply

30 Shery January 17, 2012 at 7:16 am

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

Reply

31 Bubba April 13, 2012 at 4:55 pm

Thanks a million!! This was very helpful.

Reply

32 Ashok June 7, 2012 at 12:46 am

thanks for your valuable stuff buddy

Reply

33 james September 7, 2012 at 10:42 am

very useful and straight forward method for scaning new disks .

Reply

34 RAMS February 7, 2013 at 11:05 am

Very useful stuff..

Reply

35 Rajesh July 4, 2013 at 9:30 am

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

Reply

36 okon August 28, 2013 at 9:39 pm

thanks a lot.

Reply

37 joe December 20, 2013 at 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

Reply

38 Kuldeep Kulkarni April 20, 2014 at 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

Reply

39 Alex May 29, 2014 at 1:06 pm

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

Reply

40 ser tr June 20, 2014 at 8:26 am

great! thanks a lot :)

Reply

Leave a Comment

Tagged as: , , , , , , , , , , ,

Previous post:

Next post: