Created
February 4, 2026 23:41
-
-
Save tiebingzhang/94a48798e508e65a7eac842a4c983c2f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| arch=`uname -m` | |
| dest_kernel="hello-vmlinux.bin" | |
| dest_rootfs="hello-rootfs.ext4" | |
| image_bucket_url="https://s3.amazonaws.com/spec.ccfc.min/img/quickstart_guide/$arch" | |
| if [ ${arch} = "x86_64" ]; then | |
| kernel="${image_bucket_url}/kernels/vmlinux.bin" | |
| rootfs="${image_bucket_url}/rootfs/bionic.rootfs.ext4" | |
| elif [ ${arch} = "aarch64" ]; then | |
| kernel="${image_bucket_url}/kernels/vmlinux.bin" | |
| rootfs="${image_bucket_url}/rootfs/bionic.rootfs.ext4" | |
| else | |
| echo "Cannot run firecracker on $arch architecture!" | |
| exit 1 | |
| fi | |
| if [ ! -f $dest_kernel ]; then | |
| echo "Kernel not found, downloading $kernel..." | |
| curl -fsSL -o $dest_kernel $kernel | |
| echo "Saved kernel file to $dest_kernel." | |
| fi | |
| if [ ! -f $dest_rootfs ]; then | |
| echo "Rootfs not found, downloading $rootfs..." | |
| curl -fsSL -o $dest_rootfs $rootfs | |
| echo "Saved root block device to $dest_rootfs." | |
| fi | |
| echo "Downloading public key file..." | |
| [ -e hello-id_rsa ] || wget -O hello-id_rsa https://raw.githubusercontent.com/firecracker-microvm/firecracker-demo/ec271b1e5ffc55bd0bf0632d5260e96ed54b5c0c/xenial.rootfs.id_rsa | |
| echo "Saved public key file." |
This file contains hidden or 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
| set -eu | |
| TAP_DEV="fc-88-tap0" | |
| # set up the kernel boot args | |
| MASK_LONG="255.255.255.252" | |
| MASK_SHORT="/30" | |
| FC_IP="169.254.0.21" | |
| TAP_IP="169.254.0.22" | |
| FC_MAC="02:FC:00:00:00:05" | |
| KERNEL_BOOT_ARGS="ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules random.trust_cpu=on" | |
| KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:off" | |
| sudo ip link del "$TAP_DEV" 2> /dev/null || true | |
| sudo ip tuntap add dev "$TAP_DEV" mode tap | |
| sudo sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null | |
| sudo sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null | |
| sudo ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV" | |
| sudo ip link set dev "$TAP_DEV" up | |
| cat <<EOF > vmconfig.json | |
| { | |
| "boot-source": { | |
| "kernel_image_path": "hello-vmlinux.bin", | |
| "boot_args": "$KERNEL_BOOT_ARGS" | |
| }, | |
| "drives": [ | |
| { | |
| "drive_id": "rootfs", | |
| "path_on_host": "hello-rootfs.ext4", | |
| "is_root_device": true, | |
| "is_read_only": false | |
| } | |
| ], | |
| "network-interfaces": [ | |
| { | |
| "iface_id": "eth0", | |
| "guest_mac": "$FC_MAC", | |
| "host_dev_name": "$TAP_DEV" | |
| } | |
| ], | |
| "machine-config": { | |
| "vcpu_count": 2, | |
| "mem_size_mib": 1024, | |
| "smt": false | |
| } | |
| } | |
| EOF | |
| ~/bin/firecracker --no-api --config-file vmconfig.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment