activate-storage.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. #
  3. # This script activates storage at boot after the iSCSI login. It can
  4. # be called from both the init script as well as the native systemd
  5. # service.
  6. #
  7. PATH=/sbin:/bin
  8. MULTIPATH=/sbin/multipath
  9. VGCHANGE=/sbin/vgchange
  10. if [ -f /etc/default/open-iscsi ]; then
  11. . /etc/default/open-iscsi
  12. fi
  13. # See if we need to handle LVM
  14. if [ ! -x $VGCHANGE ] && [ -n "$LVMGROUPS" ]; then
  15. echo "Warning: LVM2 tools are not installed, not honouring LVMGROUPS." >&2
  16. LVMGROUPS=""
  17. fi
  18. # If we don't have to activate any VGs and are running systemd, we
  19. # don't have to activate anything, so doing udevadm settle here and
  20. # potentially sleeping (if multipath is used) will not be productive,
  21. # because after waiting for both of these things, we will do nothing.
  22. # Therefore just drop out early if that is the case.
  23. if [ -d /run/systemd/system ] && [ -z "$LVMGROUPS" ] ; then
  24. exit 0
  25. fi
  26. # Make sure we pick up all devices
  27. udevadm settle || true
  28. # Work around race condition here: after udevadm settle it is
  29. # guaranteed that all iSCSI disks have now properly appeared, but
  30. # other dependent devices may not have. This can include multipath
  31. # mappings of iSCSI devices (multipathd will race against udev for
  32. # locking the underlying source block devices when it comes to
  33. # creating the mappings, and it will retry the lock only once per
  34. # second, and typically succeed only on second try), but also
  35. # partitions on the given disks (which the kernel scans
  36. # asyncronously).
  37. #
  38. # The proper way of handling this is to have LVM activation and/or
  39. # mounting of file systems be handled in a completely event-driven
  40. # manner, but that requires configuration by the sysadmin in the
  41. # case of LVM, and for mounting it only works with systemd at the
  42. # moment. For compatibility with how the package handled this
  43. # previously, we will work around this race for a while longer.
  44. if [ -x $MULTIPATH ] ; then
  45. # 1 second is too short for multipath devices to appear,
  46. # because multipathd takes more than 1s to activate them
  47. # after udevadm settle is done.
  48. sleep 3
  49. else
  50. sleep 1
  51. fi
  52. udevadm settle || true
  53. # Handle LVM
  54. if [ -n "$LVMGROUPS" ] ; then
  55. if ! $VGCHANGE -ay $LVMGROUPS ; then
  56. echo "Warning: could not activate all LVM groups." >&2
  57. fi
  58. # Make sure we pick up all LVM devices
  59. udevadm settle || true
  60. fi
  61. # Mount all network filesystems
  62. # (systemd takes care of it directly, so don't do it there)
  63. if ! [ -d /run/systemd/system ] ; then
  64. if [ $HANDLE_NETDEV -eq 1 ] ; then
  65. mount -a -O _netdev >/dev/null 2>&1 || true
  66. # FIXME: should we really support swap on iSCSI?
  67. # If so, we should update umountiscsi.sh!
  68. swapon -a -e >/dev/null 2>&1 || true
  69. fi
  70. fi