From e27774cb441ebdacc0ea36b2eb71ccf3323f6208 Mon Sep 17 00:00:00 2001 From: Misha Sakhnov Date: Wed, 16 Oct 2024 16:03:45 +0200 Subject: [PATCH 1/5] vm-builder: vm-builder builds arch images Add arm support to vm-builder without cross-compilation --- Makefile | 24 ++++++++++++++++++------ vm-builder/files/Dockerfile.img | 21 +++++++++++++-------- vm-builder/files/inittab | 2 +- vm-builder/main.go | 5 +++-- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index f420d01f6..1ffb4390e 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ GOOS ?= $(shell go env GOOS) # The target architecture for linux kernel. Possible values: amd64 or arm64. # Any other supported by linux kernel architecture could be added by introducing new build step into neonvm/hack/kernel/Dockerfile.kernel-builder KERNEL_TARGET_ARCH ?= amd64 - +TARGET_ARCH ?= amd64 # Get the currently used golang base path GOPATH=$(shell go env GOPATH) # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) @@ -188,6 +188,7 @@ docker-build-controller: docker-build-go-base ## Build docker image for NeonVM c docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runner docker build \ --tag $(IMG_RUNNER) \ + --build-arg TARGET_ARCH=$(TARGET_ARCH) \ --build-arg GO_BASE_IMG=$(GO_BASE_IMG) \ --file neonvm-runner/Dockerfile \ . @@ -196,6 +197,7 @@ docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runne docker-build-daemon: docker-build-go-base ## Build docker image for NeonVM daemon. docker build \ --tag $(IMG_DAEMON) \ + --build-arg TARGET_ARCH=$(TARGET_ARCH) \ --file neonvm-daemon/Dockerfile \ . @@ -228,11 +230,11 @@ docker-build-scheduler: docker-build-go-base ## Build docker image for (autoscal .PHONY: docker-build-examples docker-build-examples: bin/vm-builder ## Build docker images for testing VMs - ./bin/vm-builder -src postgres:15-bullseye -dst $(E2E_TESTS_VM_IMG) -spec tests/e2e/image-spec.yaml + ./bin/vm-builder -src postgres:15-bullseye -dst $(E2E_TESTS_VM_IMG) -spec tests/e2e/image-spec.yaml -target-arch linux/$(TARGET_ARCH) .PHONY: docker-build-pg16-disk-test docker-build-pg16-disk-test: bin/vm-builder ## Build a VM image for testing - ./bin/vm-builder -src alpine:3.19 -dst $(PG16_DISK_TEST_IMG) -spec vm-examples/pg16-disk-test/image-spec.yaml + ./bin/vm-builder -src alpine:3.19 -dst $(PG16_DISK_TEST_IMG) -spec vm-examples/pg16-disk-test/image-spec.yaml -target-arch linux/$(TARGET_ARCH) #.PHONY: docker-push #docker-push: ## Push docker image with the controller. @@ -394,6 +396,10 @@ load-example-vms: check-local-context kubectl kind k3d ## Load the testing VM im .PHONY: example-vms example-vms: docker-build-examples load-example-vms ## Build and push the testing VM images to the kind/k3d cluster. +.PHONY: example-vms-arm64 +example-vms-arm64: TARGET_ARCH=arm64 +example-vms-arm64: example-vms + .PHONY: load-pg16-disk-test load-pg16-disk-test: check-local-context kubectl kind k3d ## Load the pg16-disk-test VM image to the kind/k3d cluster. @if [ $$($(KUBECTL) config current-context) = k3d-$(CLUSTER_NAME) ]; then $(K3D) image import $(PG16_DISK_TEST_IMG) --cluster $(CLUSTER_NAME) --mode direct; fi @@ -492,8 +498,14 @@ CODE_GENERATOR_VERSION ?= v0.28.12 KUTTL ?= $(LOCALBIN)/kuttl # k8s deps @ 1.28.3 -KUTTL_VERSION ?= v0.16.0 - +KUTTL_VERSION ?= v0.19.0 +ifeq ($(GOARCH), arm64) + KUTTL_ARCH = arm64 +else ifeq ($(GOARCH), amd64) + KUTTL_ARCH = x86_64 +else + $(error Unsupported architecture: $(GOARCH)) +endif KUBECTL ?= $(LOCALBIN)/kubectl KUBECTL_VERSION ?= v1.29.10 @@ -535,7 +547,7 @@ $(KUBECTL): $(LOCALBIN) .PHONY: kuttl kuttl: $(KUTTL) ## Download kuttl locally if necessary. $(KUTTL): $(LOCALBIN) - @test -s $(LOCALBIN)/kuttl || { curl -sfSLo $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/$(KUTTL_VERSION)/kubectl-kuttl_$(subst v,,$(KUTTL_VERSION))_$(GOOS)_$(shell uname -m) && chmod +x $(KUTTL); } + test -s $(LOCALBIN)/kuttl || { curl -sfSLo $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/$(KUTTL_VERSION)/kubectl-kuttl_$(subst v,,$(KUTTL_VERSION))_$(GOOS)_$(KUTTL_ARCH) && chmod +x $(KUTTL); } .PHONY: k3d k3d: $(K3D) ## Download k3d locally if necessary. diff --git a/vm-builder/files/Dockerfile.img b/vm-builder/files/Dockerfile.img index b72027975..990ae8617 100644 --- a/vm-builder/files/Dockerfile.img +++ b/vm-builder/files/Dockerfile.img @@ -9,16 +9,19 @@ USER root FROM {{.NeonvmDaemonImage}} AS neonvm-daemon-loader +FROM busybox:1.35.0-musl AS busybox-loader + FROM alpine:3.19 AS vm-runtime +ARG TARGET_ARCH +RUN set -e && mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config # add busybox -ENV BUSYBOX_VERSION 1.35.0 +COPY --from=busybox-loader /bin/busybox /neonvm/bin/busybox + RUN set -e \ - && mkdir -p /neonvm/bin /neonvm/runtime /neonvm/config \ - && wget -q https://busybox.net/downloads/binaries/${BUSYBOX_VERSION}-x86_64-linux-musl/busybox -O /neonvm/bin/busybox \ - && chmod +x /neonvm/bin/busybox \ - && /neonvm/bin/busybox --install -s /neonvm/bin + chmod +x /neonvm/bin/busybox \ + && /neonvm/bin/busybox --install -s /neonvm/bin -COPY helper.move-bins.sh /helper.move-bins.sh + COPY helper.move-bins.sh /helper.move-bins.sh # add udevd and agetty (with shared libs) RUN set -e \ @@ -49,8 +52,10 @@ RUN set -e \ # Install vector.dev binary RUN set -e \ - && wget https://packages.timber.io/vector/0.26.0/vector-0.26.0-x86_64-unknown-linux-musl.tar.gz -O - \ - | tar xzvf - --strip-components 3 -C /neonvm/bin/ ./vector-x86_64-unknown-linux-musl/bin/vector + && ARCH=$( [ "$TARGET_ARCH" = "linux/arm64" ] && echo "aarch64" || echo "x86_64") \ + && wget https://packages.timber.io/vector/0.26.0/vector-${ARCH}-unknown-linux-musl.tar.gz -O - \ + | tar xzvf - --strip-components 3 -C /neonvm/bin/ ./vector-${ARCH}-unknown-linux-musl/bin/vector + # chrony RUN set -e \ diff --git a/vm-builder/files/inittab b/vm-builder/files/inittab index bc59e8404..9f7c284ec 100644 --- a/vm-builder/files/inittab +++ b/vm-builder/files/inittab @@ -12,5 +12,5 @@ {{ range .InittabCommands }} ::{{.SysvInitAction}}:su -p {{.CommandUser}} -c {{.ShellEscapedCommand}} {{ end }} -ttyS0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyS0 linux +ttyAMA0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyAMA0 linux ::shutdown:/neonvm/bin/vmshutdown diff --git a/vm-builder/main.go b/vm-builder/main.go index 3c379aa4c..439c182ea 100644 --- a/vm-builder/main.go +++ b/vm-builder/main.go @@ -72,6 +72,7 @@ var ( version = flag.Bool("version", false, `Print vm-builder version`) daemonImageFlag = flag.String("daemon-image", "", `Specify the neonvm-daemon image: --daemon-image=neonvm-daemon:dev`) + targetArch = flag.String("target-arch", "linux/amd64", `Target architecture: --arch linux/amd64`) ) func AddTemplatedFileToTar(tw *tar.Writer, tmplArgs any, filename string, tmplString string) error { @@ -84,7 +85,6 @@ func AddTemplatedFileToTar(tw *tar.Writer, tmplArgs any, filename string, tmplSt if err = tmpl.Execute(&buf, tmplArgs); err != nil { return fmt.Errorf("failed to execute template for %q: %w", filename, err) } - return addFileToTar(tw, filename, buf.Bytes()) } @@ -129,7 +129,6 @@ type inittabCommand struct { func main() { flag.Parse() var dstIm string - if *version { fmt.Println(Version) os.Exit(0) @@ -366,6 +365,7 @@ func main() { buildArgs := make(map[string]*string) buildArgs["DISK_SIZE"] = size + buildArgs["TARGET_ARCH"] = targetArch opt := types.ImageBuildOptions{ AuthConfigs: authConfigs, Tags: []string{dstIm}, @@ -376,6 +376,7 @@ func main() { Dockerfile: "Dockerfile", Remove: true, ForceRemove: true, + Platform: *targetArch, } buildResp, err := cli.ImageBuild(ctx, tarBuffer, opt) if err != nil { From 6cf110ec8553f961459d72d0663ec334abe8d1f7 Mon Sep 17 00:00:00 2001 From: Misha Sakhnov Date: Thu, 17 Oct 2024 13:14:54 +0200 Subject: [PATCH 2/5] vm-builder: agetty init per architecture --- vm-builder/files/Dockerfile.img | 2 +- vm-builder/files/agetty-init-amd64 | 1 + vm-builder/files/agetty-init-arm64 | 1 + vm-builder/files/inittab | 2 +- vm-builder/main.go | 42 +++++++++++++++++++++++++++--- 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 vm-builder/files/agetty-init-amd64 create mode 100644 vm-builder/files/agetty-init-arm64 diff --git a/vm-builder/files/Dockerfile.img b/vm-builder/files/Dockerfile.img index 990ae8617..0abed8262 100644 --- a/vm-builder/files/Dockerfile.img +++ b/vm-builder/files/Dockerfile.img @@ -21,7 +21,7 @@ RUN set -e \ chmod +x /neonvm/bin/busybox \ && /neonvm/bin/busybox --install -s /neonvm/bin - COPY helper.move-bins.sh /helper.move-bins.sh +COPY helper.move-bins.sh /helper.move-bins.sh # add udevd and agetty (with shared libs) RUN set -e \ diff --git a/vm-builder/files/agetty-init-amd64 b/vm-builder/files/agetty-init-amd64 new file mode 100644 index 000000000..894a24ae4 --- /dev/null +++ b/vm-builder/files/agetty-init-amd64 @@ -0,0 +1 @@ +ttyS0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyS0 linux diff --git a/vm-builder/files/agetty-init-arm64 b/vm-builder/files/agetty-init-arm64 new file mode 100644 index 000000000..713a4f669 --- /dev/null +++ b/vm-builder/files/agetty-init-arm64 @@ -0,0 +1 @@ +ttyAMA0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyAMA0 linux diff --git a/vm-builder/files/inittab b/vm-builder/files/inittab index 9f7c284ec..e9ef19f1c 100644 --- a/vm-builder/files/inittab +++ b/vm-builder/files/inittab @@ -12,5 +12,5 @@ {{ range .InittabCommands }} ::{{.SysvInitAction}}:su -p {{.CommandUser}} -c {{.ShellEscapedCommand}} {{ end }} -ttyAMA0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyAMA0 linux +{{ .AgettyInitLine }} ::shutdown:/neonvm/bin/vmshutdown diff --git a/vm-builder/main.go b/vm-builder/main.go index 439c182ea..13e3f1aff 100644 --- a/vm-builder/main.go +++ b/vm-builder/main.go @@ -38,6 +38,10 @@ var ( scriptVmStart string //go:embed files/inittab scriptInitTab string + //go:embed files/agetty-init-amd64 + scriptAgettyInitAmd64 string + //go:embed files/agetty-init-arm64 + scriptAgettyInitArm64 string //go:embed files/vmacpi scriptVmAcpi string //go:embed files/vmshutdown @@ -58,6 +62,11 @@ var ( configSshd string ) +const ( + targetArchLinuxAmd64 = "linux/amd64" + targetArchLinuxArm64 = "linux/arm64" +) + var ( Version string NeonvmDaemonImage string @@ -72,7 +81,7 @@ var ( version = flag.Bool("version", false, `Print vm-builder version`) daemonImageFlag = flag.String("daemon-image", "", `Specify the neonvm-daemon image: --daemon-image=neonvm-daemon:dev`) - targetArch = flag.String("target-arch", "linux/amd64", `Target architecture: --arch linux/amd64`) + targetArch = flag.String("target-arch", "", fmt.Sprintf("Target architecture: --arch %s | %s", targetArchLinuxAmd64, targetArchLinuxArm64)) ) func AddTemplatedFileToTar(tw *tar.Writer, tmplArgs any, filename string, tmplString string) error { @@ -117,6 +126,7 @@ type TemplatesContext struct { SpecBuild string SpecMerge string InittabCommands []inittabCommand + AgettyInitLine string ShutdownHook string } @@ -133,13 +143,24 @@ func main() { fmt.Println(Version) os.Exit(0) } - if len(*daemonImageFlag) == 0 && len(NeonvmDaemonImage) == 0 { log.Println("neonvm-daemon image not set, needs to be explicitly passed in, or compiled with -ldflags '-X main.NeonvmDaemonImage=...'") flag.PrintDefaults() os.Exit(1) } + if targetArch == nil || *targetArch == "" { + log.Println("Target architecture not set, see usage info:") + flag.PrintDefaults() + os.Exit(1) + } + + if *targetArch != targetArchLinuxAmd64 && *targetArch != targetArchLinuxArm64 { + log.Fatalf("Unsupported target architecture: %q", *targetArch) + flag.PrintDefaults() + return + } + neonvmDaemonImage := NeonvmDaemonImage if len(*daemonImageFlag) != 0 { neonvmDaemonImage = *daemonImageFlag @@ -290,7 +311,8 @@ func main() { SpecBuild: "", // overridden below if spec != nil SpecMerge: "", // overridden below if spec != nil InittabCommands: nil, // overridden below if spec != nil - ShutdownHook: "", // overridden below if spec != nil + AgettyInitLine: getAgettyInitLine(*targetArch), + ShutdownHook: "", // overridden below if spec != nil } if len(imageSpec.Config.User) != 0 { @@ -347,6 +369,8 @@ func main() { {"vmstart", scriptVmStart}, {"vmshutdown", scriptVmShutdown}, {"inittab", scriptInitTab}, + {"agetty-init-amd64", scriptAgettyInitAmd64}, + {"agetty-init-arm64", scriptAgettyInitArm64}, {"vmacpi", scriptVmAcpi}, {"vminit", scriptVmInit}, {"vector.yaml", configVector}, @@ -542,3 +566,15 @@ func (f file) validate() []error { return errs } + +func getAgettyInitLine(targetArch string) string { + switch targetArch { + case targetArchLinuxAmd64: + return scriptAgettyInitAmd64 + case targetArchLinuxArm64: + return scriptAgettyInitArm64 + default: + log.Fatalf("Unsupported target architecture: %q", targetArch) + return "" + } +} From 1b444ab7b7caac6931dca9c9dd378c5e9f2baa6b Mon Sep 17 00:00:00 2001 From: Misha Sakhnov Date: Mon, 21 Oct 2024 13:06:05 +0200 Subject: [PATCH 3/5] vm-builder,ci: pass target arch as vm-builder argument --- .github/workflows/build-test-vm.yaml | 3 ++- .github/workflows/vm-example.yaml | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-test-vm.yaml b/.github/workflows/build-test-vm.yaml index c63c5c4eb..d6d0eec87 100644 --- a/.github/workflows/build-test-vm.yaml +++ b/.github/workflows/build-test-vm.yaml @@ -31,6 +31,7 @@ env: IMG_POSTGRES_16_BULLSEYE: "neondatabase/vm-postgres-16-bullseye" # using image built in the same workflow IMG_DAEMON: "neondatabase/neonvm-daemon" + TARGET_ARCH: "amd64" defaults: run: @@ -87,7 +88,7 @@ jobs: - name: build ${{ needs.tags.outputs.vm-postgres-16-bullseye }} run: | - ./bin/vm-builder -src postgres:16-bullseye -spec tests/e2e/image-spec.yaml -dst ${{ needs.tags.outputs.vm-postgres-16-bullseye }} -daemon-image ${{ needs.tags.outputs.daemon }} + ./bin/vm-builder -src postgres:16-bullseye -spec tests/e2e/image-spec.yaml -dst ${{ needs.tags.outputs.vm-postgres-16-bullseye }} -daemon-image ${{ needs.tags.outputs.daemon }} -target-arch linux/${TARGET_ARCH} - name: docker push ${{ needs.tags.outputs.vm-postgres-16-bullseye }} run: | docker push ${{ needs.tags.outputs.vm-postgres-16-bullseye }} diff --git a/.github/workflows/vm-example.yaml b/.github/workflows/vm-example.yaml index 0b2387a22..3125c5587 100644 --- a/.github/workflows/vm-example.yaml +++ b/.github/workflows/vm-example.yaml @@ -8,6 +8,9 @@ on: - ".github/workflows/vm-example.yaml" workflow_dispatch: # adds ability to run this manually +env: + TARGET_ARCH: amd64 + jobs: vm-example: runs-on: ubuntu-latest @@ -37,26 +40,26 @@ jobs: password: ${{ secrets.NEON_DOCKERHUB_PASSWORD }} - name: build vm-alpine:3.16 - run: bin/vm-builder -src alpine:3.16 -dst neondatabase/vm-alpine:3.16 + run: bin/vm-builder -src alpine:3.16 -dst neondatabase/vm-alpine:3.16 -target-arch linux/${TARGET_ARCH} - name: push vm-alpine:3.16 run: docker push -q neondatabase/vm-alpine:3.16 - name: build vm-ubuntu:22.04 - run: bin/vm-builder -src ubuntu:22.04 -dst neondatabase/vm-ubuntu:22.04 + run: bin/vm-builder -src ubuntu:22.04 -dst neondatabase/vm-ubuntu:22.04 -target-arch linux/${TARGET_ARCH} - name: push vm-ubuntu:22.04 run: docker push -q neondatabase/vm-ubuntu:22.04 - name: build vm-debian:11 - run: bin/vm-builder -src debian:11 -dst neondatabase/vm-debian:11 + run: bin/vm-builder -src debian:11 -dst neondatabase/vm-debian:11 -target-arch linux/${TARGET_ARCH} - name: push vm-debian:11 run: docker push -q neondatabase/vm-debian:11 - name: build vm-postgres:14-alpine - run: bin/vm-builder -src postgres:14-alpine -dst neondatabase/vm-postgres:14-alpine + run: bin/vm-builder -src postgres:14-alpine -dst neondatabase/vm-postgres:14-alpine -target-arch linux/${TARGET_ARCH} - name: push vm-postgres:14-alpine run: docker push -q neondatabase/vm-postgres:14-alpine - name: build vm-postgres:15-alpine - run: bin/vm-builder -src postgres:15-alpine -dst neondatabase/vm-postgres:15-alpine + run: bin/vm-builder -src postgres:15-alpine -dst neondatabase/vm-postgres:15-alpine -target-arch linux/${TARGET_ARCH} - name: push vm-postgres:15-alpine run: docker push -q neondatabase/vm-postgres:15-alpine From 4c303be82d6e738ac5613fe904f3df500ef1bbeb Mon Sep 17 00:00:00 2001 From: Misha Sakhnov Date: Tue, 22 Oct 2024 12:06:30 +0200 Subject: [PATCH 4/5] vm-builder: drop unused variables, format code Signed-off-by: Misha Sakhnov --- Makefile | 1 - vm-builder/main.go | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1ffb4390e..f1ed063a8 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,6 @@ docker-build-controller: docker-build-go-base ## Build docker image for NeonVM c docker-build-runner: docker-build-go-base ## Build docker image for NeonVM runner docker build \ --tag $(IMG_RUNNER) \ - --build-arg TARGET_ARCH=$(TARGET_ARCH) \ --build-arg GO_BASE_IMG=$(GO_BASE_IMG) \ --file neonvm-runner/Dockerfile \ . diff --git a/vm-builder/main.go b/vm-builder/main.go index 13e3f1aff..2cd76d994 100644 --- a/vm-builder/main.go +++ b/vm-builder/main.go @@ -311,8 +311,8 @@ func main() { SpecBuild: "", // overridden below if spec != nil SpecMerge: "", // overridden below if spec != nil InittabCommands: nil, // overridden below if spec != nil + ShutdownHook: "", // overridden below if spec != nil AgettyInitLine: getAgettyInitLine(*targetArch), - ShutdownHook: "", // overridden below if spec != nil } if len(imageSpec.Config.User) != 0 { @@ -369,8 +369,6 @@ func main() { {"vmstart", scriptVmStart}, {"vmshutdown", scriptVmShutdown}, {"inittab", scriptInitTab}, - {"agetty-init-amd64", scriptAgettyInitAmd64}, - {"agetty-init-arm64", scriptAgettyInitArm64}, {"vmacpi", scriptVmAcpi}, {"vminit", scriptVmInit}, {"vector.yaml", configVector}, From 5bee7bc9ad8db238c2d72b43909a00c518697f27 Mon Sep 17 00:00:00 2001 From: Mikhail Sakhnov Date: Tue, 10 Dec 2024 08:59:10 +0100 Subject: [PATCH 5/5] neonvm-builder: apply code review requests Rollback kuttl version Simplify agetty init line passing --- Makefile | 2 +- vm-builder/files/agetty-init-amd64 | 1 - vm-builder/files/agetty-init-arm64 | 1 - vm-builder/files/inittab | 2 +- vm-builder/main.go | 15 ++++++--------- 5 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 vm-builder/files/agetty-init-amd64 delete mode 100644 vm-builder/files/agetty-init-arm64 diff --git a/Makefile b/Makefile index f1ed063a8..2d5ff8577 100644 --- a/Makefile +++ b/Makefile @@ -497,7 +497,7 @@ CODE_GENERATOR_VERSION ?= v0.28.12 KUTTL ?= $(LOCALBIN)/kuttl # k8s deps @ 1.28.3 -KUTTL_VERSION ?= v0.19.0 +KUTTL_VERSION ?= v0.16.0 ifeq ($(GOARCH), arm64) KUTTL_ARCH = arm64 else ifeq ($(GOARCH), amd64) diff --git a/vm-builder/files/agetty-init-amd64 b/vm-builder/files/agetty-init-amd64 deleted file mode 100644 index 894a24ae4..000000000 --- a/vm-builder/files/agetty-init-amd64 +++ /dev/null @@ -1 +0,0 @@ -ttyS0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyS0 linux diff --git a/vm-builder/files/agetty-init-arm64 b/vm-builder/files/agetty-init-arm64 deleted file mode 100644 index 713a4f669..000000000 --- a/vm-builder/files/agetty-init-arm64 +++ /dev/null @@ -1 +0,0 @@ -ttyAMA0::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 ttyAMA0 linux diff --git a/vm-builder/files/inittab b/vm-builder/files/inittab index e9ef19f1c..92ffeb43d 100644 --- a/vm-builder/files/inittab +++ b/vm-builder/files/inittab @@ -12,5 +12,5 @@ {{ range .InittabCommands }} ::{{.SysvInitAction}}:su -p {{.CommandUser}} -c {{.ShellEscapedCommand}} {{ end }} -{{ .AgettyInitLine }} +{{ .AgettyTTY }}::respawn:/neonvm/bin/agetty --8bits --local-line --noissue --noclear --noreset --host console --login-program /neonvm/bin/login --login-pause --autologin root 115200 {{ .AgettyTTY }} linux ::shutdown:/neonvm/bin/vmshutdown diff --git a/vm-builder/main.go b/vm-builder/main.go index 2cd76d994..7cdd17623 100644 --- a/vm-builder/main.go +++ b/vm-builder/main.go @@ -38,10 +38,6 @@ var ( scriptVmStart string //go:embed files/inittab scriptInitTab string - //go:embed files/agetty-init-amd64 - scriptAgettyInitAmd64 string - //go:embed files/agetty-init-arm64 - scriptAgettyInitArm64 string //go:embed files/vmacpi scriptVmAcpi string //go:embed files/vmshutdown @@ -126,7 +122,7 @@ type TemplatesContext struct { SpecBuild string SpecMerge string InittabCommands []inittabCommand - AgettyInitLine string + AgettyTTY string ShutdownHook string } @@ -312,7 +308,7 @@ func main() { SpecMerge: "", // overridden below if spec != nil InittabCommands: nil, // overridden below if spec != nil ShutdownHook: "", // overridden below if spec != nil - AgettyInitLine: getAgettyInitLine(*targetArch), + AgettyTTY: getAgettyTTY(*targetArch), } if len(imageSpec.Config.User) != 0 { @@ -565,12 +561,13 @@ func (f file) validate() []error { return errs } -func getAgettyInitLine(targetArch string) string { +// getAgettyTTY returns the tty device name for agetty based on the target architecture. +func getAgettyTTY(targetArch string) string { switch targetArch { case targetArchLinuxAmd64: - return scriptAgettyInitAmd64 + return "ttyS0" case targetArchLinuxArm64: - return scriptAgettyInitArm64 + return "ttyAMA0" default: log.Fatalf("Unsupported target architecture: %q", targetArch) return ""