unified preinit environment
[openwrt.git] / package / base-files / files / sbin / mount_root
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3 . /etc/functions.sh
4
5 mount none /proc -t proc
6
7 size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)?mt-l:s}' /proc/meminfo)
8 mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
9
10 if grep devfs /proc/filesystems >/dev/null; then
11 mount none /dev -t devfs
12 else
13 mount -t tmpfs tmpfs /dev -o size=512K
14 mknod /dev/console c 5 1
15 exec >/dev/console </dev/console 2>&1
16 fi
17
18 mkdir /dev/shm
19
20 if grep sysfs /proc/filesystems >/dev/null; then
21 mount -t sysfs none /sys
22 HOTPLUG=""
23 # use a minimal ruleset only for creating device nodes
24 /sbin/hotplug2 --no-persistent --coldplug --set-rules-file /etc/hotplug2-init.rules
25 else
26 HOTPLUG="/sbin/hotplug2-dnode"
27 fi
28 echo "$HOTPLUG" > /proc/sys/kernel/hotplug
29
30 mkdir -p /dev/pts
31 mount none /dev/pts -t devpts
32
33 jffs2_ready () {
34 mtdpart="$(find_mtd_part rootfs_data)"
35 magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
36 [ "$magic" != "deadc0de" ]
37 }
38
39 [ failsafe != "$1" ] && {
40 grep rootfs /proc/mtd >/dev/null 2>/dev/null && {
41 mtd unlock rootfs
42 grep rootfs_data /proc/mtd >/dev/null 2>/dev/null && {
43 . /bin/firstboot
44 jffs2_ready && {
45 echo "switching to jffs2"
46 mount "$(find_mtd_part rootfs_data)" /jffs -t jffs2
47 fopivot /jffs /rom
48 } || {
49 echo "jffs2 not ready yet; using ramdisk"
50 ramoverlay
51 }
52 }
53 } || mount -o remount,rw /dev/root /
54 }
This page took 0.045302 seconds and 5 git commands to generate.