lvm.rc-2.02.166-r2 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2017 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. _get_lvm_path() {
  5. local lvm_path=
  6. for lvm_path in /bin/lvm /sbin/lvm ; do
  7. [ -x "$lvm_path" ] && break
  8. done
  9. echo "${lvm_path}"
  10. }
  11. _need_lvmetad()
  12. {
  13. local lvm_path="$(_get_lvm_path)"
  14. [ ! -x "${lvm_path}" ] && return 1
  15. ${lvm_path} dumpconfig global 2>/dev/null | grep -q 'use_lvmetad=1'
  16. }
  17. _need_lvmlockd()
  18. {
  19. local lvm_path="$(_get_lvm_path)"
  20. [ ! -x "${lvm_path}" ] && return 1
  21. ${lvm_path} dumpconfig global 2>/dev/null | grep -q 'use_lvmlockd=1'
  22. }
  23. depend() {
  24. before checkfs fsck
  25. after modules device-mapper
  26. # We may use lvmetad based on the configuration. If we added lvmetad
  27. # support while lvm2 is running then we aren't dependent on it. For the
  28. # more common case, if its disabled in the config we aren't dependent
  29. # on it.
  30. config /etc/lvm/lvm.conf
  31. local _need=
  32. if service_started; then
  33. _need=$(service_get_value need)
  34. else
  35. if _need_lvmetad; then
  36. _need="${_need} lvmetad"
  37. fi
  38. if _need_lvmlockd; then
  39. _need="${_need} lvmlockd"
  40. fi
  41. fi
  42. need sysfs ${_need}
  43. }
  44. config='global { locking_dir = "/run/lock/lvm" }'
  45. dm_in_proc() {
  46. local retval=0
  47. for x in devices misc ; do
  48. grep -qs 'device-mapper' /proc/${x}
  49. retval=$((${retval} + $?))
  50. done
  51. return ${retval}
  52. }
  53. start() {
  54. # LVM support for /usr, /home, /opt ....
  55. # This should be done *before* checking local
  56. # volumes, or they never get checked.
  57. # NOTE: Add needed modules for LVM or RAID, etc
  58. # to /etc/modules.autoload if needed
  59. lvm_path="$(_get_lvm_path)"
  60. for lvm_path in /bin/lvm /sbin/lvm ; do
  61. [ -x "$lvm_path" ] && break
  62. done
  63. if [ ! -x "$lvm_path" ]; then
  64. eerror "Cannot find lvm binary in /sbin or /bin!"
  65. return 1
  66. fi
  67. if [ -z "${CDBOOT}" ] ; then
  68. if [ -e /proc/modules ] && ! dm_in_proc ; then
  69. modprobe dm-mod 2>/dev/null
  70. fi
  71. if [ -d /proc/lvm ] || dm_in_proc ; then
  72. ebegin "Setting up the Logical Volume Manager"
  73. #still echo stderr for debugging
  74. lvm_commands="#! ${lvm_path} --config '${config}'\n"
  75. # Extra PV find pass because some devices might not have been available until very recently
  76. lvm_commands="${lvm_commands}pvscan\n"
  77. # Now make the nodes
  78. lvm_commands="${lvm_commands}vgscan --mknodes\n"
  79. # And turn them on!
  80. lvm_commands="${lvm_commands}vgchange --sysinit -a ly\n"
  81. if _need_lvmlockd; then
  82. # Start lockd VGs as required
  83. lvm_commands="${lvm_commands}vgchange --lock-start --lock-opt auto\n"
  84. fi
  85. # Order of this is important, have to work around dash and LVM readline
  86. printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
  87. eend $? "Failed to setup the LVM"
  88. fi
  89. fi
  90. }
  91. start_post()
  92. {
  93. # Save if we needed lvmetad
  94. if _need_lvmetad; then
  95. service_set_value need lvmetad
  96. fi
  97. }
  98. stop() {
  99. for lvm_path in /bin/lvm /sbin/lvm ; do
  100. [ -x "$lvm_path" ] && break
  101. done
  102. if [ ! -x "$lvm_path" ]; then
  103. eerror "Cannot find lvm binary in /sbin or /bin!"
  104. return 1
  105. fi
  106. # Stop LVM2
  107. if [ -x /sbin/vgs ] && \
  108. [ -x /sbin/vgchange ] && \
  109. [ -x /sbin/lvchange ] && \
  110. [ -f /etc/lvmtab -o -d /etc/lvm ] && \
  111. [ -d /proc/lvm -o "`grep device-mapper /proc/misc 2>/dev/null`" ]
  112. then
  113. einfo "Shutting down the Logical Volume Manager"
  114. VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix --rows 2> /dev/null)
  115. if [ "$VGS" ]
  116. then
  117. ebegin " Shutting Down LVs & VGs"
  118. #still echo stderr for debugging
  119. lvm_commands="#! ${lvm_path} --config '${config}'\n"
  120. # Extra PV find pass because some devices might not have been available until very recently
  121. lvm_commands="${lvm_commands}lvchange --sysinit -a ln ${VGS}\n"
  122. # Now make the nodes
  123. lvm_commands="${lvm_commands}vgchange --sysinit -a ln ${VGS}\n"
  124. # Order of this is important, have to work around dash and LVM readline
  125. printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
  126. eend $? "Failed (possibly some LVs still needed for /usr or root)"
  127. fi
  128. einfo "Finished shutting down the Logical Volume Manager"
  129. return 0
  130. fi
  131. }
  132. # vim:ts=4