All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Matteo Croce <mcroce@linux.microsoft.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: add option to chroot before emulation
Date: Tue, 8 Dec 2020 19:25:11 +0100	[thread overview]
Message-ID: <5b7460b5-922e-3208-0c8a-161baf8b9c55@vivier.eu> (raw)
In-Reply-To: <CAFnufp1QkXMxMwVksczL8jSHET2zwLSgv4Lm34MgqWd5jyYTNA@mail.gmail.com>

Le 08/12/2020 à 17:04, Matteo Croce a écrit :
> On Tue, Dec 8, 2020 at 9:21 AM Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> Le 08/12/2020 à 01:17, Matteo Croce a écrit :
>>> From: Matteo Croce <mcroce@microsoft.com>
>>>
>>> Add a '-c' option which does a chroot() just before starting the
>>> emulation. This is useful when the static QEMU user binary can't
>>> be copied into the target root filesystem, e.g. if it's readonly.
>>
>> Did you try to use the binfmt_misc 'F' flag (fix binary)?
>>
>> https://www.kernel.org/doc/Documentation/admin-guide/binfmt-misc.rst
>>
>> ``F`` - fix binary
>>
>> The usual behaviour of binfmt_misc is to spawn the
>> binary lazily when the misc format file is invoked.  However,
>> this doesn``t work very well in the face of mount namespaces and
>> changeroots, so the ``F`` mode opens the binary as soon as the
>> emulation is installed and uses the opened image to spawn the
>> emulator, meaning it is always available once installed,
>> regardless of how the environment changes.
>>
>> This can be configured with scripts/qemu-binfmt-conf.sh and
>> "--persistent yes"" option
>>
> 
> Yes, this works too.
> Basically it's the same trick, open the binary early and then emulate.
> The only difference is that with binfmt emulation the procfs open
> still fails:
> 
> # strace -feopenat chroot debian /bin/true 2>&1 |grep /proc/sys
> [pid  9359] openat(AT_FDCWD, "/proc/sys/vm/mmap_min_addr", O_RDONLY) =
> -1 ENOENT (No such file or directory)
> 
> vs
> 
> # strace -feopenat qemu-aarch64 -c debian /bin/true 2>&1 |grep /proc/sys
> [pid  9348] openat(AT_FDCWD, "/proc/sys/vm/mmap_min_addr", O_RDONLY) = 3
> 

If you want to have the /proc mounted earlier you can use "unshare".

something like:

unshare --mount-proc -R debian /bin/true

There is also the "-L" option, something like:

qemu-aarch64 -L debian debian/bin/true

Thanks,
Laurent


      reply	other threads:[~2020-12-08 18:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  0:17 [PATCH] linux-user: add option to chroot before emulation Matteo Croce
2020-12-08  2:09 ` no-reply
2020-12-08  8:21 ` Laurent Vivier
2020-12-08 16:04   ` Matteo Croce
2020-12-08 18:25     ` Laurent Vivier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5b7460b5-922e-3208-0c8a-161baf8b9c55@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=mcroce@linux.microsoft.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.