Add the tiny x86/init.S which just mounts /host and execs
/virt/init.
NOTE: of course, the usage of CONFIG_GUEST_PRE_INIT is ugly, we
need to cleanup this code. But I'd prefer to do this on top of
this minimal/simple change. And I think this needs cleanups in
any case, for example I think lkvm shouldn't abuse the "init="
kernel parameter at all.
Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
The reboot() call that guest/init used was an older version, the
manpage talks about libc4 and libc5.
Update it to the current version exported by glibc by using the right
include file and adjusting the parameter.
This also fixed GCC 5.1.0 compile, because linux/reboot.h misses the
actual prototype.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
GCC 5.1.0 complains about missing prototypes for waitpid() and
mkdir(), so add the appropriate #includes to get rid of the warning.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
init.c is not very kind with processes that get reparented when
their own parent die, leaving them hanging around. Looking at the
code, it only seem to care about its own flesh and blood. Bad init.
Teach it some basic zombie reaping skills.
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a HOME env var when booting a hostfs guest. This will point out to a home
dir within the given guest name.
This will make several apps happier when being run under hostfs.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
I'm seeing this in guest due to lacking of /dev/pts:
sh-4.2# xterm
xterm: Error 32, errno 28: No space left on device
Reason: get_pty: not enough ptys
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
It is useful to run a X program in guest and display it on host.
1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0
2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Generate
~/.lkvm/$guest/virt/etc/passwd
~/.lkvm/$guest/virt/init
on the fly.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Two stages init process is introduced in
commit eaf720b285947a6f4e29174d0eba1899de31d8ab
kvm tools: Split custom rootfs init into two stages
to address the outdated init binary issue.
Currenly, init binary is embedded in lkvm binary and generated on the
fly. So there is no need to split the init process.
This makes
1) the size of lkvm binary smaller becasue only one
statically linked init binary.
2) the init process simpler and cleaner.
Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch removes the following printout from init:
Starting '/bin/sh'...
which is completely bogus for "vm sandbox", for example.
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Right now we wait for any of the children to stop, which means we might
exit before /bin/sh stopped.
Instead, wait only for the /bin/sh (or the sandboxed) process.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
We currently panic guest when exiting from custom rootfs since at that point
we terminate init, and the guest kernel doesn't quite like that.
Instead, we do a graceful shutdown when init is done (either when 'lkvm
sandbox' command or '/bin/sh' is finished).
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch adds a '--sandbox' argument when used in conjuction with a custom
rootfs, it allows running a script or an executable in the guest environment
by using executables and other files from the host.
This is useful when testing code that might cause problems on the host, or
to automate kernel testing since it's now easy to link a kvm tools test
script with 'git bisect run'.
Suggested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Currently custom rootfs init is built along with the main KVM tools executable
and is copied into custom rootfs directories when they are created with
'kvm setup'. The problem there is that if the init code changes, they have
to be manually copied to custom rootfs directories.
Instead, this patch splits init process into two parts. One part that simply
handles mounts, and passes it to stage 2 of the init.
Stage 2 really sits along in the code tree, and does all the heavy lifting.
This allows us to make init changes in the code tree and have it automatically
be updated in custom rootfs guests without having to copy files over manua
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
[ penberg@kernel.org: fix 'make check' breakage in Makefile ]
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch creates a dummy /etc/passwd on guest creation.
This is done because some applications (read: git) get angry when they
can't find current user in /etc/passwd.
Reported-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch sets active console to the serial console before running the
shell. Doing so fixes two issues:
* Fix job control.
* Set all env vars.
The user visible issues are less warnings (no more of this:
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell)
A working 'top', and a working ctrl-c.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch removes the manual/usermode dhcp client configuration and instead
uses the DHCP client built within the kernel.
Since this client is tightly integrated with NFS (if NFS config is set), we
will add a specific NFS root addr in our DHCP offer to point it to a non
existent address so that we won't hang trying to poke it for our root.
Acked-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
Add a script to automatically configure networking in the guest.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This patch implements 'kvm setup' command that can be used to setup a guest
filesystem that shares system libraries and binaries from host filesystem in
read-only mode.
You can setup a new shared rootfs guest with:
./kvm setup -n default
and launch it with:
./kvm run --9p /,hostfs -p "init=virt/init" -d ~/.kvm-tools/default/
We want to teach 'kvm run' to be able to launch guest filesystems by name in
the future. Furthermore, 'kvm run' should setup a 'default' filesystem and use
it by default unless the user specifies otherwise.
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>