diff --git a/mk/ch.mk b/mk/ch.mk index f3938954d..fccee5db5 100644 --- a/mk/ch.mk +++ b/mk/ch.mk @@ -117,7 +117,7 @@ ch-check: $(call ch_check_set,CH_FIRMWARE) $(if $(filter tap,$(net)),$(if $(ch_tap_found),,$(error no tap device $(CH_TAP). Create it with scripts/ch-tap-setup.sh or leave out net=tap to use passt))) -ch-deps: $(DISK) $(EXTRA_DISK) $(CH_DOWNLOADS) +ch-deps: $(DISK) $(EXTRA_DISK) $(CH_DOWNLOADS) $(VIRTIOFS_DEPS) ch-fetch: ch-check $(CH_DOWNLOADS) diff --git a/mk/config.mk b/mk/config.mk index 9e799e6f4..ec95b4a0e 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -17,7 +17,7 @@ PREFIX_USE_UPSTREAM_RUST_COMPILER?=0 ## Enable to use binary packages (much faster) REPO_BINARY?= ## Name of the configuration to include in the image name e.g. desktop or server -CONFIG_NAME?=desktop +CONFIG_NAME?=server ## Build appstream data for repo REPO_APPSTREAM?=0 ## Ignore errors when building the repo, attempt to build every package diff --git a/mk/qemu.mk b/mk/qemu.mk index f1760e544..48f5e5050 100644 --- a/mk/qemu.mk +++ b/mk/qemu.mk @@ -352,7 +352,7 @@ endif .PHONY: qemu-deps -qemu-deps: $(DISK) +qemu-deps: $(DISK) $(VIRTIOFS_DEPS) ifeq ($(disk),usb) else ifeq ($(disk),sdcard) diff --git a/mk/virtiofs.mk b/mk/virtiofs.mk index ea5a156bd..0e46b504f 100644 --- a/mk/virtiofs.mk +++ b/mk/virtiofs.mk @@ -17,11 +17,28 @@ # WARNING: share=redox exposes the whole build tree to the guest, including # the harddrive.img Redox is booted from, .git and .config. Writing to them # from Redox can corrupt the build system. share=redox:ro avoids that. +# +# virtiofsd runs on the host. The first one found is used: VIRTIOFSD, then +# virtiofsd in PATH, /usr/libexec/virtiofsd or /usr/lib/qemu/virtiofsd. When +# there is none, x86_64 Linux hosts download a static build into +# build/virtiofsd/$(HOST_ARCH) (make virtiofsd-fetch does only that). Other +# hosts must install virtiofsd, e.g. from their distribution (the package is +# virtiofsd on Fedora, Arch and recent Debian/Ubuntu). +# +# TODO: the download is the CI build of upstream's main branch, so it is +# neither pinned nor checked: virtiofsd releases do not ship binaries or +# checksums yet (their CI only builds main, and those artifacts expire). Once +# they do, pin it to a release and check its sha256 like Cloud Hypervisor in +# mk/ch.mk. share?= share_tag?=host share_sockdir?=$(BUILD) VIRTIOFS_RUN= +VIRTIOFS_DEPS= + +VIRTIOFSD_URL?=https://gitlab.com/virtio-fs/virtiofsd/-/jobs/artifacts/main/raw/target/x86_64-unknown-linux-musl/release/virtiofsd?job=publish +VIRTIOFSD_DOWNLOAD=build/virtiofsd/$(HOST_ARCH)/virtiofsd ifneq ($(strip $(share)),) share_norm:=$(foreach s,$(share),$(if $(filter redox redox:ro,$(s)),redox=$(ROOT)$(if $(filter %:ro,$(s)),:ro),$(s))) @@ -40,5 +57,28 @@ $(error share: every entry must be tag=dir when sharing several directories (bad vfs_tag=$(firstword $(subst =, ,$(call vfs_entry,$(1)))) vfs_sock=$(share_sockdir)/virtiofsd-$(1).sock - VIRTIOFS_RUN=scripts/virtiofs-run.sh $(foreach i,$(share_idx),--share "$(call vfs_sock,$(i))" "$(call vfs_entry,$(i))") -- + ifeq ($(strip $(VIRTIOFSD)),) + VIRTIOFSD:=$(firstword $(shell command -v virtiofsd 2>/dev/null) $(wildcard /usr/libexec/virtiofsd /usr/lib/qemu/virtiofsd) $(VIRTIOFSD_DOWNLOAD)) + endif + VIRTIOFS_DEPS=$(filter $(VIRTIOFSD_DOWNLOAD),$(VIRTIOFSD)) + + VIRTIOFS_RUN=VIRTIOFSD="$(VIRTIOFSD)" scripts/virtiofs-run.sh $(foreach i,$(share_idx),--share "$(call vfs_sock,$(i))" "$(call vfs_entry,$(i))") -- endif + +.PHONY: virtiofsd-fetch + +virtiofsd-fetch: $(VIRTIOFSD_DOWNLOAD) + +# Goes through $@.partial, so $@ only ever holds a complete ELF binary. +$(VIRTIOFSD_DOWNLOAD): + $(if $(and $(filter x86_64,$(HOST_ARCH)),$(filter Linux,$(shell uname -s))),,$(error virtiofsd: no prebuilt virtiofsd for this $(shell uname -s) $(HOST_ARCH) host. Install virtiofsd (e.g. dnf install virtiofsd or pacman -S virtiofsd) or set VIRTIOFSD=/path/to/virtiofsd)) + @echo "virtiofsd: downloading the CI build of upstream's main branch (not pinned or checked)" + mkdir -p "$(@D)" + curl -fL --retry 3 --retry-delay 1 -o "$@.partial" "$(VIRTIOFSD_URL)" + @if [ "$$(head -c 4 "$@.partial")" != "$$(printf '\177ELF')" ]; then \ + rm -f "$@.partial"; \ + echo "virtiofsd: the download is not an ELF binary (see $(VIRTIOFSD_URL))" >&2; \ + exit 1; \ + fi + chmod +x "$@.partial" + mv "$@.partial" "$@" diff --git a/podman_bootstrap.sh b/podman_bootstrap.sh index ddaec0de9..a1b2d30ed 100755 --- a/podman_bootstrap.sh +++ b/podman_bootstrap.sh @@ -472,116 +472,6 @@ solus() fi } -############################################################################### -# virtiofsd is needed on the host by `make qemu share=` to share -# directories with Redox (scripts/virtiofs-run.sh only looks for it). -############################################################################### -virtiofsd_find() -{ - local c - for c in "${VIRTIOFSD:-}" virtiofsd /usr/libexec/virtiofsd /usr/lib/qemu/virtiofsd \ - "${XDG_CACHE_HOME:-$HOME/.cache}/virtiofsd-redox/virtiofsd"; do - [ -n "$c" ] || continue - if [ -f "$c" ] && [ -x "$c" ]; then - echo "$c" - return 0 - fi - if command -v "$c" >/dev/null 2>&1; then - command -v "$c" - return 0 - fi - done - return 1 -} - -############################################################################### -# Download a static x86_64 virtiofsd build from the upstream CI into -# ~/.cache/virtiofsd-redox, after asking for confirmation. -# Override the source with VIRTIOFSD_URL. -# -# TODO: this is the CI build of upstream's main branch, so it is neither -# pinned nor checked: virtiofsd releases do not ship binaries or checksums -# yet. Once they do, move this download into mk/virtiofs.mk, pinned to a -# release and checked against its sha256 like Cloud Hypervisor in mk/ch.mk, -# and pass it to scripts/virtiofs-run.sh through VIRTIOFSD. -############################################################################### -virtiofsd_download() -{ - local url cache dest tmp answer - url="${VIRTIOFSD_URL:-https://gitlab.com/virtio-fs/virtiofsd/-/jobs/artifacts/main/raw/target/x86_64-unknown-linux-musl/release/virtiofsd?job=publish}" - cache="${XDG_CACHE_HOME:-$HOME/.cache}/virtiofsd-redox" - dest="$cache/virtiofsd" - - if [ "$(uname -m)" != "x86_64" ]; then - echo "No prebuilt virtiofsd is available for $(uname -m)." - return 1 - fi - echo "A static virtiofsd build can be downloaded from" - echo " gitlab.com/virtio-fs/virtiofsd (CI artifact of the main branch)" - echo "to $dest" - printf "Download it now? (y/N): " - read answer || answer="" - if ! echo "$answer" | grep -iq "^y"; then - return 1 - fi - - mkdir -p "$cache" - tmp="$(mktemp "$cache/virtiofsd.XXXXXX")" - if command -v curl >/dev/null 2>&1; then - curl -fL --retry 3 --retry-delay 1 -o "$tmp" "$url" || { rm -f "$tmp"; return 1; } - elif command -v wget >/dev/null 2>&1; then - wget -O "$tmp" "$url" || { rm -f "$tmp"; return 1; } - else - echo "Need curl or wget to download virtiofsd." - rm -f "$tmp" - return 1 - fi - if [ "$(head -c 4 "$tmp")" != "$(printf '\177ELF')" ]; then - echo "The download is not an ELF binary (see $url)." - rm -f "$tmp" - return 1 - fi - chmod +x "$tmp" - mv -f "$tmp" "$dest" - echo "virtiofsd installed at $dest" -} - -############################################################################### -# This function makes sure virtiofsd is available: it looks for an existing -# one, then tries the distribution package, then offers a download. -# It never fails the bootstrap, virtiofsd is only needed for `share=`. -# @params: $1 the package manager to use on Debian-based Linux -############################################################################### -virtiofsd_setup() -{ - local found - echo "Checking for virtiofsd (used by 'make qemu share=')..." - if found="$(virtiofsd_find)"; then - echo "virtiofsd found at $found" - return 0 - fi - echo "virtiofsd not found." - - if command -v pacman >/dev/null 2>&1; then - sudo pacman -S --needed virtiofsd || true - elif command -v dnf >/dev/null 2>&1; then - sudo dnf install virtiofsd || true - elif command -v apt-get >/dev/null 2>&1 && apt-cache show virtiofsd >/dev/null 2>&1; then - sudo "$1" install virtiofsd || true - fi - - if found="$(virtiofsd_find)"; then - echo "virtiofsd found at $found" - return 0 - fi - if virtiofsd_download; then - return 0 - fi - echo "Continuing without virtiofsd. 'make qemu share=' will not work until" - echo "it is installed (or set VIRTIOFSD=/path/to/virtiofsd), re-run this script" - echo "with -d to retry." -} - ###################################################################### # This function outlines the different options available for bootstrap ###################################################################### @@ -769,11 +659,6 @@ else fi fi -# Directory sharing with `make qemu share=` needs virtiofsd and a Linux host -if [ "$emulator" == "qemu" ] && [ "$(uname -s)" == "Linux" ]; then - virtiofsd_setup "$defpackman" -fi - if [ "$dependenciesonly" = false ]; then boot fi diff --git a/scripts/virtiofs-run.sh b/scripts/virtiofs-run.sh index 5c87d036f..9b069d7e9 100755 --- a/scripts/virtiofs-run.sh +++ b/scripts/virtiofs-run.sh @@ -71,15 +71,14 @@ done find_virtiofsd() { local c - for c in "${VIRTIOFSD:-}" virtiofsd /usr/libexec/virtiofsd /usr/lib/qemu/virtiofsd \ - "${XDG_CACHE_HOME:-${HOME:-/tmp}/.cache}/virtiofsd-redox/virtiofsd"; do + for c in "${VIRTIOFSD:-}" virtiofsd /usr/libexec/virtiofsd /usr/lib/qemu/virtiofsd; do [[ -n "${c}" ]] && command -v "${c}" && return 0 done return 1 } VIRTIOFSD_BIN="$(find_virtiofsd)" \ - || die "virtiofsd not found. Install it (e.g. 'dnf install virtiofsd' or 'pacman -S virtiofsd'), run ./podman_bootstrap.sh -d, or set VIRTIOFSD=/path/to/virtiofsd" + || die "virtiofsd not found. Install it (e.g. 'dnf install virtiofsd' or 'pacman -S virtiofsd'), run 'make virtiofsd-fetch' (x86_64 Linux hosts), or set VIRTIOFSD=/path/to/virtiofsd" PIDS=()