Skip to content

Commit a68aabc

Browse files
committed
virtme-ng: auto-detect host architecture
Instead of implicitly assuming amd64 as the host architecture, detect it automatically so the user doesn't need to manually specify --arch on non-amd64 systems. This fixes issue #173. Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
1 parent e5d641c commit a68aabc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

virtme_ng/run.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import argparse
77
import re
88
import os
9+
import platform
910
import sys
1011
import socket
1112
import shutil
@@ -564,6 +565,20 @@ def create_root(destdir, arch, release):
564565
os.chdir(prevdir)
565566

566567

568+
def get_host_arch():
569+
"""Translate host architecture to the corresponding virtme-ng arch name."""
570+
arch = platform.machine()
571+
arch_map = {
572+
'x86_64': 'amd64',
573+
'aarch64': 'arm64',
574+
'armv7l': 'armhf',
575+
'ppc64le': 'ppc64el',
576+
'riscv64': 'riscv64',
577+
's390x': 's390x',
578+
}
579+
return arch_map.get(arch, None)
580+
581+
567582
class KernelSource:
568583
"""Main class that implement actions to perform on a kernel source directory."""
569584

@@ -829,7 +844,7 @@ def _get_virtme_arch(self, args):
829844

830845
def _get_virtme_root(self, args):
831846
if args.root is not None:
832-
create_root(args.root, args.arch or "amd64", args.root_release)
847+
create_root(args.root, args.arch or get_host_arch(), args.root_release)
833848
self.virtme_param["root"] = f"--root {args.root}"
834849
else:
835850
self.virtme_param["root"] = ""
@@ -880,7 +895,7 @@ def _get_virtme_run(self, args):
880895
# repository.
881896
if re.match(r'^v\d+(\.\d+)*(-rc\d+)?$', args.run):
882897
if args.arch is None:
883-
arch = 'amd64'
898+
arch = get_host_arch()
884899
else:
885900
arch = args.arch
886901
try:

0 commit comments

Comments
 (0)