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
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
Select hardware type Hard disk and click on Next
Fig.03 VMware Adding a new disk wizard
Select create a new virtual disk and click on Next
Fig.04: Vmware Wizard Disk
Set virtual disk type to SCSI and click on Next
Fig.05: Vmware Virtual Disk
Set maximum disk size as per your requirements and click on Next
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:
Fig.01:Linux Vmware Rescan New Scsi Disk Without Reboot
# 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
### [if you want ext3 fs] ###
# mkfs.ext3 /dev/sdc3
### [if you want ext4 fs] ###
# mkfs.ext4 /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
For ext4 fs:
/dev/sdc3 /disk3 ext4 defaults 1 2
Save and close the file.
Optional Task: Label the partition
You can label the partition using e2label command. For example, if you want to label the new partition /backupDisk, enter
# e2label /dev/sdc1 /backupDisk
See “The importance of Linux partitions
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 51 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
My Man, you’re the best!
Thanks sir, it solved my problem.
# 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????
Thanks this soloved my problem.
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.
The three values stand for channel, SCSI target ID, and LUN. The dashes act as wildcards meaning “rescan everything”
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
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.
rescan-scsi-bus.sh exists since 10 years for thus purpose.
great! thanks a lot 🙂
You’re aways saving me!! Thanks a lot!!!
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
Pretty cool!
Any directions for doing this on RHEL 6.5 on a VMWare(ext4)? Or would it be the same.
Thanks
thanks a lot.
Great article, i was looking for this details. Well, explained.keep coming….
Very useful stuff..
very useful and straight forward method for scaning new disks .
thanks for your valuable stuff buddy
Thanks a million!! This was very helpful.
Great!.
Like your articles..
Always a direct hit!
Nice article. Thanks for the steps.
Excellent post. Worked like a charm.
Always Appreciated nixcraft blogs.
Keep the great work going.
Excellent Work. Thanks a lot.
Awesome web-site yours sincerely, Pauletta Mencia
I’m using Centos 5.5. I can’t find it in /dev/
but dmesg shows the new drive
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.
the rescan part doesnt seem to work on SuSE 10 Enterprise Linux SP3
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 ?
Thanks,useful one.I like the rescan part!
Thanks !
very cool to ‘hot-add’ virtual disks. Thanks for the info.
Really Good 🙂
Thanks a lot !!!
Rgds,
Arumon
Hello from Zuerich,
i just want to say that i like your website very much.
I will come back soon.
Yours Ivy
Very very useful.
Nonetheless, /sbin/partprobe is not necessary/recommended?
cheers
TF
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 🙂
Thank you, this information helped me.
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
Awesome, thanks.
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.
I really liked it. But not bad, it would be to add a few important sections.
Nice job! I’m sure this will save my bacon one day.
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 …
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?
Exchange scan with rescan
I usually use
find /sys/ -name rescan -exec sh -c ‘echo 1 1 1 > {}’ ;
@jok,
Thanks for pointing out a typo.
@ashwani,
It is syntax for rescanning and nothing else.
Thanks for very nice info
can u please explain what it means “- – -” ??
– – – = wild cards for Channel ID, SCI target ID and LUV
Very nice, thanks!
Oh, and in Step #3, i guess, it should be:
mkfs.ext3 /dev/sdc3
(not mkfs.exr3).
may be mkfs -t ext4 /dev/sdc3
@Bram-NL,
Thanks for the heads-up!
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 “<" (<)