Skip to main content

Fedora Cloud 44

Fedora Cloud 44 VM creation on a Linux host using KVM​

This gives us a fairly minimal UEFI based VM with /var, /home and / on a btrfs volume, a FAT16 EFI partition and an ext4 boot partition.

Download Fedora Cloud 44​

mkdir -p ~/VMs/base_images/Fedora/44
# Set an appropriate folder icon:
gio set -t string ~/VMs/ISOs/Linux/AWS metadata::custom-icon file://"${HOME}"/Pictures/icons/folder-fedora.svg

curl \
--location https://ftp2.osuosl.org/pub/fedora/linux/releases/test/44_Beta/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-44_Beta-1.2.x86_64.qcow2 \
--output ~/VMs/base_images/Fedora/44/Fedora-Cloud-Base-Generic-44_Beta-1.2.x86_64.qcow2

Setup tmux windows (Optional)​

# Setup the tmux server:
tmux new -s split_vm
# Split the tmux screen so we can see both terminal windows simultaneously:
tmux split-window

Define the VM name and location​

# Define the new VM name:
export VMNAME="fedora-cloud-44-01"
mkdir -p ~/VMs/"${VMNAME}"
cd ~/VMs/"${VMNAME}"
# Set an appropriate folder icon:
gio set -t string ~/VMs/"${VMNAME}" metadata::custom-icon file://"${HOME}"/Pictures/icons/folder-fedora.svg

Create the cloud-init user-data file​

The following cloud-init file automates almost everything that we did in the Fedora Server example above.

nano -w "${HOME}/VMs/${VMNAME}/${VMNAME}-user-data.yaml"

And paste in the following contents:

#cloud-config

# Grow the disk partitions to fill the "physical" disk
growpart:
mode: auto
devices: ['/']

write_files:
- path: /etc/dnf/dnf.conf
owner: root:root
permissions: '0644'
defer: true
content: |
# see `man dnf.conf` for defaults and possible options
[main]
exclude=mercurial,subversion
- path: /run/scripts/test-script.sh
content: |
#!/usr/bin/env bash
touch /opt/testing.txt
printf "Test script executed successfully!" >> /opt/testing.txt
permissions: '0755'

hostname: VMNAME
create_hostname_file: true
fqdn: VMNAME.btv.internal.asuresoftware.com
prefer_fqdn_over_hostname: true

# Disable password authentication over SSH
# https://cloudinit.readthedocs.io/en/latest/reference/modules.html#set-passwords
ssh_pwauth: false
# Do not print SSH keys to the console during cloud-init setup
no_ssh_fingerprints: true
ssh:
emit_keys_to_console: false

users:
- name: patrickmslattery
gecos: User with SSH key configured and sudo nopasswd enabled
lock_passwd: false
groups: sudo
sudo: ['ALL=(ALL) NOPASSWD:ALL']
shell: /bin/zsh
ssh_authorized_keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJGbdZXGee0zdBqQaDsUXOgp/1DuD3b3YlHREEtne8OV [email protected]"
- "[email protected] AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAINasnNd3FLrNWPJTGBbAc8bA7I+HdH8gtkHvEaWtG6gZAAAABHNzaDo= [email protected] - YubiKey Red"

# Run dnf upgrade
package_upgrade: true
package_reboot_if_required: true
# Install the following packages:
packages:
- git
- jq
- yq
- htop
- zsh
- curl
- wget
- fzf
- powerline-go
- powerline-fonts
- https://github.com/PowerShell/PowerShell/releases/download/v7.5.4/powershell-7.5.4-1.rh.x86_64.rpm

timezone: "America/New_York"
# timezone: "Etc/UTC"

runcmd:
# - [ "sh", "-c", 'echo "IP is: \4" >> /etc/issue' ] # Not needed on this image
# Set Zsh as the default shell for default user
- [ "chsh", "-s", '$(which zsh) patrickmslattery' ]
# Install Oh My Zsh for the default user
- runuser -l patrickmslattery --command 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended'
- [ sh, "/run/scripts/test-script.sh" ]

# Reboot the VM when install is complete
power_state:
delay: now
mode: reboot
message: Rebooting...
timeout: 30
condition: True

Update the hostname:

sed -i "s/VMNAME/${VMNAME}/g" "${HOME}/VMs/${VMNAME}/${VMNAME}-user-data.yaml"
grep ${VMNAME} "${HOME}/VMs/${VMNAME}/${VMNAME}-user-data.yaml"

Validate the cloud-init user-data file​

sudo cloud-init schema --config-file "${HOME}/VMs/${VMNAME}/${VMNAME}-user-data.yaml" --annotate

You should get: Valid schema ???-user-data.yaml

Creating the VM​

# Copy the base image to the VM specific directory:
rsync --progress ~/VMs/base_images/Fedora/44/Fedora-Cloud-Base-Generic-44_Beta-1.2.x86_64.qcow2 ~/VMs/${VMNAME}/${VMNAME}-vda.qcow2
# NOTE: THIS IS VERY SLOW WHEN RUNNING UNDER TMUX

# How big is the allocated disk?
qemu-img info ~/VMs/${VMNAME}/${VMNAME}-vda.qcow2
# file format: qcow2
# virtual size: 5 GiB (5368709120 bytes)
# disk size: 555 MiB

# Extend the base image by 10GB
qemu-img resize ~/VMs/${VMNAME}/${VMNAME}-vda.qcow2 +10G
# Image resized.

# Create the VM with 2GB of RAM initially:
virt-install \
--connect qemu:///session \
--hvm \
--name "${VMNAME}" \
--memory "2048",maxmemory="8192" \
--vcpus "2" \
--disk path="${HOME}/VMs/${VMNAME}/${VMNAME}-vda.qcow2",bus=virtio \
--os-variant "fedora-rawhide" \
--graphics none \
--network bridge:virbr0 \
--boot uefi \
--noautoconsole \
--sound none \
--cloud-init user-data="${HOME}/VMs/${VMNAME}/${VMNAME}-user-data.yaml" \
--import

Wait for the VM to reboot or shutdown before moving on to the next steps. This will take about 4 minutes in total. If the VM shuts down instead of rebooting then turn it back on again.

VM IP v4 address​

The VMs IP v4 should be clearly listed on the VM console, where it can be selected and copied from.

info

Note that this VM is setup by default with a text console, not a graphical console.

# This assigns the contents of the clipboard to the variable: `IP_ADDRESS`
# Copy and paste the command line below into a terminal but don't press Enter:
export IP_ADDRESS=$(wl-paste) && printf "IP_ADDRESS: ${IP_ADDRESS}\n"

Copy the IP address from the VM console now

TODO_NEED_IMAGE

Then press enter to the line above.

Then you can copy/paste the following on the VM host machine:

sudo sed -i "/${VMNAME}/d" /etc/hosts
echo -e "${IP_ADDRESS} ${VMNAME}" | sudo tee -a /etc/hosts > /dev/null
cat /etc/hosts
# Remove any prior instances of the VM listed in the SSH known_hosts file:
sed -i "/${VMNAME}/d" ~/.ssh/known_hosts
grep "${VMNAME}" ~/.ssh/known_hosts

Connect to the VM with the SSH key on the YubiKey​

# With the YubiKey inserted:
ssh -o "IdentitiesOnly=yes" -i ~/.ssh/id_ed25519_sk patrickmslattery@${IP_ADDRESS}

Expected response:

Warning: Permanently added '192.168.122.92' (ED25519) to the list of known hosts.
➜ ~ hostname
fedora-cloud-44-01.btv.internal.asuresoftware.com

Increase the memory allocation of the VM (Optional)​

# SSH to the VM
ssh ${IP_ADDRESS}
# Run htop in the VM so we can see the RAM usage live
htop

# Jump between tmux windows
CTRL + B + ARROW_DOWN

#----------------------------------------
# On the VM Host
# Set memory to 8GB (8388608 KiB) while the VM is live (do it while htop is running):
export VMNAME="fedora-cloud-44-01"
virsh setmem --domain "${VMNAME}" --size 8388608 --live

Destroying the VM when work is complete​

cd ~
virsh shutdown "${VMNAME}"
sleep 10
virsh undefine "${VMNAME}" --remove-all-storage --nvram
rm -rf "${HOME}/VMs/${VMNAME}"