2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/mount.h>
16 #include <sys/types.h>
24 #include "../utils/utils.h"
26 #include "../libc-compat.h"
32 mknod("/dev/null", 0666, makedev(1, 3));
36 early_console(const char *dev)
41 ERROR("Failed to stat %s\n", dev);
45 if (patch_stdio(dev)) {
46 ERROR("Failed to setup i/o redirection\n");
50 fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
56 unsigned int oldumask = umask(0);
58 mount("proc", "/proc", "proc", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
59 mount("sysfs", "/sys", "sysfs", MS_NOATIME | MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
60 mount("cgroup", "/sys/fs/cgroup", "cgroup", MS_NODEV | MS_NOEXEC | MS_NOSUID, 0);
61 mount("tmpfs", "/dev", "tmpfs", MS_NOATIME | MS_NOSUID, "mode=0755,size=512K");
62 ignore(symlink("/tmp/shm", "/dev/shm"));
63 mkdir("/dev/pts", 0755);
64 mount("devpts", "/dev/pts", "devpts", MS_NOATIME | MS_NOEXEC | MS_NOSUID, "mode=600");
67 early_console("/dev/console");
68 if (mount_zram_on_tmp()) {
69 mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, 0);
70 mkdir("/tmp/shm", 01777);
72 mkdir("/tmp/shm", 01777);
73 mount("tmpfs", "/tmp/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME,
76 mkdir("/tmp/run", 0755);
77 mkdir("/tmp/lock", 0755);
78 mkdir("/tmp/state", 0755);
85 setenv("PATH", EARLY_PATH, 1);
97 LOG("Console is alive\n");