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[] = { "TERM=linux" }; 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 /* get session leader */ 34 setsid(); 35 36 /* set controlling terminal */ 37 ioctl (0, TIOCSCTTY, 1); 38 39 puts("Starting '/bin/sh'..."); 40 41 run_process("/bin/sh"); 42 43 printf("Init failed: %s\n", strerror(errno)); 44 45 return 0; 46 } 47