File: mkrlconf

package info (click to toggle)
refind 0.14.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,432 kB
  • sloc: ansic: 52,757; sh: 2,086; python: 592; makefile: 351; perl: 5
file content (64 lines) | stat: -rwxr-xr-x 2,435 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash

# Script to create a refind_linux.conf file for the current Linux
# installation.

# copyright (c) 2012-2015 by Roderick W. Smith
#
# This program is licensed under the terms of the GNU GPL, version 3,
# or (at your option) any later version.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Usage:
#
# ./mkrlconf [--force]
#
# Options:
#
#   --force  -- Overwrite an existing file (default is to not replace existing file)

# Revision history:
#
# 0.10.1  -- Improve extraction of kernel options from /proc/cmdline
# 0.10.0  -- Renamed from mkrlconf.sh to mkrlconf; changed to get $DefaultOptions
#            from /proc/cmdline rather than from GRUB
# 0.9.0   -- Added check for OS type, to keep from running pointlessly on OS X
# 0.7.7   -- Fixed bug that caused stray PARTUUID= and line breaks in generated file
# 0.5.1   -- Initial release
#
# Note: mkrlconf version numbers match those of the rEFInd package
# with which they first appeared.

RLConfFile="/boot/refind_linux.conf"

if [[ $(uname -s) != "Linux" ]] ; then
    echo "This script is intended to be run from Linux. Aborting!"
    echo ""
    exit 1
fi

if [[ ! -f $RLConfFile || $1 == "--force" ]] ; then
    RootFS=$(df / | grep dev | cut -f 1 -d " ")
    StartOfDevname=$(echo "$RootFS" | cut -b 1-7)
    if [[ $StartOfDevname == "/dev/sd" || $StartOfDevname == "/dev/hd" ]] ; then
        # Identify root filesystem by UUID rather than by device node, if possible
        Uuid=$(blkid -o export -s UUID "$RootFS" 2> /dev/null | grep UUID=)
        if [[ -n $Uuid ]] ; then
            RootFS=$Uuid
        fi
    fi
    FirstCmdlineOption=$(cut -d ' ' -f 1 < /proc/cmdline)
    if [[ "$FirstCmdlineOption" =~ (vmlinuz|bzImage|kernel) ]] ; then
        DefaultOptions=$(cut -d ' ' -f 2- < /proc/cmdline | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//')
    else
        DefaultOptions=$(sed 's/\S*initrd=\S*//g' < /proc/cmdline | sed 's/ *$//' | sed 's/^ *//')
    fi
    echo "\"Boot with standard options\"  \"$DefaultOptions\"" > $RLConfFile
    echo "\"Boot to single-user mode\"    \"$DefaultOptions single\"" >> $RLConfFile
    echo "\"Boot with minimal options\"   \"ro root=$RootFS\"" >> $RLConfFile
else
    echo "Existing $RLConfFile found! Not overwriting!"
    echo "To force overwriting, pass the --force option."
    echo ""
fi