[Libguestfs] [PATCH] customize: Use setarch when running commands on i686 guest (RHBZ#1256405).
Richard W.M. Jones
rjones at redhat.com
Thu Aug 27 16:38:50 UTC 2015
On Thu, Aug 27, 2015 at 05:32:31PM +0100, Richard W.M. Jones wrote:
> When running (eg) dnf on a 32 bit i686 guest when the host is 64 bit
> x86_64, dnf believes it is running on a 64 bit machine and so tries to
> install x86_64 packages. We can 'trick' dnf into believing it's a 32
> bit machine using the setarch program.
>
> $ virt-builder fedora-22 --arch i686 --install 'gperf'
> ...
> [ 27.4] Installing packages: gperf
> ...
> Running transaction test
> Error: Transaction check error:
> package libgcc-5.1.1-4.fc22.x86_64 is intended for a different architecture
> ...
>
> Thanks: Jan Sedlák for finding the solution.
> ---
> customize/customize_run.ml | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/customize/customize_run.ml b/customize/customize_run.ml
> index 828c711..2a4c71e 100644
> --- a/customize/customize_run.ml
> +++ b/customize/customize_run.ml
> @@ -59,6 +59,7 @@ let run (g : Guestfs.guestfs) root (ops : ops) =
> * - Pass environment variables through from the host.
> * - Send stdout and stderr to a log file so we capture all output
> * in error messages.
> + * - Use setarch when running x86_64 host + i686 guest.
> * Also catch errors and dump the log file completely on error.
> *)
> let env_vars =
> @@ -69,11 +70,16 @@ let run (g : Guestfs.guestfs) root (ops : ops) =
> ) [ "http_proxy"; "https_proxy"; "ftp_proxy"; "no_proxy" ] in
> let env_vars = String.concat "\n" env_vars ^ "\n" in
>
> + let setarch =
> + match Config.host_cpu, guest_arch with
> + | "x86_64", ("i386"|"i486"|"i586"|"i686") -> "setarch i686"
> + | _ -> "" in
> +
> let cmd = sprintf "\
> exec >>%s 2>&1
> %s
> -%s
> -" (quote logfile) env_vars cmd in
> +%s %s
> +" (quote logfile) env_vars setarch cmd in
Unfortunately this doesn't work if the 'cmd' is actually
multiple commands. For example if the command was:
uname -m ; uname -m
then this would be turned into:
setarch i686 uname -m ; uname -m
and that would print:
i686
x86_64
It's tricky because setarch always wants to create a new shell.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list