50_determine_usb_root 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. determine_external_root() {
  6. pi_include /lib/functions/extmount.sh
  7. pi_include /lib/functions/mount.sh
  8. local OLD_UCI_CONFIG_DIR="$UCI_CONFIG_DIR"
  9. set_jffs_mp
  10. determine_root_device
  11. # extroot requires extroot and fstab config files, therefore
  12. # we assume configuration is incomplete and not to be used if either of them
  13. # is missing (for jffs versions of these files on squashfs image)
  14. if [ "$jffs" = "/tmp/overlay" ] && [ -r "/tmp/overlay/etc/config/fstab" ]; then
  15. UCI_CONFIG_DIR="/tmp/overlay/etc/config"
  16. ER_IS_SQUASHFS=true
  17. ER_OVERLAY_PREFIX="/tmp/overlay"
  18. fi
  19. # For squashfs on firstboot root_device will be tmpfs for the ramoverlay,
  20. # unless there is a saved config, in which case it will be /dev/root,
  21. # however in the case of a saved config, it won't be restored until after
  22. # this script, so there won't be a config on the first boot after
  23. # flashing a squashfs-based filesystem
  24. # For ext2, ramdisk, or jffs2 root filesystems root_device is /dev/root
  25. # For squashfs after firstboot, root filesystem is /dev/root
  26. # We only use the config from the root or jffs if the root_device is
  27. # /dev/root
  28. [ "$root_device" = "/dev/root" ] && {
  29. er_load_modules
  30. [ -n "$extroot_settle_time" ] && [ "$extroot_settle_time" -gt 0 ] && {
  31. sleep $extroot_settle_time
  32. }
  33. config_load fstab
  34. config_foreach config_mount_by_section mount 1
  35. ER_OVERLAY_ROM="/no-extroot"
  36. [ "$rootfs_found" = "1" ] && grep -q ' /overlay ' /proc/mounts && {
  37. pi_extroot_mount_success=true
  38. pi_mount_skip_next=false
  39. ER_OVERLAY_ROM="/overlay"
  40. }
  41. [ "$rootfs_found" = "1" ] && grep -q ' /rom ' /proc/mounts && {
  42. pi_extroot_mount_success=true
  43. pi_mount_skip_next=false
  44. ER_OVERLAY_ROM="/rom"
  45. }
  46. }
  47. UCI_CONFIG_DIR="$OLD_UCI_CONFIG_DIR"
  48. }
  49. boot_hook_add preinit_mount_root determine_external_root