mount.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # Copyright 2010 Vertical Communications
  3. # This is free software, licensed under the GNU General Public License v2.
  4. # See /LICENSE for more information.
  5. #
  6. pi_include /lib/functions/block.sh
  7. pi_include /lib/functions/fsck.sh
  8. config_mount_by_section() {
  9. local cfg="$1"
  10. local find_rootfs="$2"
  11. mount_cb() {
  12. local cfg="$1"
  13. local device="$2"
  14. shift
  15. local target="$2"
  16. local cfgdevice="$3"
  17. local fstype="$4"
  18. local options="$5"
  19. local enabled="$6"
  20. local enabled_fsck="$7"
  21. local uuid="$8"
  22. local label="$9"
  23. shift
  24. local is_rootfs="$9"
  25. shift
  26. local found_device=""
  27. found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
  28. if [ -n "$found_device" ]; then
  29. if [ -z "$find_rootfs" ] || [ "$find_rootfs" -eq 0 ] || [ "$is_rootfs" -eq 1 ]; then
  30. [ "$enabled_fsck" -eq 1 ] && {
  31. grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
  32. libmount_fsck "$found_device" "$fstype" "$enabled_fsck"
  33. }
  34. }
  35. [ "$is_rootfs" -eq 1 ] && [ "$find_rootfs" -eq 1 ] && {
  36. target=/overlay
  37. }
  38. config_create_mount_fstab_entry "$found_device" "$target" "$fstype" "$options" "$enabled"
  39. grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
  40. [ "$enabled" -eq 1 ] && mkdir -p "$target" && mount "$target" 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
  41. }
  42. fi
  43. fi
  44. [ "$is_rootfs" -eq 1 ] && [ "$find_rootfs" -eq 1 ] && {
  45. rootfs_found=1
  46. }
  47. return 0
  48. }
  49. config_get_mount "$cfg"
  50. reset_block_cb
  51. }
  52. config_swapon_by_section() {
  53. local cfg="$1"
  54. swap_cb() {
  55. local cfg="$1"
  56. local device="$2"
  57. local cfgdevice="$3"
  58. local enabled="$4"
  59. local uuid="$5"
  60. local label="$6"
  61. local uuid
  62. local label
  63. local found_device=""
  64. found_device="$(libmount_find_device_by_id "$uuid" "$label" "$device" "$cfgdevice")"
  65. if [ -n "$found_device" ]; then
  66. config_create_swap_fstab_entry "$found_device" "$enabled"
  67. grep -q "$found_device" /proc/swaps || grep -q "$found_device" /proc/mounts || {
  68. [ "$enabled" -eq 1 ] && swapon "$found_device" | tee /proc/self/fd/2 | logger -t 'fstab'
  69. }
  70. fi
  71. return 0
  72. }
  73. config_get_swap "$cfg"
  74. reset_block_cb
  75. }