Skip to content

Instantly share code, notes, and snippets.

@tsutsu
Last active September 25, 2016 09:14
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tsutsu/490f35f48897df0f5173 to your computer and use it in GitHub Desktop.
Save tsutsu/490f35f48897df0f5173 to your computer and use it in GitHub Desktop.
CoreOS on DigitalOcean (using "Debian 7 x64" as a base)
#cloud-config
hostname: <<your chosen hostname>>
users:
- name: <<your chosen user name>>
groups:
- sudo
- docker
ssh-authorized-keys:
- <<your ssh key (should start with "ssh-rsa ...")>>
coreos:
units:
- name: static.network
content: |
[Match]
Name=ens3
[Network]
Address=<<your host's static IP, assigned by DO>>/24
Gateway=<<your host's gateway's static IP>>
DNS=8.8.8.8
DNS=8.8.4.4
- name: media-doroot.mount
command: start
content: |
[Mount]
What=/dev/vda
Where=/media/doroot
Type=ext4
- name: format-docker-store.service
command: start
content: |
[Unit]
Requires=media-doroot.mount
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/media/doroot/usr/sbin/create-coreos-docker-store
- name: var-lib-docker.mount
command: start
content: |
[Unit]
Requires=format-docker-store.service
Before=docker.service
[Mount]
What=/dev/disk/by-label/docker
Where=/var/lib/docker
Type=btrfs
#!/bin/sh
mkdir -p /media/doroot/var/lib/coreos
if [ ! -f "/media/doroot/var/lib/coreos/docker.img" ]; then
DOFORMAT=1
fi
truncate -s 10G /media/doroot/var/lib/coreos/docker.img
LODEV=`losetup -f --show /media/doroot/var/lib/coreos/docker.img`
if [ -n "$DOFORMAT" ]; then
mkfs.btrfs -L docker "$LODEV"
fi
  1. run sudo apt-get install squashfs-tools kexec-tools
  2. copy "update.sh" to /usr/sbin/update-coreos, and make it executable
  3. copy "create-docker-store.sh" to /usr/sbin/create-coreos-docker-store, and make it executable
  4. copy "cloud-config.yml" to /etc/default/coreos, modifying it to suit your preferences
  5. run sudo update-coreos -d
  6. reboot
#!/bin/bash
set -e
BASE_URL="http://storage.core-os.net/coreos/amd64-usr/alpha"
KERNEL="/boot/coreos/vmlinuz"
INITRD_IMAGE="/boot/coreos/initrd.cpio.gz"
INITRD_TEMPLATE="/boot/coreos/initrd.template"
CONFIG="/etc/default/coreos"
CONFIG_LINK_DIR="/boot/coreos/initrd.template/usr/share/oem"
if [ ! -f "$CONFIG" ]; then
echo "cannot proceed without a valid cloud-config in $CONFIG; aborting"
exit 1
fi
mkdir -p "$CONFIG_LINK_DIR"
if [ "$1" = "-d" -o "$1" = "--download" ]; then
shift
REDOWNLOAD_KERNEL=1
REDOWNLOAD_INITRD=1
fi
if [ ! -f "$CONFIG_LINK_DIR/cloud-config.yml" ]; then
ln -s "$CONFIG" "$CONFIG_LINK_DIR/cloud-config.yml"
fi
if [ ! -f "$KERNEL" ]; then
REDOWNLOAD_KERNEL=1
fi
if [ "$(find "$INITRD_TEMPLATE" -name "*.squashfs" -type f | wc -l)" -eq 0 ]; then
REDOWNLOAD_INITRD=1
fi
if [ -n "$REDOWNLOAD_KERNEL" ]; then
curl "$BASE_URL/coreos_production_pxe.vmlinuz" > "$KERNEL"
fi
if [ -n "$REDOWNLOAD_INITRD" ]; then
find "$INITRD_TEMPLATE" -name "*.squashfs" -type f -delete
TMP=`mktemp -d`
pushd "$TMP" >/dev/null
curl "$BASE_URL/coreos_production_pxe_image.cpio.gz" | zcat | cpio -id
find "$TMP" -name "*.squashfs" -type f -exec 'mv' '{}' "${INITRD_TEMPLATE}/" ';'
popd >/dev/null
rm -rf "$TMP"
fi
rm -f "$INITRD_IMAGE"
pushd "$INITRD_TEMPLATE" >/dev/null
rm -f ./manifest
find . -name "*.squashfs" >> ./manifest
find ./usr >> ./manifest
cat ./manifest | cpio -o -H newc -L | gzip -nc - > "$INITRD_IMAGE"
popd >/dev/null
@sttts
Copy link

sttts commented Jun 8, 2014

Very good recipe. Some comments:

  • reboot does not launch kexec. You can do it manually:
kexec --load /boot/coreos/vmlinuz --initrd /boot/coreos/initrd.cpio.gz
kexec --exec
  • or put that into /etc/rc.local to be executed automatically.
  • for debugging very helpful: autlogin
kexec --load /boot/coreos/vmlinuz --initrd /boot/coreos/initrd.cpio.gz --append 'console=tty1 coreos.autologin=tty1'
kexec --exec
  • sometimes kexec freezes here after showing "Starting new kernel" on tty1. No idea why.

@sttts
Copy link

sttts commented Jun 11, 2014

I extended your code and integrated it into the Deis bootstrapping: deis/deis#1159

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