Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest

by Vivek Gite on July 18, 2009 · 30 comments

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.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 30 comments… read them below or add one }

1 Bram-NL July 18, 2009

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 Vivek Gite July 18, 2009

@Bram-NL,

Thanks for the heads-up!

Reply

3 jok July 18, 2009

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

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

Reply

5 Vivek Gite July 19, 2009

@jok,

Thanks for pointing out a typo.

@ashwani,

It is syntax for rescanning and nothing else.

Reply

6 hillel July 20, 2009

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

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

Reply

8 michaelvino July 22, 2009

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

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

Reply

10 trentlaceysunxxp August 20, 2009

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

Reply

11 antonio August 21, 2009

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

Awesome, thanks.

Reply

13 qubex October 24, 2009

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

Thank you, this information helped me.

Reply

15 radiodog December 4, 2009

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

Very very useful.

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

cheers

TF

Reply

17 brautkleiderIvy January 10, 2010

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

Really Good :-)
Thanks a lot !!!

Rgds,
Arumon

Reply

19 Jimbo March 18, 2010

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

Reply

20 Seb March 24, 2010

Thanks !

Reply

21 Lakshmipathi August 4, 2010

Thanks,useful one.I like the rescan part!

Reply

22 msawawa September 20, 2010

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

Reply

23 somnath January 25, 2011

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

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

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

Awesome web-site yours sincerely, Pauletta Mencia

Reply

27 Suresh September 14, 2011

Excellent Work. Thanks a lot.

Reply

28 Wallander November 22, 2011

Excellent post. Worked like a charm.

Always Appreciated nixcraft blogs.

Keep the great work going.

Reply

29 Shaik December 10, 2011

Nice article. Thanks for the steps.

Reply

30 Shery January 17, 2012

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 10 + 11 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: