Back to basics – Hot add new disk to Linux VM

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.

 

 

pragmaticio.com/2015/04/back-to-basics-hot-add-new-disk-to-linux-vm/