I recently showed this to a colleague who is new to Linux. It should be part of your minimum capabilities as an admin. Manipulating disks/volumes on a guest VM is a task we all have to do.
In this post I’m going to detail how to add a new disk to an Ubuntu VM, online. Call it a “back to basics” post.
First add another Hard-Disk to the guest as required. This will add a disk @ XX size, store it with the Guest VM files and it will be in persistent mode.
1 |
get-vm VM | New-HardDisk -CapacityGB XX -Persistence persistent |
Logon to the guest and issue the lshw -C disk command to filter the list hardware output by disk;
As you can see, the new disk (16GB) does not show up, and will not until a scsci bus rescan is executed. The lazy way here would be to reboot, at which time a host rescan is done anyway.
A better way, is to force a scsi rescan. First, let’s determine which scsi host is in use
1 |
grep mpt /sys/class/scsi_host/host?/proc_name |
in this case it’s host2
1 |
sudo echo "- - -" > /sys/class/scsi_host/host2/scan |
oh noes, permission denied, even through I sudo’d !
If you examine the syntax, this is because although I used sudo, it is dropped after the “>”. the correct way is to run the echo through a pipeline then tee through.
1 |
sudo echo "- - -" | sudo tee /sys/class/scsi_host/host2/scan |
the return to stdout is “- – -“. So what is this actually doing ?
The 3 “-” are acting as wildcards to represent the “Channel, SCSI ID and LUN” id’s available on a scsi host. So effectively “Scan all the things now!”
You could execute this against all the hosts by substituting the host id with a ? like this;
1 |
sudo echo "- - -" | sudo tee /sys/class/scsi_host/host?/scan |
On a Red hat EL system (5.4 +) there is an included script /usr/bin/rescan-scsi-bus.sh which will achieve the same result.
From the host console, you should see a device discovery message; (or you could tail /var/log/dmesg )
running the list hardware command again should now show the new Disk device;
fdisk sees it also, so we’re ready to partition and create the filesystem.
fidsk to partition
make the filesystem (format)
create label and manually mount
finally add to fstab so it automounts at boot time.
Next task will be to extend the partition, live. Coming soon.
Job done. Party on.
Hi Sir,
I have 500 gb add on Vcenter. Now I need to do scan scsi and resize my partition on VM. But i am having this “—” what does it mean? what should I have to do?
Is there anyway to scan disk.
#sudo echo “- – -” | sudo tee /sys/class/scsi_host/host2/scan
– – –
your help would highly appreciated.
Thanks
Moon
Hi, make sure you are running the scan against the correct scsi host on your system.
execute “grep mpt /sys/class/scsi_host/host?/proc_name” to return the correct host id, then use it inthe scan syntax. The ” – – – ” are wildcards for the channel, scsi id and LUN id’s that are returned from the bus scan.
Hi Sir,
I have 500 gb add on Vcenter. Now I need to do scan scsi and resize my partition on VM. But i am having this “—” what does it mean? what should I have to do?
Is there anyway to scan disk.
#sudo echo “- – -” | sudo tee /sys/class/scsi_host/host2/scan
– – –
your help would highly appreciated.
Thanks
Moon