In our previous lesson, we created a very minimal virtual machine.
It didn't have any virtual disk attached so it couldn't host an operating system.
Now,
it served well for our demonstrating purposes as
we learned how to manage it with the BSH
command.
But now let's do something more interesting to
see some real world scenarios as well.
We'll look at how to create a more complete
virtual machine with an operating system running inside.
This will give us a chance to see the real
thing in action and learn about some additional commands.
Now, the first thing we need to do is download a disk image
now on
Ubuntu site, they have a listing here of an
Ubuntu operating system preconfigured to be used in a cloud environment.
These are the cloud images, for example,
Google cloud uses these similar images when we spin
up a virtual private server on their platform.
So we're going to download this minimal cloud image with WGET
OK. And our image is finished downloading.
Now,
what we want to do is we want to check to make
sure that this image wasn't corrupted during the download process or modified
to do that we have what's called a checksum process
on the
Ubuntu page.
We have a couple of files here. SHA 256 sums
and ss A 256 sums dot GP G.
Now the first file here
contains check sums for all of the images.
And we use this GPG file to check all of the
images that are in the folder of these two files.
And I'll show you how to do that.
We'll copy the link here and we'll wget this file.
So now that we have these two files here,
we can run this simple command to check that image file that's in this folder.
What this will do is look at every image in
the folder and you want to see this OK message.
If anything else pops up,
you need to redownload that image because there was some kind of problem with it.
But here we can see the images exactly as it needs to be. So we're ready to go.
Now, we can also inspect this image with the KU
utility.
For example,
if we run KU
dash image info,
we can see the information for this image.
What's interesting to note here is the virtual size of 3.5 gigabytes.
When we attach this image to a virtual machine, it will serve as the virtual disk
and virtual size tells us that this disk is
configured to have a total size of 3.5 gigabytes.
In most cases that won't be enough.
We'll want to install additional software on our virtual machine.
So we'll need a larger disk to expand the
size of this virtual disk to approximately 10 gigabytes.
We can run this command and it shows that the image is resized
if we check the info again. Now we can see that we have a 10 gig drive. Perfect.
Now,
our virtualization tools will need to access what's
called a storage pool in this pool,
it will store disk images, snapshots and other data.
Now by default, it will use the slash bar slash live slash live Burt directory.
For this additional storage pools can be created if you desire.
Let's follow a simple path and just use the default location.
Now, if we take a look at
VRLI
live
bet
we can see this images subdirectory here.
So let's copy our disc image file to that subdirectory.
And now we get to a pretty complex task.
What command should we use to create a virtual machine and
tell it to use this image file as a virtual disk.
Well, for this purpose, we can use the Burt dash install utility.
However,
this utility supports hundreds of combinations of command-line options.
So it can be quite confusing to figure out the options that we need for each purpose.
Let's see how we can kind of orient ourselves as total beginners.
Well, you can start by just typing in the command.
Now, even though it'll throw an error,
it will help us discover the first options that we need.
The output tells us that the vert install needs to know what
kind of operating system we intend to use in our virtual machine.
It even then gives us an example of a command that
we can use to list what operating systems are supported.
So let's run that command,
scroll up here
and we can see that the one that we want to install Ubuntu
24.4 Ubuntu Noble is available here. We'll need to use Ubuntu
24.04 as a parameter in our future Vert install command.
So let's get some extra help by looking at the manual.
We'll type in man
Vert dash install.
We'll notice that this example here seems to be the most relevant for our scenario.
It shows us how to create a virtual machine based on an existing disk image.
Now, unfortunately, it's a very minimal example.
We'll need more command-line options to get to our desired result.
However, note that the dash dash import option is what we'll need to use.
And that's quite important for our purpose here,
but it can be easily missed if we're not aware about what it does.
Why do we need this dash dash import option?
Well, let's see what the manual says.
We can hit the question mark
and type dash dash import
and press enter
and we press n a few times
until we find the information that we need.
Here we go
with dash dash import,
we skip the OS installation process and build a guest around an existing disk image.
The device used for booting is the first device specified via dash dash
disk or dash dash file system.
We can see that this option tells our utility to skip the OS installation process.
That's because normally Vert install will try to install
an operating system on top of a disk image.
That's why it's called Burt dash install.
So it's default mode of operation is to do that with the dash dash import option,
we can tell it to skip that step.
Our disk image already has the
Ubuntu operating system preinstalled.
Also,
we can see that this option tells bird install to set our
image as the device used for booting in this virtual machine.
Now let's exit the manual and see another trick we
can use to find the options that we need.
We can type in Vert dash install, dash dash help.
Now we can start to cherry pick the options we need.
Now, if we scroll up, we can see the first three that interest us
name memory and BC P us with these,
we can set the name of our virtual machine so we can easily identify it later.
Then we can set the memory to be allocated in this machine in megabytes.
1024 megabytes is equivalent to one gigabyte.
Finally with dash dash VCP us,
we pick how many virtual CPU CORS we want to allocate to the virtual machine.
Now let's scroll down.
The next option we care about is dash dash
disk to provide the path to our virtual disk.
In this case,
the path to our image file note that
we can provide multiple parameters for this option.
In the example, we can see dash dash
disk,
the location of the disk comma cache equals none.
This line specifies the path to the disk but also disables cache.
For our scenario, we'll have to provide the path to the disk.
The next option is dash dash graphics with dash dash graphics. None.
We'll tell our virtual machine that we don't have
a graphical user interface available on our system.
Now let me make a quick note for the next commands we'll use in this demonstration.
First, we'll type invert dash install
then
OS info
and we're going to use
Ubuntu
24.04 that we found in that previous help file for the name.
We're going to call this Ubuntu one
for memory. We're going to use a gig
vcpus,
we're going to use one
and then were going to import
disk
and we're going to put the full path to our image file that we used earlier.
And then we're going to say graphics
none. Now with OS info, we'll set the operating system type to
Aunon 2 22.04
and this is equivalent to the OS variant option.
But O SS info is easier to remember and type.
And then with the name, we set it to
21
we assigned 1024 megabytes of memory.
Then we assign one virtual CPU.
After that, we'll tell our utility that we're importing the disk image.
So it should skip all installation steps.
Everything is already preinstalled on the image.
Then we provide the path to the disk image it should use.
And finally,
we specify that the host system does not have a graphical interface available.
Now, let's run it and see what happens.
And we're automatically connected to the text console of the virtual machine.
It's as if we plugged in a monitor and keyboard to it.
So we can see the output that it displays and we can start
interacting with it if we wouldn't have specified the option dash dash graphical.
None. This wouldn't have happened.
That's why this option is so important in a text only environment.
Now, we can type in a username and interact with the virtual machine
we can't log in since we don't know the password.
However, the machine is fully booted up.
Now, the problem is how do we exit from this virtual machine?
Well, if we scroll all the way back up,
we can see this line
to exit from the console of a virtual machine,
we have to press control plus the closing square bracket
and that combination will be hard to remember.
So after you run a Vert install command,
look for this output before the virtual machine
starts up and fills your screen with output,
it will serve as a quick reminder.
So let's press control, closing bracket and exit
the message domain creation completed, tells us that everything went fine,
at least with the virtual machine creation part and booting up,
but we don't know the root password.
So let's fix this now, we can list all of our virtual machines that are available.
And we can see here that we have Ubuntu one running.
Let's shut it down
and we'll give it a few seconds and we'll see if it's successfully powered off
and it did
if for some reason, it would refuse to shut down. We can also force a power
off with BSH
destroy
Ubuntu one as we learned in our previous lesson.
Now, in our case, it's in a shutoff state so we can remove it from our system.
So now we've completely deleted the virtual machine and we removed all storage,
which means that we removed that image file that we copied earlier.
So let's go ahead and copy that back.
Now, let's recreate this virtual machine. But this time with a twist,
since this Ubuntu
disk image is created for the cloud, it has some automation scripts.
These are included in a collection of tools called cloud dash
and kit.
And some of these scripts can help us set a
root password if we pass the required data to them.
So let's do that.
We'll reuse our old command, but we'll add in a new option at the end.
Now here type in
cloud
init
root dash password
generate
on
by writing in
cloud
init root
password
generate equals on here. We pass instructions to cloud
init to generate a random password for the root user.
Now, before we press enter a quick note,
the random root password will be displayed for 10 seconds.
We should be ready to select and copy that password text from our screen.
Before the virtual machine starts outputting its boot data,
we can copy it afterwards as well, but you have to scroll up a lot. So now it's present
and we will copy this root password
and as we can see the installation is starting.
Ok. Now we're at the login prompt and we don't have any errors with anything.
So we're ready to go.
So we'll type in root
and then we'll paste in that password
note that nothing will be displayed at the password prompt when we paste it in.
Now, we're forced to reenter our password to change it.
So we'll paste in the previous one again.
And then at the new password prompt, we'll pick a new one that we want
and you'll have to confirm it.
All right. We're in after that, we've successfully logged into the
AUD
two operating system running in our virtual machine.
Now, let's look at the sizes of our virtual disks with DF dash H.
Notice how our virtual disk comes preallocated with around 10 gigabytes.
The size we picked when we resize it with the key
U dash image command.
And if we type in apt update,
we'll see that we even have internet connectivity on this virtual machine.
Even though we didn't specify any networking parameters.
Vert install will pick many reasonable defaults for us.
Now, we can log out with this command
and disconnect from the virtual machine console
with control and closing bracket.
In a running virtual machine, we can always reattach to the console with the BSH
console command followed by the name of the machine,
but this won't show us previous output. So we won't see the login prompt
to force the virtual machine to output that login prompt again.
A trick we can use is simply press enter here and we'll get the login prompt.
Now, let's disconnect from the console with control closing bracket
and we'll wrap up our lesson with some alternate commands.
Now, another important thing to note is that in some cases,
you can't be sure about the operating system type included in a virtual disk image.
In other cases, the operating system can be newer than what Vert
install supports. For example, Vert
install won't know about
Ubuntu 26.04. If this operating system was launched yesterday,
it will take a while for the tool to be updated with new information.
And in such cases, you have a few options available. We can type in Vert dash
install
to get a quick reminder of these alternate options.
Now, if we're not sure about the operating system instead of that dash dash OS info,
Ubuntu
24.4 parameter, we can type in OS info
detect equals on here
and Vert install will try to auto detect it based on what it can find in the image.
Alternatively,
if we have a fair idea that this is a Linux
distribution that appeared after the year 2022 we can type in
OS info,
Linux 2022.
And of course, we should remove the cloud and knit option if we don't need it,
we only use that with images that were built specifically for the cloud
that include those cloud and knit utilities
and that wraps up our lesson. Let's jump ahead to the next one.