* updated libkcddb (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / target / share / livecd / init2
blobb4e6d3bd663700a133d7aae1a16d5f66b382c08d
1 #!/bin/sh
3 echo "T2 live setup (C) 2005 - 2007 Rene Rebe, ExactCODE"
5 mkdir -p /tmp ; chmod 1777 /tmp
7 livedev=`sed -n '/[^ ]* \/media\/live/{s/ .*//p; q}' /proc/mounts`
9 if mount -n $livedev -o remount,rw /media/live 2>/dev/null; then
10 echo "Re-mounted /media/live read-write."
13 echo "Unionfs overlay setup ..."
15 dirs='/mnt/live=ro'
16 rw=0
17 for f in /media/live/live-*.*; do
18 [ -e $f ] || continue
20 n=${f##*/}; n=${n%.*}
21 mkdir -p /mnt/$n
22 if mount -nt auto -o loop,noatime $f /mnt/$n; then
23 if grep -q "/mnt/$n .* rw" /proc/mounts; then
24 echo "Mounted $f read-write."
25 dirs="/mnt/$n=rw:$dirs"
26 rw=1
27 else
28 echo "Mounted $f read-only."
29 dirs="/mnt/$n=ro:$dirs"
31 else
32 echo "Failed to mount $f!"
34 done
36 # determine union fs to use, TODO: allow user-overwrite
37 unionfs=
38 modprobe aufs 2> /dev/null
39 if grep -q 'aufs$' /proc/filesystems; then unionfs=aufs
40 elif grep -q 'unionfs$' /proc/filesystems; then unionfs=unionfs
43 if [ "$unionfs" ]; then
44 if [ $rw = 0 ]; then
45 mkdir -p /mnt/overlay
46 mount -nt tmpfs none /mnt/overlay
47 dirs="/mnt/overlay:$dirs"
50 mount -nt $unionfs -o noatime,dirs=$dirs none /mnt/live
52 echo "Finalizing setup ..."
53 cat /proc/mounts > /etc/mtab
55 find /tmp/lib -type f -name '*.ko' | while read f; do
56 f=${f#/tmp}
57 [ -e $f ] || mv -f /tmp/$f $f
58 done
61 # convert symlinks to bind mounts
62 for x in /mnt/live/* ; do
63 x=${x#/mnt/live/}
64 case $x in
65 dev|proc|sys|media|mnt|tmp) continue ;;
66 esac
67 if [ -e /$x ]; then
68 # echo "Removing /$x ..."
69 /tmp/bin/rm -rf /$x
71 # echo "Binding /mnt/live/$x /$x"
72 /tmp/bin/mkdir -p /$x
73 /tmp/bin/mount -t none -o bind /mnt/live/$x /$x
74 done
76 rm -rf /tmp/lib /tmp/bin /init{,2}
78 init="init= `cat /proc/cmdline`" ; init=${init##*init=} ; init=${init%% *}
79 # TODO: later on search other places if we want 100% backward compat.
80 [ "$init" ] || init=/sbin/init
81 if [ -f $init ]; then
82 exec $init $*
85 echo "No init found, giving up. Debug shell:"
86 exec sh --login