wok-next view busybox/stuff/init @ rev 1772

busybox: check memory size before tmpfs switch
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Nov 27 16:12:32 2008 +0000 (2008-11-27)
parents daea944c82bd
children f0cb83ba12fd
line source
1 #!/bin/sh
3 echo -n "switching / to tmpfs..."
4 mount -t proc proc /proc
5 size="$(grep rootfssize= < /proc/cmdline | \
6 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
7 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
8 umount /proc
9 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
10 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
11 exec /sbin/init
12 fi
13 for i in $(ls -a /); do
14 case "$i" in
15 .|..) ;;
16 mnt) mkdir /mnt/mnt;;
17 *) if ! cp -a /$i /mnt 2> /dev/null; then
18 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
19 umount /mnt
20 exec /sbin/init
21 fi;;
22 esac
23 done
24 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
25 exec /sbin/switch_root mnt /sbin/init