#define _POSIX_C_SOURCE 200809L #include #include #include #include #include void create_vfs(void) { mkdir("/proc", 0755); mkdir("/sys", 0755); mkdir("/dev", 0755); mkdir("/run", 0755); } void mount_vfs(void) { if (mount("proc", "/proc", "proc", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) { perror("mount /proc"); } if (mount("sys", "/sys", "sysfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) { perror("mount /sys"); } if (mount("dev", "/dev", "devtmpfs", MS_NOSUID | MS_RELATIME, "mode=755") != 0) { perror("mount /dev"); } if (mount("run", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME, "mode=755") != 0) { perror("mount /run"); } mkdir("/dev/pts", 0755); mkdir("/dev/shm", 1777); if (mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC | MS_RELATIME, "gid=5,mode=620") != 0) { perror("mount /dev/pts"); } if (mount("shm", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME, "mode=1777") != 0) { perror("mount /dev/shm"); } } int main(void) { create_vfs(); mount_vfs(); return 0; }