How To Run Fedora CoreOS (FCOS) on VirtualBox

Posted on 86 views

Welcome to this guide on how to run Fedora CoreOS (FCOS) on VirtualBox. Fedora CoreOS is a minimal monolithic automatically updating operating system used to run containerized workloads. This operating system is designed for clusters but can as well operate as a standalone system, optimized for Kubernetes e.t.c

The main goal of the Fedora CoreOS project is to provide the best container host that can run containerized workloads that are secure, highly compatible with existing Container Linux configuration, and scalable. This is achieved by combining the best of Fedora Atomic host and CoreOS Container Linux thus integrating technology such as the Ignition from Container Linux and SELinux hardening from the Atomic project.

There are 3 available Fedora CoreOS update streams i.e testingnext and stable streams. For each stream, there is a canonical URL to represent its current state, normally in JSON format also referred to as the stream metadata.

Fedora CoreOS can be run on VMware, Azure, AWS cloud, Alibaba Cloud, DigitalOcean, IBM Cloud, OpenStack, Vultr, QEMU, Bare Metal, VirtualBox e.t.c

For VMware check the guide How To Run Fedora CoreOS (FCOS) on VMware Workstation

Getting Started.

For this guide, we will run Fedora CoreOS (FCOS) on VirtualBox. Before we begin, ensure that you have VirtualBox installed on your system. You can use one of the dedicated guides below to accomplish this:

Step 1 – Download Fedora CoreOS ISO.

Fedora CoreOS ISO file can be downloaded from the official Fedora CoreOS downloads page. There are 3 release streams, the stable, testing, and next streams, download one that suits your interest.

We recommend using stable channel release:

wget https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/35.20220131.3.0/x86_64/fedora-coreos-35.20220131.3.0-live.x86_64.iso -O fedora-coreos.iso

Step 2 – Create a Fedora CoreOS VM on VirtualBox.

Now we will proceed and create a Virtual Machine for Fedora CoreOS installation. There are two methods to use when creating a VM i.e using GUI or the vboxmanage CLI.

We will proceed and set up a VM using the CLI as below.

Export the VM name and set the VM storage location.

VM_NAME='fcos-node'
VM_DISK=$(realpath ~/VirtualBox\ VMs/$VM_NAME)/$VM_NAME.vdi

Now set the VM OS type, assign memory, CPUs, graphics, and storage controllers as below.

vboxmanage createvm --name "$VM_NAME" --ostype Fedora_64 --register
vboxmanage modifyvm "$VM_NAME" --memory 4096 --cpus 2 --vram 20 --graphicscontroller vmsvga --rtcuseutc on
vboxmanage storagectl "$VM_NAME" --name SATA --add sata --controller IntelAhci --portcount 30 --bootable on

Create a hard disk and set the disk size(In the command 10 GB has been set for the disk size).

vboxmanage createmedium --filename "$VM_DISK" --size 10240 --format VDI
vboxmanage storageattach "$VM_NAME" --storagectl SATA --type hdd --port 0 --device 0 --medium "$VM_DISK"

Modify the port forwarding rules to allow access to the SSH port for the guest. Using the default NAT setting. Assuming you will access SSH on port 2222

vboxmanage modifyvm "$VM_NAME" --natpf1 "guestssh,tcp,,2222,,22"

Step 3 – Produce an Ignition Config.

An ignition file is a JSON file that contains the user and SSH keys that allow you to gain remote access to the system.

Create a config file say example.bu

vim example.bu

In the file add the lines below.

variant: fcos
version: 1.4.0
passwd:
  users:
    - name: core
      ssh_authorized_keys:
        - replace-me-with-public-ssh-key

Remember to replace the replace-me-with-public-ssh-key with your actual SSH public key of your host machine obtained from the following command underssh_authorized_keys.

cat ~/.ssh/id_rsa.pub

Now save the file and proceed to produce a YAML-formatted Butane config. We need to have butane running on our system. I will make this process simple by running butane as a Podman container. Ensure you have Podman/Docker installed on your system. See our guides below:

Pull the butane image

podman pull quay.io/coreos/butane:release

Now generated the example.ign file using butane as below.

podman run --interactive --rm quay.io/coreos/butane:release \
       --pretty --strict < example.bu > example.ign

Now you should have your ignition file example.ign

Step 4 – Install Fedora CoreOS on VirtualBox.

Now that everything has been provisioned, we will proceed and attach the ISO file downloaded for Fedora CoreOS.

FCOS_DISK=$(realpath ~/Downloads/fedora-coreos.iso)
vboxmanage storagectl "$VM_NAME" --name IDE --add ide --controller PIIX4 --hostiocache on --portcount 2 --bootable on
vboxmanage storageattach "$VM_NAME" --storagectl IDE --type dvddrive --port 1 --device 0 --medium "$FCOS_DISK"

Here I assume your ISO file is at ~/Downloads/fedora-coreos.iso

Now you have successfully mounted the ISO file, proceed and start the VM

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox

Boot into FCOS live.

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-1

Now you have access to the terminal

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-2

On your host machine, start the Python3 webserver.

python3 -m http.server

Now from the FCOS VM terminal identify your gateway using the command

route -n

Proceed and pull the example.ign. Here, we are pulling the default Fedora CoreOS box from your route.

curl -LO 10.0.2.2:8000/example.ign

You should now have your ignition file in the VM.

Run the FCOS installer as below.

sudo coreos-installer install /dev/sda --ignition-file example.ign

The installation will proceed as below.

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-3

Once it is complete, shut down the VM.

sudo shutdown -h now

Unmount the Fedora CoreOS ISO file on the VM, and start the machine.

vboxmanage storageattach "$VM_NAME" --storagectl IDE --type dvddrive --port 1 --device 0 --medium emptydrive
vboxmanage startvm "$VM_NAME"

Your machine should now boot into the installed Fedora CoreOS.

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-4

In case you experience first boot problems, get error logs as below.

VM_LOG=$(realpath .)/$VM_NAME.log

vboxmanage modifyvm "$VM_NAME" --uart1 '0x3F8' '4'
vboxmanage modifyvm "$VM_NAME" --uartmode1 file "$VM_LOG"

Proceed and view logs.

cat $(realpath .)/$VM_NAME.log

Step 5 – Post Installation Basic Fedora CoreOS Configurations.

Now once the system has successfully rebooted, log in using SSH as below.

ssh [email protected] -p 2222

Sample Output:

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-5

Now verify your installation by ensuring your machine can pull the docker registry and run containers.

sudo docker run hello-world

Sample Output:

How-To-Run-Fedora-CoreOS-FCOS-on-VirtualBox-7

Using rpm-ostree on Fedora CoreOS

Here are a few commands you should get familiar with:

To show deployments in the order they appear, the first one is the default current state.

$ rpm-ostree status
State: idle
AutomaticUpdatesDriver: Zincati
  DriverState: active; periodically polling for updates (last checked Thu 2021-12-09 12:22:23 UTC)
Deployments:
● fedora:fedora/x86_64/coreos/stable
                   Version: 35.20211119.3.0 (2021-12-04T18:14:15Z)
                    Commit: 13af3774c363ffbf19d9cdf61f010f71686aced20c0f3e119ebe25e032f9bcab
              GPGSignature: Valid signature by 787EA6AE1147EEE56C40B30CDB4639719867C58F

To upgrade the system and set it as default in the next boot

rpm-ostree upgrade
sudo systemctl reboot

To roll back to the default deployment:

rpm-ostree deploy 

Adding Layered Packages using rpm-ostree

To add a layered package, use the syntax below.

rpm-ostree install 

For example, you can install multiple packages as below.

$ sudo rpm-ostree install git asciiquarium
Checking out tree 13af377... done
Enabled rpm-md repositories: fedora-cisco-openh264 fedora-modular updates-modular updates fedora updates-archive
⠁ Updating metadata for 'fedora-cisco-openh264'   0% [░░░░░░░░░░░░░░░░░░░░] (0⠙ Updating metadata for 'fedora-cisco-openh264'  95% [███████████████████░] (0⠚ Updating metadata for 'fedora-cisco-openh264' 100% [████████████████████] (0Updating metadata for 'fedora-cisco-openh264'... done
Updating metadata for 'fedora-modular'... done
Updating metadata for 'updates-modular'... done
Updating metadata for 'updates'... done
Updating metadata for 'fedora'... done
Updating metadata for 'updates-archive'... done
⠲ Importing rpm-md  67% [█████████████░░░░░░░] (2s) 
.........
 perl-overloading-0.02-482.fc35.noarch
  perl-parent-1:0.238-478.fc35.noarch
  perl-podlators-1:4.14-478.fc35.noarch
  perl-subs-1.04-482.fc35.noarch
  perl-vars-1.05-482.fc35.noarch
Changes queued for next boot. Run "systemctl reboot" to start a reboot

Verify the installation:

$ git --version
git version 2.33.1

At times the new layered package may fail to take effect, reboot your system. This is due to the atomic nature of the Operating system.

sudo systemctl reboot

Now proceed and verify the git installation.

$ git --version
git version 2.33.1

Voila!

Conclusion.

That was enough learning, we have successfully gone through how to run Fedora CoreOS (FCOS) on VirtualBox. I hope this guide was significant.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.