add base-files change from whiterussian
[openwrt.git] / package / base-files / default / sbin / mount_root
1 #!/bin/sh
2 . /etc/nvram.sh
3 is_clean() {
4         OFFSET="$((0x$(dd if=/dev/mtdblock/1 bs=1 skip=$((0x14)) count=2 2>&- | hexdump | grep 0000000 | cut -d ' ' -f 2) - 1))"
5         dd if=/dev/mtdblock/1 bs=1 skip=$OFFSET count=1 2>&- | hexdump -v | grep ' 0000' > /dev/null && return 255 || return 0
6 }
7
8 if [ "$1" != "failsafe" ]; then 
9         mount | grep jffs2 >&-
10         if [ $? = 0 ] ; then
11                 if [ $(cat /proc/mtd | wc -l) = 6 ]; then
12                         echo 5 > /proc/sys/diag
13                         mtd unlock linux
14                         mtd erase OpenWrt
15                         jffs2root --move
16                 else
17                         mtd unlock rootfs
18                         mount -o remount,rw /dev/root /
19                 fi
20         else
21                 if [ -z "$(nvram get no_root_swap)" ]; then
22                         is_clean || {
23                                 mtd erase OpenWrt
24                                 jffs2root --clean
25                         }
26                         mtd unlock OpenWrt
27                         mount -t jffs2 /dev/mtdblock/4 /jffs
28                         pivot_root /jffs /jffs/rom
29                         mount none /proc -t proc
30                         mount none /dev -t devfs
31                         umount /rom/proc rom/dev >&-
32                 fi
33         fi
34 fi
35 mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50%
36 mkdir -p /dev/pts
37 mount none /dev/pts -t devpts