Last active
December 9, 2021 15:55
-
-
Save nmilosev/7dfc0d43b4c69c3be84e1ef0f358fe8b to your computer and use it in GitHub Desktop.
Quick Fedora Cloud VM w/QEMU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Quickily setup a Fedora Minimal Cloud VM with qemu | |
# Supports aarch64 and x86_64 | |
# No KVM by default, add -accel=kvm to qemu call | |
export VER=35 | |
export ARCH=x86_64 | |
export DISK_SIZE=20G | |
export VM_HOST=fedora-cloud | |
export VM_USER=fedora | |
export VM_PASSWORD=fedora | |
export FILE=fedora-$VER-disk.qcow2 | |
export RAM=2048 | |
export CPUS=4 | |
if [[ ! -f "$FILE" ]]; then | |
echo "$FILE does not exist. Performing setup." | |
echo "Downloading Fedora Cloud image" | |
wget -q --show-progress https://download.fedoraproject.org/pub/fedora/linux/releases/$VER/Cloud/$ARCH/images/Fedora-Cloud-Base-$VER-1.2.$ARCH.qcow2 | |
echo "Making disk image extension" | |
qemu-img create -F qcow2 -f qcow2 -b Fedora-Cloud-Base-$VER-1.2.$ARCH.qcow2 $FILE $DISK_SIZE | |
echo "Preparing seed image" | |
cat > meta-data << EOF | |
instance-id: Cloud00 | |
local-hostname: $VM_HOST | |
EOF | |
cat > user-data << EOF | |
#cloud-config | |
system_info: | |
default_user: | |
name: $VM_USER | |
chpasswd: | |
list: | | |
$VM_USER:$VM_PASSWORD | |
expire: False | |
resize_rootfs: True | |
ssh_pwauth: True | |
EOF | |
genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data | |
mkisofs -J -l -R -V "cidata" -iso-level 4 -o seed.iso user-data meta-data | |
echo "Seed image is prepared" | |
if [ $ARCH = 'aarch64' ]; then | |
echo 'Setting up UEFI for aarch64' | |
cp /usr/share/edk2/aarch64/QEMU_EFI.fd . | |
fi | |
fi | |
if [ $ARCH = 'x86_64' ]; then | |
qemu-system-$ARCH \ | |
-m $RAM \ | |
-smp $CPUS \ | |
--accel tcg,thread=multi \ | |
-hda $FILE \ | |
-cdrom seed.iso \ | |
-netdev bridge,br=virbr0,id=net0 \ | |
-device virtio-net-pci,netdev=net0 \ | |
-nographic | |
fi | |
if [ $ARCH = 'aarch64' ]; then | |
qemu-system-$ARCH \ | |
-machine virt \ | |
-cpu cortex-a57 \ | |
-m $RAM \ | |
-bios QEMU_EFI.fd \ | |
-boot efi \ | |
-display none \ | |
-smp $CPUS \ | |
--accel tcg,thread=multi \ | |
-hda $FILE \ | |
-cdrom seed.iso \ | |
-netdev bridge,br=virbr0,id=net0 \ | |
-device virtio-net-pci,netdev=net0 \ | |
-nographic | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment