kvm virtual machine usage
I have successfully installed KVM virtual machine for a very long time, but I did not do some actual jobs on it yet.
Today I am started to do some developing jobs towards Hadoop eco-system, which needs virtual machines for a better and clean workspace.
create VM
Operate according to this doc, which is already detailed to fully create a KVM machine. I rewrite the build-vm script for creating VM.
During the installation, I encountered some problems. I just wanna share them online.
Notice that --dest
is the parameter that VM file will be stored, you need to create the folder name yourself, or KVM will have error stack at the final stage! killing time.
If you found it rather slow to initially create a VM, this might caused by the slow network between you and source provider, in my experiment, I use 163 as source provider, be aware of this connection speed between you and source server.
After fetching bin files from source server, maybe it will have a error that shows Could not found libvirt
, whenever this happens, please startup libvirt
by:sudo service libvirt start
After a around 15 mins, the automatical installation procedure already finished and it will deploy to the folder that you specified in build-vm
script.
clone VM
It also very simple and easy to clone a VM rather than recreate a VM from network again!
For more details, please refer to clone> virt-clone --connect=qemu:///system -o oldVM -n newVM -f /home/rugal/VM/new/NewVM.gcow2
step into VM
Now its time to startup our VM, how exciting!
Use list
command:
1 |
|
Use start
to startup VM named master
> virsh --connect qemu:///system start master
After installation, the first thing you might to do is use SSH to connect into VM, but actually you do not know about the DHCP allocated IP adress, here I found a method to get IP for your new created VM.
First use virsh
command to find out MAC address of your VM.
1 |
|
Then use ARP scan to determine the allocated IP.
1 |
|
Now just try on this with ssh 192.168.122.50
1 |
|
Wow it works!
close VM
It also very easy to do the reverse action to shutdown VM, just as command below:> virsh --connect qemu:///system shutdown master
drop VM
I wrote a script to delete a VM in one command, you will find it rather easy!