Set up a Linux cloud on bare metal | Opensource.com

Set up a Linux cloud on bare metal

Create cloud images with virt-install on Fedora.

Sky with clouds and grass
Image credits : 

Flickr user: theaucitron (CC BY-SA 2.0)

x

Subscribe now

Get the highlights in your inbox every week.

Virtualization is one of the most used technologies. Fedora Linux uses Cloud Base images to create general-purpose virtual machines (VM), but there are many ways to set up Cloud Base images. Recently, the virt-install command-line tool for provisioning VMs added support for cloud-init, so it can now be used to configure and run a cloud image locally.

This article walks through how to set up a base Fedora cloud instance on bare metal. The same steps can be used with any raw or Qcow2 Cloud Base image.

What is --cloud-init?

The virt-install command creates a KVM, Xen, or LXC guest using libvirt. The --cloud-init option uses a local file (called a nocloud datasource) so you don't need a network connection to create an image. The nocloud method derives user data and metadata for the guest from an iso9660 filesystem (an .iso file) during the first boot. When you use this option, virt-install generates a random (and temporary) password for the root user account, provides a serial console so you can log in and change your password, and then disables the --cloud-init option for subsequent boots. 

Set up a Fedora Cloud Base image

First, download a Fedora Cloud Base (for OpenStack) image.

fedoracloud.png

Fedora Cloud website screenshot

(Sumantro Mukherjee, CC BY-SA 4.0)

Then install the virt-install command:

$ sudo dnf install virt-install

Once virt-install is installed and the Fedora Cloud Base image is downloaded, create a small YAML file named cloudinit-user-data.yaml to contain a few configuration lines that virt-install will use.

#cloud-config
password
: 'r00t'
chpasswd
: { expire: false }

This simple cloud-config sets the password for the default fedora user. If you want to use a password that expires, you can set it to expire after logging in.

Create and boot the VM:

$ virt-install --name local-cloud18012709 \
--memory 2000 --noreboot \
--os-variant detect=on,name=fedora-unknown \
--cloud-init user-data="/home/r3zr/cloudinit-user-data.yaml" \
--disk=size=10,backing_store="/home/r3zr/Downloads/Fedora-Cloud-Base-33-1.2.x86_64.qcow2"

In this example, local-cloud18012709 is the name of the virtual machine, RAM is set to 2000MiB, disk size (the virtual hard drive) is set to 10GB, and --cloud-init and backing_store contain the absolute path to the YAML config file you created and the Qcow2 image you downloaded.

Log in

After the image is created, you can log in with the username fedora and the password set in the YAML file (in my example, this is r00t, but you may have used something different). Change your password once you've logged in for the first time.

To power off your virtual machine, execute the sudo poweroff command, or press Ctrl+] on your keyboard.

Start, stop, and kill VMs

The virsh command is used to start, stop, and kill VMs.

To start any VM that is running:

$ virsh start <vm-name>

To stop any running VM:

$ virsh shutdown <vm-name>

To list all VMs that are in a running state:

$ virsh list

To destroy the VMs:

$ virsh destroy <vm-name>

destroyvm.png

Destroying a VM

(Sumantro Mukherjee, CC BY-SA 4.0)

Fast and easy

The virt-install command combined with the --cloud-init option makes it fast and easy to create cloud-ready images without worrying about whether you have a cloud to run them on yet.  Whether you're preparing for a a major deployment or just learning about containers, give virt-install --cloud-init a try.

Do you have a favourite tool for your work in the cloud? Tell us about them in the comments.

What is virtualization

Run, customize, and manage your VMs with open source Virt Tools. Plus get a glossary of key virtualization terms.
A person programming

This easy "hello world" tutorial makes it easy to start using Vagrant for virtual machine management.
Ships at sea on the web

Containers are everywhere, and they've radically changed the IT landscape. What do you need to know about them?

About the author

Sumantro Mukherjee - Hey, open source folks! I am Sumantro, hailing from India (the eastern part - former capital during the British era AKA Kolkata). I love sharing knowledge and writing about technology and experiences (mostly that I try every day). Anything from k8s, ansible to setting up TCMS for make-believe projects is right up my alley. I work as a Software Developer in Test in Fedora Project and contribute to Open Source communities in the form of testing, public speaking, documentation, mentorship, and...