Root/package/block-mount/files/50_determine_usb_root

1#!/bin/sh
2# Copyright (C) 2010 Vertical Communications
3# This is free software, licensed under the GNU General Public License v2.
4# See /LICENSE for more information.
5
6
7determine_external_root() {
8    pi_include /lib/functions/extmount.sh
9    pi_include /lib/functions/mount.sh
10
11    local OLD_UCI_CONFIG_DIR="$UCI_CONFIG_DIR"
12    local OLD_PATH="$PATH"
13    local OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
14    set_jffs_mp
15    determine_root_device
16
17    # extroot requires extroot and fstab config files, therefore
18    # we assume configuration is incomplete and not to be used if either of them
19    # is missing (for jffs versions of these files on squashfs image)
20    if [ "$jffs" = "/tmp/overlay" ] && [ -r "/tmp/overlay/etc/config/fstab" ]; then
21        UCI_CONFIG_DIR="/tmp/overlay/etc/config"
22        ER_IS_SQUASHFS=true
23        ER_OVERLAY_PREFIX="/tmp/overlay"
24        PATH=$ER_OVERLAY_PREFIX/sbin:$PATH
25        LD_LIBRARY_PATH=$ER_OVERLAY_PREFIX/usr/lib:$LD_LIBRARY_PATH
26        export PATH LD_LIBRARY_PATH
27    fi
28
29    # For squashfs on firstboot root_device will be tmpfs for the ramoverlay,
30    # unless there is a saved config, in which case it will be /dev/root,
31    # however in the case of a saved config, it won't be restored until after
32    # this script, so there won't be a config on the first boot after
33    # flashing a squashfs-based filesystem
34    # For ext2, ramdisk, or jffs2 root filesystems root_device is /dev/root
35    # For squashfs after firstboot, root filesystem is /dev/root
36    # We only use the config from the root or jffs if the root_device is
37    # /dev/root
38    [ "$root_device" = "/dev/root" ] && {
39        er_load_modules
40        [ -n "$extroot_settle_time" ] && [ "$extroot_settle_time" -gt 0 ] && {
41            sleep $extroot_settle_time
42        }
43        config_load fstab
44        config_foreach config_mount_by_section mount 1
45        ER_OVERLAY_ROM="/no-extroot"
46        
47        [ "$rootfs_found" = "1" ] && grep -q ' /overlay ' /proc/mounts && {
48            pi_extroot_mount_success=true
49            pi_mount_skip_next=false
50            ER_OVERLAY_ROM="/overlay"
51        }
52        [ "$rootfs_found" = "1" ] && grep -q ' /rom ' /proc/mounts && {
53            pi_extroot_mount_success=true
54            pi_mount_skip_next=false
55            ER_OVERLAY_ROM="/rom"
56        }
57    }
58    UCI_CONFIG_DIR="$OLD_UCI_CONFIG_DIR"
59    PATH="$OLD_PATH"
60    LD_LIBRARY_PATH="$OLD_LD_LIBRARY_PATH"
61    export PATH LD_LIBRARY_PATH
62}
63
64boot_hook_add preinit_mount_root determine_external_root
65
66

Archive Download this file



interactive