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