Skip to content

Commit 75443f8

Browse files
committed
allow overriding qemu binary ($QEMU_SYSTEM_X86_64, $QEMU_SYSTEM_AARCH64)
Passing args is also possible (only for debugging purpose), e.g., "QEMU_SYSTEM_X86_64=/opt/qemu/bin/qemu-system-x86_64 -snapshot" . Signed-off-by: Akihiro Suda <[email protected]>
1 parent 2405f30 commit 75443f8

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

docs/internal.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ The directory contains the following files:
5959
- `$LIMA_INSTANCE`: `lima ...` is expanded to `limactl shell ${LIMA_INSTANCE} ...`.
6060
- Default : `default`
6161

62+
- `$QEMU_SYSTEM_X86_64`: path of `qemu-system-x86_64`
63+
- Default: `qemu-system-x86_64` in `$PATH`
64+
65+
- `$QEMU_SYSTEM_AARCH64`: path of `qemu-system-aarch64`
66+
- Default: `qemu-system-aarch64` in `$PATH`
67+
6268
## `cidata.iso`
6369
`cidata.iso` contains the following files:
6470

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/gorilla/mux v1.8.0
1515
github.com/hashicorp/go-multierror v1.1.1
1616
github.com/mattn/go-isatty v0.0.13
17+
github.com/mattn/go-shellwords v1.0.12
1718
github.com/norouter/norouter v0.6.3
1819
github.com/nxadm/tail v1.4.8
1920
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1y
496496
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
497497
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
498498
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
499+
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
500+
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
499501
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
500502
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
501503
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=

pkg/qemu/qemu.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"path/filepath"
88
"runtime"
99
"strconv"
10+
"strings"
1011

1112
"github.com/AkihiroSuda/lima/pkg/downloader"
1213
"github.com/AkihiroSuda/lima/pkg/iso9660util"
1314
"github.com/AkihiroSuda/lima/pkg/limayaml"
1415
"github.com/AkihiroSuda/lima/pkg/store/filenames"
1516
"github.com/docker/go-units"
17+
"github.com/mattn/go-shellwords"
1618
"github.com/pkg/errors"
1719
"github.com/sirupsen/logrus"
1820
)
@@ -83,12 +85,10 @@ func EnsureDisk(cfg Config) error {
8385

8486
func Cmdline(cfg Config) (string, []string, error) {
8587
y := cfg.LimaYAML
86-
exeBase := "qemu-system-" + y.Arch
87-
exe, err := exec.LookPath(exeBase)
88+
exe, args, err := getExe(y.Arch)
8889
if err != nil {
8990
return "", nil, err
9091
}
91-
var args []string
9292

9393
// Architecture
9494
accel := getAccel(y.Arch)
@@ -205,6 +205,27 @@ func Cmdline(cfg Config) (string, []string, error) {
205205
return exe, args, nil
206206
}
207207

208+
func getExe(arch limayaml.Arch) (string, []string, error) {
209+
exeBase := "qemu-system-" + arch
210+
var args []string
211+
envK := "QEMU_SYSTEM_" + strings.ToUpper(arch)
212+
if envV := os.Getenv(envK); envV != "" {
213+
ss, err := shellwords.Parse(envV)
214+
if err != nil {
215+
return "", nil, errors.Wrapf(err, "failed to parse %s value %q", envK, envV)
216+
}
217+
exeBase, args = ss[0], ss[1:]
218+
if len(args) != 0 {
219+
logrus.Warnf("Specifying args (%v) via $%s is supported only for debugging!", args, envK)
220+
}
221+
}
222+
exe, err := exec.LookPath(exeBase)
223+
if err != nil {
224+
return "", nil, err
225+
}
226+
return exe, args, nil
227+
}
228+
208229
func getAccel(arch limayaml.Arch) string {
209230
nativeX8664 := arch == limayaml.X8664 && runtime.GOARCH == "amd64"
210231
nativeAARCH64 := arch == limayaml.AARCH64 && runtime.GOARCH == "arm64"

0 commit comments

Comments
 (0)