lvm.rc-2.02.105-r2 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2016 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. depend() {
  5. before checkfs fsck
  6. after modules device-mapper
  7. need lvmetad sysfs
  8. }
  9. config='global { locking_dir = "/run/lock/lvm" }'
  10. dm_in_proc() {
  11. local retval=0
  12. for x in devices misc ; do
  13. grep -qs 'device-mapper' /proc/${x}
  14. retval=$((${retval} + $?))
  15. done
  16. return ${retval}
  17. }
  18. start() {
  19. # LVM support for /usr, /home, /opt ....
  20. # This should be done *before* checking local
  21. # volumes, or they never get checked.
  22. # NOTE: Add needed modules for LVM or RAID, etc
  23. # to /etc/modules.autoload if needed
  24. for lvm_path in /bin/lvm /sbin/lvm ; do
  25. [ -x "$lvm_path" ] && break
  26. done
  27. if [ ! -x "$lvm_path" ]; then
  28. eerror "Cannot find lvm binary in /sbin or /bin!"
  29. return 1
  30. fi
  31. if [ -z "${CDBOOT}" ] ; then
  32. if [ -e /proc/modules ] && ! dm_in_proc ; then
  33. modprobe dm-mod 2>/dev/null
  34. fi
  35. if [ -d /proc/lvm ] || dm_in_proc ; then
  36. ebegin "Setting up the Logical Volume Manager"
  37. #still echo stderr for debugging
  38. lvm_commands="#! ${lvm_path} --config '${config}'\n"
  39. # Extra PV find pass because some devices might not have been available until very recently
  40. lvm_commands="${lvm_commands}pvscan\n"
  41. # Now make the nodes
  42. lvm_commands="${lvm_commands}vgscan --mknodes\n"
  43. # And turn them on!
  44. lvm_commands="${lvm_commands}vgchange --sysinit -a ly\n"
  45. # Order of this is important, have to work around dash and LVM readline
  46. printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
  47. eend $? "Failed to setup the LVM"
  48. fi
  49. fi
  50. }
  51. stop() {
  52. for lvm_path in /bin/lvm /sbin/lvm ; do
  53. [ -x "$lvm_path" ] && break
  54. done
  55. if [ ! -x "$lvm_path" ]; then
  56. eerror "Cannot find lvm binary in /sbin or /bin!"
  57. return 1
  58. fi
  59. # Stop LVM2
  60. if [ -x /sbin/vgs ] && \
  61. [ -x /sbin/vgchange ] && \
  62. [ -x /sbin/lvchange ] && \
  63. [ -f /etc/lvmtab -o -d /etc/lvm ] && \
  64. [ -d /proc/lvm -o "`grep device-mapper /proc/misc 2>/dev/null`" ]
  65. then
  66. einfo "Shutting down the Logical Volume Manager"
  67. VGS=$($lvm_path vgs --config "${config}" -o vg_name --noheadings --nosuffix --rows 2> /dev/null)
  68. if [ "$VGS" ]
  69. then
  70. ebegin " Shutting Down LVs & VGs"
  71. #still echo stderr for debugging
  72. lvm_commands="#! ${lvm_path} --config '${config}'\n"
  73. # Extra PV find pass because some devices might not have been available until very recently
  74. lvm_commands="${lvm_commands}lvchange --sysinit -a ln ${VGS}\n"
  75. # Now make the nodes
  76. lvm_commands="${lvm_commands}vgchange --sysinit -a ln ${VGS}\n"
  77. # Order of this is important, have to work around dash and LVM readline
  78. printf "%b\n" "${lvm_commands}" | $lvm_path /proc/self/fd/0 --config "${config}" >/dev/null
  79. eend $? "Failed (possibly some LVs still needed for /usr or root)"
  80. fi
  81. einfo "Finished shutting down the Logical Volume Manager"
  82. return 0
  83. fi
  84. }
  85. # vim:ts=4