Back to basics – Hot add new disk to Linux VM

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.

22-04-2015 9-40-41 AM

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

11122-04-2015 9-48-21 AM

in this case it’s host2

22-04-2015 9-51-07 AM

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.

22-04-2015 9-58-20 AM

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;

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 )

22-04-2015 10-11-44 AM

running the  list hardware command again should now show the new Disk device;

22-04-2015 10-10-11 AM

fdisk sees it also, so we’re ready to partition and create the filesystem.

22-04-2015 10-27-37 AM

22-04-2015 10-37-34 AM

fidsk to partition

 

 

 

22-04-2015 11-17-41 PM

 

make the filesystem (format)

 

22-04-2015 10-38-07 AM

create label and manually mount

 

 

finally add to fstab so it automounts at boot time.

22-04-2015 10-38-13 AM

 

Next task will be to extend the partition, live. Coming soon.

Job done. Party on.

Related Post

3 thoughts on “Back to basics – Hot add new disk to Linux VM

  1. 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

    1. 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.

  2. 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

Leave a Reply to Brett Sinclair Cancel reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: