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