mkrlconf 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env bash
  2. # Script to create a refind_linux.conf file for the current Linux
  3. # installation.
  4. # copyright (c) 2012-2015 by Roderick W. Smith
  5. #
  6. # This program is licensed under the terms of the GNU GPL, version 3,
  7. # or (at your option) any later version.
  8. # You should have received a copy of the GNU General Public License
  9. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  10. # Usage:
  11. #
  12. # ./mkrlconf [--force]
  13. #
  14. # Options:
  15. #
  16. # --force -- Overwrite an existing file (default is to not replace existing file)
  17. # Revision history:
  18. #
  19. # 0.10.1 -- Improve extraction of kernel options from /proc/cmdline
  20. # 0.10.0 -- Renamed from mkrlconf.sh to mkrlconf; changed to get $DefaultOptions
  21. # from /proc/cmdline rather than from GRUB
  22. # 0.9.0 -- Added check for OS type, to keep from running pointlessly on OS X
  23. # 0.7.7 -- Fixed bug that caused stray PARTUUID= and line breaks in generated file
  24. # 0.5.1 -- Initial release
  25. #
  26. # Note: mkrlconf version numbers match those of the rEFInd package
  27. # with which they first appeared.
  28. RLConfFile="/boot/refind_linux.conf"
  29. if [[ $(uname -s) != "Linux" ]] ; then
  30. echo "This script is intended to be run from Linux. Aborting!"
  31. echo ""
  32. exit 1
  33. fi
  34. if [[ ! -f $RLConfFile || $1 == "--force" ]] ; then
  35. RootFS=$(df / | grep dev | cut -f 1 -d " ")
  36. StartOfDevname=$(echo "$RootFS" | cut -b 1-7)
  37. if [[ $StartOfDevname == "/dev/sd" || $StartOfDevname == "/dev/hd" ]] ; then
  38. # Identify root filesystem by UUID rather than by device node, if possible
  39. Uuid=$(blkid -o export -s UUID "$RootFS" 2> /dev/null | grep UUID=)
  40. if [[ -n $Uuid ]] ; then
  41. RootFS=$Uuid
  42. fi
  43. fi
  44. FirstCmdlineOption=$(cut -d ' ' -f 1 < /proc/cmdline)
  45. if [[ "$FirstCmdlineOption" =~ (vmlinuz|bzImage|kernel) ]] ; then
  46. DefaultOptions=$(cut -d ' ' -f 2- < /proc/cmdline | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//')
  47. else
  48. DefaultOptions=$(sed 's/\S*initrd=\S*//g' < /proc/cmdline | sed 's/ *$//' | sed 's/^ *//')
  49. fi
  50. echo "\"Boot with standard options\" \"$DefaultOptions\"" > $RLConfFile
  51. echo "\"Boot to single-user mode\" \"$DefaultOptions single\"" >> $RLConfFile
  52. echo "\"Boot with minimal options\" \"ro root=$RootFS\"" >> $RLConfFile
  53. else
  54. echo "Existing $RLConfFile found! Not overwriting!"
  55. echo "To force overwriting, pass the --force option."
  56. echo ""
  57. fi