Created
November 9, 2021 10:59
-
-
Save t-lo/f6b1d7589ccf9c8b89a83b501a258132 to your computer and use it in GitHub Desktop.
Script to set up Flatcar to run on firecracker. Run in an empty directory to download all components, then run ./start-flatcar.sh to run Flatcar on Firecracker.
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 | |
set -eu | |
function get_firecracker() { | |
rm -f firecracker-v0.24.6-x86_64.tgz firectl-v0.1.0 | |
rm -rf release-*/* | |
wget https://github.com/firecracker-microvm/firecracker/releases/download/v0.24.6/firecracker-v0.24.6-x86_64.tgz | |
wget https://firectl-release.s3.amazonaws.com/firectl-v0.1.0 | |
tar xzf firecracker-v0.24.6-x86_64.tgz | |
mv release-*/* . | |
chmod 755 firecracker-* firectl-* | |
} | |
# -- | |
function get_flatcar() { | |
local i | |
for i in "flatcar_production_image.bin.bz2" \ | |
"flatcar_production_image.vmlinuz" ; do | |
wget "https://stable.release.flatcar-linux.net/amd64-usr/current/$i" | |
done | |
bunzip2 flatcar_production_image.bin.bz2 | |
} | |
# -- | |
function extract_vmlinux() { | |
wget https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux | |
chmod 755 extract-vmlinux | |
patch -p0 <<EOF | |
--- extract-vmlinux 2021-11-05 14:28:47.123984433 +0100 | |
+++ extract-vmlinux 2021-11-05 14:28:29.487982001 +0100 | |
@@ -49,12 +49,17 @@ | |
trap "rm -f \$tmp" 0 | |
# That didn't work, so retry after decompression. | |
-try_decompress '\\037\\213\\010' xy gunzip | |
-try_decompress '\\3757zXZ\\000' abcde unxz | |
-try_decompress 'BZh' xy bunzip2 | |
-try_decompress '\\135\\0\\0\\0' xxx unlzma | |
-try_decompress '\\211\\114\\132' xy 'lzop -d' | |
-try_decompress '\\002!L\\030' xxx 'lz4 -d' | |
+#try_decompress '\\037\\213\\010' xy gunzip | |
+#try_decompress '\\3757zXZ\\000' abcde unxz | |
+#try_decompress 'BZh' xy bunzip2 | |
+#try_decompress '\\135\\0\\0\\0' xxx unlzma | |
+#try_decompress '\\211\\114\\132' xy 'lzop -d' | |
+#try_decompress '\\002!L\\030' xxx 'lz4 -d' | |
+ | |
+# check if unzstd is installed, fail if it is not | |
+set -e | |
+unzstd -V >/dev/null | |
+set +e | |
try_decompress '(\\265/\\375' xxx unzstd | |
# Finally check for uncompressed images or objects: | |
EOF | |
./extract-vmlinux flatcar_production_image.vmlinuz > flatcar-vmlinux | |
} | |
get_firecracker | |
firecracker="$(echo ./firecracker-*)" | |
firectl="$(echo ./firectl-*)" | |
get_flatcar | |
extract_vmlinux | |
verity_hash="$(dd if=flatcar_production_image.vmlinuz conv=notrunc skip=64 count=64 bs=1 status=none)" | |
root_uuid=$(partx -s flatcar_production_image.bin | grep ROOT | tr -s " " | cut -d " " -f 8) | |
usr_uuid=$(partx -s flatcar_production_image.bin | grep USR-A | tr -s " " | cut -d " " -f 8) | |
echo "${firectl} --firecracker-binary=${firecracker} \ | |
--kernel=flatcar-vmlinux --root-drive=flatcar_production_image.bin \ | |
--root-partition=$root_uuid \ | |
--kernel-opts='rootflags=rw mount.usrflags=ro BOOT_IMAGE=/flatcar/vmlinuz-a mount.usr=/dev/mapper/usr verity.usr=PARTUUID=$usr_uuid consoleblank=0 console=ttyS0,115200n8 console=tty0 flatcar.autologin verity.usrhash=$verity_hash rd.driver.pre=virtio_mmio console=ttyS0 reboot=k panic=1 i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd'" > start-flatcar.sh | |
chmod 755 start-flatcar.sh | |
echo | |
echo " All done - run ./start-flatcar.sh to run Flatcar on Firecracker." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment