|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +# fail if we encounter an error, uninitialized variable or a pipe breaks |
| 6 | +set -eu -o pipefail |
| 7 | + |
| 8 | +# be verbose |
| 9 | +set -x |
| 10 | +PS4='+\t ' |
| 11 | + |
| 12 | +cp -ruv $rootfs/* / |
| 13 | + |
| 14 | +packages="udev systemd-sysv openssh-server iproute2 curl socat python3-minimal iperf3 iputils-ping fio kmod" |
| 15 | + |
| 16 | +# msr-tools is only supported on x86-64. |
| 17 | +arch=$(uname -m) |
| 18 | +if [ "${arch}" == "x86_64" ]; then |
| 19 | + packages="$packages msr-tools cpuid" |
| 20 | +fi |
| 21 | + |
| 22 | +export DEBIAN_FRONTEND=noninteractive |
| 23 | +apt update |
| 24 | +apt install -y --no-install-recommends $packages |
| 25 | +apt autoremove |
| 26 | + |
| 27 | +# Set a hostname. |
| 28 | +echo "ubuntu-fc-uvm" > /etc/hostname |
| 29 | + |
| 30 | +passwd -d root |
| 31 | + |
| 32 | +# The serial getty service hooks up the login prompt to the kernel console |
| 33 | +# at ttyS0 (where Firecracker connects its serial console). We'll set it up |
| 34 | +# for autologin to avoid the login prompt. |
| 35 | +for console in ttyS0; do |
| 36 | + mkdir "/etc/systemd/system/serial-getty@$console.service.d/" |
| 37 | + cat <<'EOF' > "/etc/systemd/system/serial-getty@$console.service.d/override.conf" |
| 38 | +[Service] |
| 39 | +# systemd requires this empty ExecStart line to override |
| 40 | +ExecStart= |
| 41 | +ExecStart=-/sbin/agetty --autologin root -o '-p -- \\u' --keep-baud 115200,38400,9600 %I dumb |
| 42 | +EOF |
| 43 | +done |
| 44 | + |
| 45 | +# Setup fcnet service. This is a custom Firecracker setup for assigning IPs |
| 46 | +# to the network interfaces in the guests spawned by the CI. |
| 47 | +ln -s /etc/systemd/system/fcnet.service /etc/systemd/system/sysinit.target.wants/fcnet.service |
| 48 | + |
| 49 | +# Disable resolved and ntpd |
| 50 | +# |
| 51 | +rm -f /etc/systemd/system/multi-user.target.wants/systemd-resolved.service |
| 52 | +rm -f /etc/systemd/system/dbus-org.freedesktop.resolve1.service |
| 53 | +rm -f /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service |
| 54 | + |
| 55 | +# make /tmp a tmpfs |
| 56 | +ln -s /usr/share/systemd/tmp.mount /etc/systemd/system/tmp.mount |
| 57 | +systemctl enable tmp.mount |
| 58 | + |
| 59 | +# don't need this |
| 60 | +systemctl disable e2scrub_reap.service |
| 61 | +rm -vf /etc/systemd/system/timers.target.wants/* |
| 62 | +# systemctl list-units --failed |
| 63 | +# /lib/systemd/system/systemd-random-seed.service |
| 64 | + |
| 65 | +systemctl enable var-lib-systemd.mount |
| 66 | + |
| 67 | +#### trim image https://wiki.ubuntu.com/ReducingDiskFootprint |
| 68 | +# this does not save much, but oh well |
| 69 | +rm -rf /usr/share/{doc,man,info,locale} |
| 70 | + |
| 71 | +cat >> /etc/sysctl.conf <<EOF |
| 72 | +# This avoids a SPECTRE vuln |
| 73 | +kernel.unprivileged_bpf_disabled=1 |
| 74 | +EOF |
0 commit comments