80_mount_root 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2006 OpenWrt.org
  2. # Copyright (C) 2010 Vertical Communications
  3. missing_lines() {
  4. local file1 file2 line
  5. file1="$1"
  6. file2="$2"
  7. oIFS="$IFS"
  8. IFS=":"
  9. while read line; do
  10. set -- $line
  11. grep -q "^$1:" "$file2" || echo "$line"
  12. done < "$file1"
  13. IFS="$oIFS"
  14. }
  15. # Rootfs mount options can be passed by declaring in the kernel
  16. # cmdline as much options as needed prefixed with "rootfs_mount_options."
  17. #
  18. # Example:
  19. # rootfs_mount_options.compress_algorithm=zstd rootfs_mount_options.noinline_data
  20. #
  21. compose_rootfs_mount_options() {
  22. local mount_options
  23. local cmdlinevar
  24. for cmdlinevar in $(cat /proc/cmdline); do
  25. if [ "$cmdlinevar" != "${cmdlinevar#rootfs_mount_options\.}" ]; then
  26. append mount_options "${cmdlinevar#rootfs_mount_options\.}"
  27. fi
  28. done
  29. echo $mount_options
  30. }
  31. do_mount_root() {
  32. mount_root start "$(compose_rootfs_mount_options)"
  33. boot_run_hook preinit_mount_root
  34. [ -f /sysupgrade.tgz -o -f /tmp/sysupgrade.tar ] && {
  35. echo "- config restore -"
  36. cp /etc/passwd /etc/group /etc/shadow /tmp
  37. cd /
  38. [ -f /sysupgrade.tgz ] && tar xzf /sysupgrade.tgz
  39. [ -f /tmp/sysupgrade.tar ] && tar xf /tmp/sysupgrade.tar
  40. missing_lines /tmp/passwd /etc/passwd >> /etc/passwd
  41. missing_lines /tmp/group /etc/group >> /etc/group
  42. missing_lines /tmp/shadow /etc/shadow >> /etc/shadow
  43. rm /tmp/passwd /tmp/group /tmp/shadow
  44. # Prevent configuration corruption on a power loss
  45. sync
  46. }
  47. }
  48. [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root