Created
February 21, 2019 16:11
-
-
Save alexlovelltroy/28f2161801eb644cbe7500bbd7c13bb0 to your computer and use it in GitHub Desktop.
Create, Load, and Start a bunch of simple firecracker vms
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
#!/bin/bash | |
echo "Bash version ${BASH_VERSION}..." | |
FIRECRACKER_BIN=/usr/bin/firecracker | |
JAILER_BIN=/usr/bin/jailer | |
echo -n "Jailer version " | |
$JAILER_BIN -V | |
echo -n "Firecracker version " | |
$FIRECRACKER_BIN -V | |
# Create the default chroot directory | |
mkdir -p /srv/jailer | |
for i in {1100..1200} | |
do | |
#SUFFIX=$(cat /dev/random | LC_CTYPE=C tr -dc "a-z0-9" | head -c 5) | |
SUFFIX=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w ${1:-8} | head -n 1) | |
echo "Creating user firecracker_$SUFFIX" | |
# Create a uid/gid/homedir for each vm | |
useradd firecracker_$SUFFIX | |
TMP_UID=`id -u firecracker_$SUFFIX` | |
TMP_GID=`id -g firecracker_$SUFFIX` | |
# Launch firecracker using jailer | |
JAILER_COMMAND="$JAILER_BIN --id $SUFFIX --node 0 --exec-file $FIRECRACKER_BIN --uid $TMP_UID --gid $TMP_GID --daemonize" | |
echo $JAILER_COMMAND | |
eval $JAILER_COMMAND & | |
sleep 1 | |
# Copy in the kernel and rootfs | |
cp hello* /srv/jailer/firecracker/$SUFFIX/root/ | |
chown -R $TMP_UID:$TMP_GID /srv/jailer/firecracker/$SUFFIX/root/* | |
done |
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
#!/bin/bash | |
echo "Bash version ${BASH_VERSION}..." | |
# This should work based on the swagger yaml, but doesn't work with version 0.14.0 | |
# I use pkill firecracker instead and then remove all the /srv/jailer stuff | |
for sock in `find /srv/jailer/firecracker -name "api.socket"`; do | |
curl --unix-socket $sock -i \ | |
-X PUT 'http://localhost/actions' \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"action_type": "SendCtrlAltDel" | |
}' | |
done |
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
#!/bin/bash | |
echo "Bash version ${BASH_VERSION}..." | |
for sock in `find /srv/jailer/firecracker -name "api.socket"`; do | |
echo $sock | |
curl --unix-socket $sock -i \ | |
-X PUT 'http://localhost/boot-source' \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"kernel_image_path": "hello-vmlinux.bin", | |
"boot_args": "console=ttyS0 reboot=k panic=1 pci=off" | |
}' | |
curl --unix-socket $sock -i \ | |
-X PUT 'http://localhost/drives/rootfs' \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"drive_id": "rootfs", | |
"path_on_host": "hello-rootfs.ext4", | |
"is_root_device": true, | |
"is_read_only": false | |
}' | |
done |
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
#!/bin/bash | |
echo "Bash version ${BASH_VERSION}..." | |
for sock in `find /srv/jailer/firecracker -name "api.socket"`; do | |
curl --unix-socket $sock -i \ | |
-X PUT 'http://localhost/actions' \ | |
-H 'Accept: application/json' \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"action_type": "InstanceStart" | |
}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment