In software, we can create a virtual computer on our real computer.
These simulated computers are called virtual machines and
they can be very useful on servers.
Here's an example,
imagine we have a powerful server with 64 CPU cores and 1024 gig of RA M.
If we create 32 virtual machines,
each one would have two virtual CP US which are also called VCP US and 32 gigs of RA M
now instead of renting one big physical server to just one client,
we can rent our smaller virtual servers to 32 clients.
That's what cloud compute companies like
DigitalOcean Amazon web services and Google
Cloud use to sell some of their services to thousands of clients.
There are many software solutions out there to create this kind of setup.
But in Linux, the most popular at the moment is key emu dash KVM.
These are actually two pieces of software that interconnect.
The name key
U comes from quick emulator.
This emulates or simulates a virtual computer
KVM comes from kernel based virtual machine.
This is code included in the Linux kernel that
uses hardware technology meant to speed up virtual machines.
Essen will focus on a tool called Vers or V IRS H.
This is a program that lets us manage virtual machines from the command-line.
Now, if you've ever used VirtualBox, you use the graphical interface,
clicking buttons to create a virtual machine,
um configuring it, starting it and so on. VH
just does all of these things through commands rather than a graphical interface
to quickly get started.
We can install the Vert manager software package with this command
pseudo
apt install Vert dash manager.
Normally Vert manager is meant for Linux
machines that include a graphical user interface,
but we can also install it on a Linux machine that only has a text user interface.
We won't need the Vert manager application itself.
However, by installing it,
the package manager will pull in a lot of other dependency packages which include
utilities that help us in the lessons that we have about virtual machines.
Now, let's continue with our demo.
We'll create this configuration file
type in Vim test machine dot XML
and we're going to add in this content.
This will help us create a virtual
machine called test machine and it's virtualized through
KMU with one gig of ram one virtual CPU and a 64 bed architecture.
Now H VM stands for hardware virtual machine.
Now, of course, this is a hacky example.
So we can just kind of speed through this process.
A real virtual machine also needs storage,
network cards and operating system and so on.
Now, to create this virtual machine, we'll pass in the definition file to verse
and we'll type in verse, define test machine dot XML.
Now we can dig deeper into this command. First of all, verse has a very nice help page.
As you can see by typing in VERS help.
It's quite a lot of content, but commands are nicely grouped together.
And if we scroll up, we'll see domain management. In
this category, we have most of the commands we're interested in
a domain basically refers to a virtual machine.
So the commands in here can be used to interact with them.
But first, we'll need to see the domains that we have.
Hmm no sign of what we defined earlier.
That's because only active domains are shown.
The one we defined is not active yet
to see all domains, even in active ones, we can use this command
and we'll add dash dash all to the end of it.
We can see our domain virtual machine called test machine
and we can see that it's currently shut off.
We can start it with this command
verse start test machine.
Now, if the name of the machine contains spaces, wrap it in double quotes.
And now we can see it in verse list
and to reboot it type in verse reboot test machine.
This sends a reboot signal to the operating system running the virtual machine.
So the reboot should be graceful processes should be closed.
Normally, applications should have a chance to save their data, things like that.
It's just like restarting a real computer.
But if a machine is not responding and it's frozen up for some reason,
we can force reset it.
Now,
this is just like pressing the physical reset button
or unplugging the power cord and plugging it back in
now to shut down a virtual machine. Normally we type in verse shutdown test machine.
This sends a shutdown signal to the operating system inside the virtual machine.
So just like rebooting,
this should do a graceful shutdown and give applications
enough time to close normally and save their data.
Now remember that our simple virtual machine here has no operating system.
So this won't work as expected but it will work
normally in a real setup with an operating system.
Now, if a virtual machine is stuck, we can force a hard power off with verse
destroy test machine.
Most verse commands are pretty intuitive, but this one's an Exception.
It sounds like we're actually destroying or deleting the machine.
But that's not the case.
This command is the equivalent of unplugging the power from
your home computer and not powering it back on afterwards.
And we can confirm this with verse
list dash dash all
to actually delete a domain or virtual machine.
We have to power it off and then use a command like this BSH
undefined test machine.
But let's not use this yet.
The command above deletes the virtual computer we defined but not the data stored.
For example, it's virtual disks
and we usually want to keep the data.
But let's say that this time we want to remove that too.
Now, we can explore advanced use cases for each command with verse
help and then the name of the command.
In our case, we'll type in verse help undefined.
And we see that this would delete all data associated with the domain.
So let's run this.
And now we can confirm that everything is now gone.
Now let's recreate our machine and explore some other things.
When we start up our real server,
the virtual machines on it have to be manually started.
If we want a virtual machine to start up
automatically every time the real machine the server boots,
then we could type in verse
autostart test machine.
If we want our virtual machine to not autostart, when the server boots,
then we would type in verse
autostart dash dash disable test machine
to explore the virtual resources assigned to a virtual machine.
We use Dominfo which is short for domain info,
just one CPU core. Let's say we want to bump this up and make it a little more powerful.
We want to assign two CPU cores. Instead
we'll need some help on this one.
So we'll start by typing in verse set.
And let's imagine we forgot the correct command.
We can press tab a couple of times to get some suggestions.
And now we remember the correct command verse set VCP us.
Now remember this is set VCP us with an S at the end, not set VCPU.
But how do we actually use it?
We'll type in verse help set VCP us.
And we can see the syntax here.
Set BP us, domain count, followed by a dash dash long option.
And we'll use dash dash config option that sets the number of VCP us to two.
The next time the machine will boot.
So let's run this command
verse set VCP us test machine two dash dash config
and it seems that the maximum is set to one. So let's change that with this command
ver set BC P US test machine two
config dash dash maximum.
Now this sets the maximum CP US allowed for this virtual machine to two cores
to actually assign two virtual cores. We'll run this again.
Now remember this does not change VCP us while the virtual machine is running.
So we have to power it off
now to force the power off.
In our case, since we have no operating system in there,
we'll just type in verse destroy test machine
and then we'll start it again for the changes to become active.
And if we check our domain info,
we see that it worked.
Now to change the memory size, we first changed the maximum to 2048 megabytes.
Then we set the memory allocation to 2048 megabytes.
And then we shut down the machine gracefully
or force power off. If we need to. In our case,
then we'll start it back up again.
And domain info will show our changes took effect.
Awesome. Right.
And that concludes this lesson on creating and managing virtual machines.