VMware – add scsi virtual disk on a running Linux VM without rebooting
Posted by danielFeb 4
How to add a disk to a running VM
This tutorial will show you how to make Vmware autodetect a new virtual disk in a running Linux VM without rebooting it.
1. Start by adding the SCSI virtual disk –
In my case I am using VMware workstation and following this link to add the disk. Use the steps relevant for your system, it shouldn’t be that difficult.
2. Status of the disk on the VM –
By running fdisk on my Linux VM, I can see that it has two disks attached – /dev/sda and /dev/sdb – both having the same size of 107.4GB. The later is an LVM partition, which I can resize on the fly.
[root@lincenvma ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00061f7f Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 549 4096000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 549 13055 100453376 83 Linux Disk /dev/sdb: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00ea04d0 Device Boot Start End Blocks Id System /dev/sdb1 1 3265 26226081 8e Linux LVM Disk /dev/mapper/vg_target00-lv_target00: 10.7 GB, 10737418240 bytes 64 heads, 32 sectors/track, 10240 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x153067d3 Device Boot Start End Blocks Id System /dev/mapper/vg_target00-lv_target00p1 2 2049 2097152 83 Linux [root@lincenvma ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 [root@lincenvma ~]# ls /sys/class/scsi_host/ host0 host1 host2
Apparently after adding the disk, the VM didn’t automatically detect the disk, that takes us to the next step of re-scanning the disks.
3. Rescan Scsi bus –
This is where we run the trigger command, to scan the SCSI bus for everything – channel number, SCSI target ID, and LUN values. Check the /var/log/dmesg log file or run dmesg command in another window to see the action live –
[root@lincenvma ~]# echo "- - -" > /sys/class/scsi_host/host2/scan [root@lincenvma ~]# dmesg sd 2:0:2:0: [sdc] Write Protect is off sd 2:0:2:0: [sdc] Mode Sense: 61 00 00 00 sd 2:0:2:0: [sdc] Cache data unavailable sd 2:0:2:0: [sdc] Assuming drive cache: write through sd 2:0:2:0: [sdc] Cache data unavailable sd 2:0:2:0: [sdc] Assuming drive cache: write through sdc: unknown partition table sd 2:0:2:0: [sdc] Cache data unavailable sd 2:0:2:0: [sdc] Assuming drive cache: write through sd 2:0:2:0: [sdc] Attached SCSI disk [root@lincenvma ~]# tail -f /var/log/messages Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] 2097152 512-byte logical blocks: (1.07 GB/1.00 GiB) Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Write Protect is off Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Cache data unavailable Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Assuming drive cache: write through Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Cache data unavailable Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Assuming drive cache: write through Mar 15 01:02:11 lincenvma kernel: sdc: unknown partition table Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Cache data unavailable Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Assuming drive cache: write through Mar 15 01:02:11 lincenvma kernel: sd 2:0:2:0: [sdc] Attached SCSI disk
We can see that the system detected the new disk and identified it as /dev/sdc.
In RHEL/CentOS 5.4 or above, the script /usr/bin/rescan-scsi-bus.sh will have the same effect.
4. Validate –
At the bottom, fdisk shows the new disk as /dev/sdc with size 1073 MB –
[root@lincenvma ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdc [root@lincenvma ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00061f7f Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 549 4096000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 549 13055 100453376 83 Linux Disk /dev/sdb: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00ea04d0 Device Boot Start End Blocks Id System /dev/sdb1 1 3265 26226081 8e Linux LVM Disk /dev/mapper/vg_target00-lv_target00: 10.7 GB, 10737418240 bytes 64 heads, 32 sectors/track, 10240 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x153067d3 Device Boot Start End Blocks Id System /dev/mapper/vg_target00-lv_target00p1 2 2049 2097152 83 Linux Disk /dev/sdc: 1073 MB, 1073741824 bytes 255 heads, 63 sectors/track, 130 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
From here, you can partition the disk and mount it directly or create a PV and merge it with the existing LVM to increase the size of the LVM.
References –
http://serverfault.com/questions/490397/what-does-in-echo-sys-class-scsi-host-host0-scan-mean
https://www.vmware.com/support/ws5/doc/ws_disk_add_virtual.html
12 comments
You must be logged in to post a comment.