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>
30 mknod("/dev/null", 0666, makedev(1, 3));
34 early_console(const char *dev)
40 ERROR("Failed to stat %s\n", dev);
44 dd = open(dev, O_RDWR);
46 dd = open("/dev/null", O_RDWR);
48 dup2(dd, STDIN_FILENO);
49 dup2(dd, STDOUT_FILENO);
50 dup2(dd, STDERR_FILENO);
52 if (dd != STDIN_FILENO &&
53 dd != STDOUT_FILENO &&
57 fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
63 mount("proc", "/proc", "proc", MS_NOATIME, 0);
64 mount("sysfs", "/sys", "sysfs", MS_NOATIME, 0);
65 mount("none", "/sys/fs/cgroup", "cgroup", 0, 0);
66 mount("tmpfs", "/dev", "tmpfs", MS_NOATIME, "mode=0755,size=512K");
67 mkdir("/dev/shm", 0755);
68 mkdir("/dev/pts", 0755);
69 mount("devpts", "/dev/pts", "devpts", MS_NOATIME, "mode=600");
72 early_console("/dev/console");
73 if (mount_zram_on_tmp())
74 mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, NULL);
77 mkdir("/tmp/run", 0777);
78 mkdir("/tmp/lock", 0777);
79 mkdir("/tmp/state", 0777);
80 if (symlink("/tmp", "/var"))
81 ERROR("failed to symlink /tmp -> /var\n");
87 setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin", 1);
99 LOG("Console is alive\n");