xref: /kvmtool/guest/init.c (revision 9cec19c8d7e8c28aea6656133618a9569393cd96)
1 /*
2  * This is a simple init for shared rootfs guests. This part should be limited
3  * to doing mounts and running stage 2 of the init process.
4  */
5 #include <sys/mount.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <errno.h>
10 
11 static int run_process(char *filename)
12 {
13 	char *new_argv[] = { filename, NULL };
14 	char *new_env[] = { "TERM=linux", NULL };
15 
16 	return execve(filename, new_argv, new_env);
17 }
18 
19 static void do_mounts(void)
20 {
21 	mount("hostfs", "/host", "9p", MS_RDONLY, "trans=virtio,version=9p2000.L");
22 	mount("", "/sys", "sysfs", 0, NULL);
23 	mount("proc", "/proc", "proc", 0, NULL);
24 	mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
25 }
26 
27 int main(int argc, char *argv[])
28 {
29 	puts("Mounting...");
30 
31 	do_mounts();
32 
33 	run_process("/virt/init_stage2");
34 
35 	printf("Init failed: %s\n", strerror(errno));
36 
37 	return 0;
38 }
39