lvm.rc-2.02.116-r4 3.7 KB

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