Created
July 29, 2020 04:36
-
-
Save relyt0925/06c03f82ab56eb4026e233d3aba19cb3 to your computer and use it in GitHub Desktop.
provision_redhatcoreos_qemu_macosx.sh
This file contains hidden or 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 | |
#Install brew and qemu dependencies | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | |
brew install qemu | |
brew install jq | |
rm -rf /tmp/rhcosqemu | |
#Download RedHat CoreOS Image and resize primary disk to 30G | |
mkdir -p /tmp/rhcosqemu/image | |
cd /tmp/rhcosqemu/image | |
RHCOS_IMAGE_FILE=$(curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.4/latest/sha256sum.txt | grep qemu | awk '{print $2}') | |
DOWNLOAD_URL="https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.4/latest/$RHCOS_IMAGE_FILE" | |
curl "$DOWNLOAD_URL" --output rhcos-qemu.x86_64.qcow2.xz | |
gunzip rhcos-qemu.x86_64.qcow2.xz | |
qemu-img resize /tmp/rhcosqemu/image/rhcos-qemu.x86_64.qcow2 30G | |
#create 30G secondary disk as well | |
qemu-img create -f qcow2 /tmp/rhcosqemu/image/secondarydisk.qcow2 30G | |
#Create the Ignition Configuration File | |
mkdir -p /tmp/rhcosqemu/ignitionmetadata | |
cd /tmp/rhcosqemu/ignitionmetadata | |
ssh-keygen -b 2048 -t rsa -f id_rsa_rhcosboot -P "" | |
chmod 0600 /tmp/rhcosqemu/ignitionmetadata/id_rsa_rhcosboot | |
PUBLIC_KEY=$(cat /tmp/rhcosqemu/ignitionmetadata/id_rsa_rhcosboot.pub) | |
cat <<EOF >/tmp/rhcosqemu/ignitionmetadata/ignitionconfig.ign | |
{ | |
"ignition": { | |
"version": "2.2.0" | |
}, | |
"passwd": { | |
"users": [ | |
{ | |
"name": "core", | |
"sshAuthorizedKeys": [ | |
"${PUBLIC_KEY}" | |
] | |
} | |
] | |
} | |
} | |
EOF | |
#boot the machine up | |
qemu-system-x86_64 -m 2048 -smp 4 -hda /tmp/rhcosqemu/image/rhcos-qemu.x86_64.qcow2 -hdb /tmp/rhcosqemu/image/secondarydisk.qcow2 -fw_cfg name=opt/com.coreos/config,file=/tmp/rhcosqemu/ignitionmetadata/ignitionconfig.ign -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5556-:22 -nographic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment