1 /* 2 * This is a simple init for shared rootfs guests. It brings up critical 3 * mountpoints and then launches /bin/sh. 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[] = { 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 puts("Starting '/bin/sh'..."); 34 35 run_process("/bin/sh"); 36 37 printf("Init failed: %s\n", strerror(errno)); 38 39 return 0; 40 } 41