qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] linux-user: add option to chroot before emulation


From: Laurent Vivier
Subject: Re: [PATCH] linux-user: add option to chroot before emulation
Date: Tue, 8 Dec 2020 19:25:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0

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 via email to

[Prev in Thread] Current Thread [Next in Thread]