* updated libkomparediff2 (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / mkinitrd / initrdinit.sh
blob0e4c3940922d306dbb957a1f652c6f0e9dd76586
1 #!/bin/sh
3 PATH=/sbin:/bin:/usr/bin:/usr/sbin
5 echo "T2 SDE early userspace (c)2005-2021 Rene Rebe, ExactCODE GmbH; Germany."
7 function boot {
8 mount -t none -o move {,/mnt}/dev
9 mount -t none -o move {,/mnt}/proc
10 mount -t none -o move {,/mnt}/sys
11 exec switch_root /mnt $init $*
14 echo "Mounting /dev, /proc and /sys"
15 mount -t devtmpfs -o mode=755 none /dev
16 mount -t proc none /proc
17 mount -t sysfs none /sys
18 mkdir -p /tmp /mnt
19 ln -s /proc/self/fd /dev/fd
21 echo "$(< /proc/sys/kernel/ostype) $(< /proc/sys/kernel/osrelease)," \
22 "populating u/dev"
23 udevd &
24 udevadm trigger
25 udevadm settle
27 # get the root device, init, early swap
28 cmdline="$(< /proc/cmdline)"
29 root="root= $cmdline" ; root=${root##*root=} ; root=${root%% *}
30 init="init= $cmdline" ; init=${init##*init=} ; init=${init%% *}
31 swap="swap= $cmdline" ; swap=${swap##*swap=} ; swap=${swap%% *}
33 [ "${root#UUID=}" != "$root" ] && root="/dev/disk/by-uuid/${root#UUID=}"
34 [ "${swap#UUID=}" != "$swap" ] && swap="/dev/disk/by-uuid/${swap#UUID=}"
36 # maybe resume from disk?
37 resume="$(< /proc/cmdline)"
38 if [[ "$resume" = *resume* ]] && [[ "$resume" != *noresume* ]]; then
39 resume=${resume##*resume=} ; resume=${resume%% *}
40 resume=`ls -l $resume |
41 sed 's/[^ ]* *[^ t]* *[^ ]* *[^ ]* *\([0-9]*\), *\([0-9]*\) .*/\1:\2/'`
42 echo "Attempting to resume from disk $resume."
43 echo "$resume" > /sys/power/resume
46 if [ "$swap" ]; then
47 echo "Activating swap"
48 swapon $swap
51 if [ "$root" ]; then
52 mountopt="ro"
54 # diskless network root?
55 addr="${root%:*}"
56 if [ "$addr" != "$root" ]; then
57 mountopt="$mountopt,nolock,port=2049,mountport=32790,vers=4,addr=$addr"
58 filesystems="nfs"
59 ipconfig eth0
60 else
61 unset addr
62 if [ ! -e "$root" ]; then
63 echo "Activating RAID & LVM"
64 [ -e /sbin/mdadm ] && mdadm --assemble --scan
65 [ -e /sbin/lvchange ] && lvchange -a ay ${root#/dev/}
67 if [ ! -e "$root" ]; then
68 modprobe pata_legacy
72 echo "Mounting root $mountopt"
74 i=0
75 while [ $i -le 9 ]; do
76 if [ -e $root -o "$addr" ]; then
77 if [ -z "$addr" ]; then
78 type -p cryptsetup && cryptsetup isLuks $root --disable-locks &&
79 cryptsetup luksOpen $root root --disable-locks && root=/dev/mapper/root
81 # try best match / detected root first, all the others thereafter
82 filesystems=`disktype $root 2>/dev/null |
83 sed -e '/file system/!d' -e 's/file system.*//' -e 's/ //g' \
84 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
85 -e 's/fat32/vfat/'
86 sed '/^nodev/d' /proc/filesystems | sed '1!G; $p; h; d'`
88 for fs in $filesystems; do
89 if mount -t $fs -o $mountopt $root /mnt 2> /dev/null; then
90 echo "Successfully mounted root as $fs."
91 # TODO: later on search other places if we want 100% backward compat?
92 init=${init:-/sbin/init}
93 if [ -f /mnt$init ]; then
94 kill %1
95 boot $init $*
96 else
97 echo "Specified init ($init) does not exist!"
99 break 2
101 done
103 [ $(( i++ )) -eq 0 ] && echo "Waiting for root device to become ready."
104 sleep 1
105 done
108 # PANICMARK
110 echo "No root or init, but we do not scream, debug shell:"
111 kill %1
113 exec /bin/sh