You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update-resume-partition 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # Copyright (C) 2006-2015, Stefan Lippers-Hollmann <s.l-h@gmx.de>
  3. # Copyright (C) 2007-2010, Kel Modderman <kel@otaku42.de>
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2 of the
  7. # License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. if [ "$(id -u)" -ne 0 ]; then
  14. [ -x "$(which su-to-root)" ] && exec su-to-root -X -c "$0" "$@"
  15. printf "ERROR: $0 needs root capabilities, please start it as root.\n\n" >&2
  16. exit 1
  17. fi
  18. unset RESUME SWAPUUID
  19. if [ -s /etc/initramfs-tools/conf.d/resume ]; then
  20. . /etc/initramfs-tools/conf.d/resume
  21. fi
  22. if [ -n "${RESUME}" ]; then
  23. echo -n "Validating resume partition..."
  24. case "${RESUME}" in
  25. UUID=*|LABEL=*)
  26. if findfs "${RESUME}"; then
  27. echo "Valid resume device: ${RESUME}"
  28. exit 0
  29. else
  30. echo "invalid."
  31. fi
  32. ;;
  33. /dev/disk/by-*)
  34. RESUMELINK=$(readlink -f ${RESUME})
  35. if [ -b "${RESUMELINK}" ]; then
  36. echo "${RESUMELINK}"
  37. echo "Valid resume device: ${RESUME}"
  38. exit 0
  39. else
  40. echo "invalid."
  41. fi
  42. ;;
  43. /dev/*)
  44. echo "invalid."
  45. if [ -b "${RESUME}" ]; then
  46. SWAPUUID=$(blkid -t TYPE=swap -o value -s UUID ${RESUME})
  47. fi
  48. ;;
  49. esac
  50. fi
  51. if [ -z "${SWAPUUID}" ]; then
  52. SWAPUUID=$(blkid -l -t TYPE=swap -o value -s UUID)
  53. fi
  54. if echo "${SWAPUUID}" | egrep -q '^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$'; then
  55. echo "Using UUID=${SWAPUUID} for resume."
  56. if [ -d /etc/initramfs-tools/conf.d/ ]; then
  57. # (over)write configuration
  58. echo "Writing new configuration to /etc/initramfs-tools/conf.d/resume..."
  59. echo "RESUME=UUID=${SWAPUUID}" > /etc/initramfs-tools/conf.d/resume
  60. fi
  61. if grep -q -s '^resume device\ =' /etc/uswsusp.conf; then
  62. echo "Writing new configuration to /etc/uswsusp.conf..."
  63. sed -i 's|^\(resume\ device\ =\).*|\1 '"UUID=${SWAPUUID}"'|' /etc/uswsusp.conf
  64. fi
  65. else
  66. echo "No swap partition UUID could be detected by blkid(8)."
  67. echo "Not configuring resume partition."
  68. exit 3
  69. fi
  70. if [ -x /usr/sbin/update-initramfs ]; then
  71. # rebuild the initramfs
  72. echo "Updating initial ramdisk for new resume configuration..."
  73. update-initramfs -u -k "$(uname -r)"
  74. fi
  75. echo
  76. echo "A new resume configuration has been written to:"
  77. echo " /etc/initramfs-tools/conf.d/resume"
  78. echo
  79. echo "If you do not trust me to make the correct choice, then please"
  80. echo "check the file and change according to your needs."
  81. echo