Skip to content

Instantly share code, notes, and snippets.

@SvenDowideit
Last active May 6, 2019 06:15
Show Gist options
  • Save SvenDowideit/46728f61c22a0d9acbdc6d7bdeb91751 to your computer and use it in GitHub Desktop.
Save SvenDowideit/46728f61c22a0d9acbdc6d7bdeb91751 to your computer and use it in GitHub Desktop.
#!/bin/bash
# get the kernel and initrd
ROS_VERSION="v0.9.2-rc4"
URL_BASE="https://github.com/rancher/os/releases/download/${ROS_VERSION}"
VMLINUX="vmlinuz-4.9.21-rancher"
INITRD="initrd-v0.9.2-rc4"
cd /tmp
echo "downloading ${URL_BASE}/${VMLINUX}" > /dev/kmsg
curl -O -L "${URL_BASE}/${VMLINUX}"
echo "downloading ${URL_BASE}/${INITRD}" > /dev/kmsg
curl -O -L "${URL_BASE}/${INITRD}"
# setup the host ready for kexec
PUBLIC_IPV4=$(wget -qO- http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
if [ "$(ros config get rancher.environment.installer)" == "true" ] && ros --version &>/dev/null; then
cat > cloud-config.yml <<EOF
#cloud-config
rancher:
network:
interfaces:
eth0:
address: $(ip -4 addr show dev eth0 | awk "/${PUBLIC_IPV4}/ {print \$2}")
gateway: $(ip -o route get 1 | awk '{print $3}')
dhcp: false
ssh_authorized_keys:
EOF
while read -r KEY; do
echo " - ${KEY}" >> cloud-config.yml
done < <(wget -qO- http://169.254.169.254/metadata/v1/public-keys; echo)
yes | ros install -c cloud-config.yml -d /dev/vda --append "rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0"
exit 0
fi
echo "apt-get installing kexec" > /dev/kmsg
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y kexec-tools ipcalc
PUBLIC_IPV4_NETMASK=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/netmask)
PUBLIC_IPV4_CIDR=$(ipcalc ${PUBLIC_IPV4}/${PUBLIC_IPV4_NETMASK} | awk '/^Network/ {n=split($2, i, "/"); print i[2]};')
PUBLIC_IPV4_GATEWAY=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/gateway)
echo "running kexec" > /dev/kmsg
kexec --initrd=${INITRD} -l ${VMLINUX} -f --command-line="rancher.debug=true printk.devkmsg=on notsc clocksource=kvm-clock rancher.network.interfaces.eth0.ipv4ll rancher.cloud_init.datasources=[digitalocean] rancher.autologin=tty1 rancher.autologin=ttyS0 rancher.environment.installer=true"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment