init-install: fix rootfs.img not found issue
[pti/rtp.git] / meta-oran / recipes-core / initrdscripts / initramfs-module-setup-live / setup-live
1 #/bin/sh
2 # Copyright (C) 2011 O.S. Systems Software LTDA.
3 # Licensed on MIT
4
5 _UDEV_DAEMON=`udev_daemon`
6
7 setup_enabled() {
8         return 0
9 }
10
11 setup_run() {
12 ROOT_IMAGE="rootfs.img"
13 ISOLINUX=""
14 ROOT_DISK=""
15 shelltimeout=60
16
17         if [ -z "$bootparam_root" -o "$bootparam_root" = "/dev/ram0" ]; then
18                 echo "Waiting for removable media..."
19                 udevadm trigger --action=add
20                 udevadm settle
21                 echo "Mounted filesystems"
22                 mount |grep media
23                 C=0
24                 while true
25                 do
26                   for i in `ls /run/media 2>/dev/null`; do
27                       if [ -f /run/media/$i/$ROOT_IMAGE ] ; then
28                                 found="yes"
29                                 ROOT_DISK="$i"
30                                 break
31                           elif [ -f /run/media/$i/isolinux/$ROOT_IMAGE ]; then
32                                 found="yes"
33                                 ISOLINUX="isolinux"
34                                 ROOT_DISK="$i"
35                                 break
36                       fi
37                   done
38                   if [ "$found" = "yes" ]; then
39                       break;
40                   fi
41                   # don't wait for more than $shelltimeout seconds, if it's set
42                   if [ -n "$shelltimeout" ]; then
43                       echo " " $(( $shelltimeout - $C ))
44                       if [ $C -ge $shelltimeout ]; then
45                            echo "..."
46                            echo "Mounted filesystems"
47                            mount | grep media
48                            echo "Available block devices"
49                            cat /proc/partitions
50                            fatal "Cannot find $ROOT_IMAGE file in /run/media/* , dropping to a shell "
51                       fi
52                       udevadm trigger --action=add
53                       udevadm settle
54                       echo "Mounted filesystems"
55                       mount |grep media
56                       C=$(( C + 1 ))
57                   fi
58                   sleep 1
59                 done
60                 killall -9 "${_UDEV_DAEMON##*/}" 2>/dev/null
61                 # The existing rootfs module has no support for rootfs images. Assign the rootfs image.
62                 bootparam_root="/run/media/$ROOT_DISK/$ISOLINUX/$ROOT_IMAGE"
63         fi
64
65         if [ "$bootparam_LABEL" != "boot" -a -f /init.d/$bootparam_LABEL.sh ] ; then
66                 if [ -f /run/media/$ROOT_DISK/$ISOLINUX/$ROOT_IMAGE ] ; then
67                     ./init.d/$bootparam_LABEL.sh $ROOT_DISK/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params
68                 else
69                     fatal "Could not find $bootparam_LABEL script"
70                 fi
71
72                 # If we're getting here, we failed...
73                 fatal "Target $bootparam_LABEL failed"
74         fi
75 }