add failsafe support for x86-2.6 and fix mdev support for platforms using /etc/preinit
[openwrt/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 size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
7 mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
8 if grep devfs /proc/filesystems > /dev/null; then
9 mount none /dev -t devfs
10 else
11 mount -t sysfs none /sys
12 mount -t tmpfs tmpfs /dev -o size=512K
13 mknod /dev/console c 5 1
14 mkdir /dev/shm
15 /sbin/mdev -s
16 fi
17 mkdir -p /dev/pts
18 mount none /dev/pts -t devpts
19
20 [ failsafe != "$1" ] && {
21 grep rootfs /proc/mtd >/dev/null 2>/dev/null && {
22 mtd unlock rootfs
23 grep rootfs_data /proc/mtd >/dev/null 2>/dev/null && {
24 . /bin/firstboot
25 echo "switching to jffs2"
26 mount "$(find_mtd_part rootfs_data)" /jffs -t jffs2
27 fopivot /jffs /rom
28 }
29 } || mount -o remount,rw /dev/root /
30 }
31
32 grep sysfs /proc/filesystems >/dev/null && mount -t sysfs none /sys 2>&-