[Libguestfs] [PATCH 1/2] customize: Give a clear error message if host_cpu not compatible with guest arch.

Richard W.M. Jones rjones at redhat.com
Fri May 15 09:08:09 UTC 2015


In cases where we are asked to run commands in the guest (eg.  options
such as --run-command or --install), give a clear error in the cases
where the guest arch is not compatible with the host arch.
---
 customize/customize_run.ml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 08cff0b..0f1d72a 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -30,6 +30,19 @@ let run ~verbose ~quiet (g : Guestfs.guestfs) root (ops : ops) =
   (* Timestamped messages in ordinary, non-debug non-quiet mode. *)
   let msg fs = make_message_function ~quiet fs in
 
+  (* Is the host_cpu compatible with the guest arch?  ie. Can we
+   * run commands in this guest?
+   *)
+  let guest_arch = g#inspect_get_arch root in
+  let guest_arch_compatible =
+    match Config.host_cpu, guest_arch with
+    | x, y when x = y -> true
+    | "x86_64", ("i386"|"i486"|"i586"|"i686") -> true
+    (* In theory aarch64 host could run armv7l commands, but it won't
+     * work without libvirt changes.  XXX
+     *)
+    | _ -> false in
+
   (* Based on the guest type, choose a log file location. *)
   let logfile =
     match g#inspect_get_type root with
@@ -53,6 +66,10 @@ let run ~verbose ~quiet (g : Guestfs.guestfs) root (ops : ops) =
 
   (* Useful wrapper for scripts. *)
   let do_run ~display cmd =
+    if not guest_arch_compatible then
+      error (f_"host cpu (%s) and guest arch (%s) are not compatible, so you cannot use command line options that involve running commands in the guest.  Use --firstboot scripts instead.")
+            Config.host_cpu guest_arch;
+
     (* Add a prologue to the scripts:
      * - Pass environment variables through from the host.
      * - Send stdout and stderr to a log file so we capture all output
-- 
2.3.1




More information about the Libguestfs mailing list