Skip to content

Instantly share code, notes, and snippets.

@zonggen
Created April 15, 2020 18:49
Show Gist options
  • Save zonggen/73ce7330f1c92338e5300ac7907bda34 to your computer and use it in GitHub Desktop.
Save zonggen/73ce7330f1c92338e5300ac7907bda34 to your computer and use it in GitHub Desktop.
Install Fedora CoreOS by running `coreos-installer` directly on block device `/dev/loop0`
#!/usr/bin/env bash
function create_ign_file() {
cat >> base3.ign <<EOF
{
"ignition": {
"version": "3.0.0"
},
"passwd": {
"users": [
{
"name": "core",
"sshAuthorizedKeys": [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC6jeR8fMqwxDsoVdc62m+V6L9QWH7MSJ+zmmrE0UWClF3iuFJ5belHxXNg/6wnpefyu5hKrrwCGjcfxNxH438MYuUOBxo5CwZHI3d3+kkMudidEhFJxMhk+S9I5XnBRjhzQrTnqcf2BULW4kV6JfrLSx2TQxvaUh9d59tJa5J6sFtob6Iil/qY9oyKQQHA/+7+xgCqWW2P/lgkBCLk1+ll+F0nNCTygUJjWyRWy3lUDo5edwyV8cqoYJVmE1dcBAqV7GwflrlSf+RzAVa8S5hxpdKyXs9SVVlFoN3/SjwaJnJX/oQWPbubraBm3/7sAC2pLAo9BuSRYdylUJyS9NGhNK2ibdB4o5rWREynnX6Lr4FotzIAQg+xDFRc9EX+sHHaTOWXDebFzL4aJEPn1XA0hQ5zzK5PZyL6l1v+qiz16o4hO4PlRaW5FmNndjCJ3yREalIZBp6a9PCdNw9K4LPcPQ1ZYjxx6bn1SWXbRodKpdSQqLlzKeUNjH0Aro6+TB8= abai@unused-10-15-17-19.yyz.redhat.com"
]
}
]
},
"systemd": {
"units": [
{
"dropins": [
{
"contents": "[Service]\nTTYVTDisallocate=no\nExecStart=\nExecStart=-/usr/sbin/agetty --autologin core --noclear %I xterm-256color",
"name": "autologin.conf"
}
],
"name": "serial-getty@ttyS0.service"
}
]
}
}
EOF
}
if [[ $1 == "install" ]];
then
set -x
# if the coreos-installer directory does not exist
# pull the coreos-install repo from github
[[ -d coreos-installer ]] || \
git clone https://github.com/coreos/coreos-installer.git \
; cd coreos-installer
# build the binary file
cargo build
# create a QEMU image
qemu-img create -f qcow2 fcos.qcow2 8G
# shrink/extend the size of the image file
truncate -s 8G fcos.qcow2
# set up a loop device
sudo losetup -P /dev/loop0 fcos.qcow2
# run the coreos-installer binary
create_ign_file && \
sudo target/debug/coreos-installer install /dev/loop0 -s testing --ignition-file base3.ign
# run the virtual machine with QEMU
qemu-system-x86_64 -accel kvm -name fcos -m 2048 -cpu host -smp 2 -netdev user,id=eth0,hostname=coreos -device virtio-net-pci,netdev=eth0 -drive file=fcos.qcow2
set +x
exit 0
fi
if [[ $1 == "clean" ]];
then
set -x
[[ $(basename $PWD) != "coreos-installer" ]] && cd coreos-installer
# detach the file or device associated with the specified loop device(s)
sudo losetup -d /dev/loop0
# remvoes qcow2 and ignition config file
rm -f fcos.qcow2
rm -f base3.ign
set +x
exit 0
fi
printf "Available options:\n\tinstall\n\tclean\n"
exit 1
@zonggen
Copy link
Author

zonggen commented Apr 15, 2020

Please replace the sshAuthorizedKeys section with your own ssh pubkey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment