summaryrefslogtreecommitdiff
path: root/libre/grub-parabola/09_parabola
blob: 90a9062a3614151c9665d1bab13d67caa51ff88c (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash

##
## grub-mkconfig helper script specific to Parabola GNU/Linux-libre
## Contributed by "Keshav Amburay" <the ddoott ridikulus ddoott rat aatt geemmayil ddoott ccoomm>
## Rebranded for Parabola by "André Silva" <emulatorman@parabola.nu>
## Updated on 08 February 2014
##
## Script based on do_grub_config() function in Arch Archboot ISO Installer/Setup script 
## Some parts taken from /etc/grub.d/10_linux script shipped by GRUB(2) upstream
##
## This script can be freely distributed and/or modified 
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This script is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

_FUNC_GRUB_FILE_PRESENT() {
    
    [[ -z "${GRUB_PLATFORM}" ]] && GRUB_PLATFORM="x86"
    
    if [[ "${GRUB_PLATFORM}" == "x86" ]]; then
        check="--is-x86-linux32"
    elif [[ "${GRUB_PLATFORM}" == "i386-xen-pae" ]]; then
        check="--is-i386-xen-pae-domu"
    elif [[ "${GRUB_PLATFORM}" == "x86_64-xen" ]]; then
        check="--is-x86_64-xen-domu"
    else
        check="--is-${GRUB_PLATFORM}-linux"
    fi
    
    case "${GRUB_PLATFORM}" in
        x86)
            list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do
                        if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi
                    done)" ;;
        *) 
          list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do
                      if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi
                  done)" ;;
    esac
}

set -e

prefix="/usr"
exec_prefix="${prefix}"
datarootdir="/usr/share"
datadir="${datarootdir}"
sysconfdir="/etc"

. "${datarootdir}/grub/grub-mkconfig_lib"

. "${sysconfdir}/default/grub"

export TEXTDOMAIN="grub"
export TEXTDOMAINDIR="${datarootdir}/locale"

CLASS="--class parabola --class gnu-linux --class gnu --class os"

[[ "${grub_file}" != "" ]] && _FUNC_GRUB_FILE_PRESENT

BOOT_PART_FS_UUID="$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)"
BOOT_PART_HINTS_STRING="$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null || true)"
BOOT_PART_FS="$(${grub_probe} --target="fs" "/boot" 2>/dev/null)"

ROOT_PART_GRUB_DEVICE="$(${grub_probe} --target=device / || true)"
ROOT_PART_FS="$(${grub_probe} --device ${ROOT_PART_GRUB_DEVICE} --target=fs 2> /dev/null || echo "unknown")"

if [[ "${GRUB_LINUX_ROOT_DEVICE}" == "" ]]; then
    
    case "${ROOT_PART_FS}" in
        btrfs)
            rootsubvol="$(make_system_path_relative_to_its_root /)"
            rootsubvol="${rootsubvol#/}"
            if [[ "${rootsubvol}" != "" ]]; then
                GRUB_LINUX_ROOT_DEVICE="subvol=${rootsubvol}"
            fi
        ;;
        zfs)
            rpool="$(${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true)"
            bootfs="$(make_system_path_relative_to_its_root / | sed -e "s,@$,,")"
            GRUB_LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
        ;;
    esac
    
    if [[ "${GRUB_DEVICE_UUID}" == "" ]] || \
       [[ "${GRUB_DISABLE_LINUX_UUID}" == "true" ]] || \
       [[ ! -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ]] || \
       uses_abstraction "${GRUB_DEVICE}" lvm ; then
           GRUB_LINUX_ROOT_DEVICE="${GRUB_DEVICE}"
    else
       GRUB_LINUX_ROOT_DEVICE="UUID=${GRUB_DEVICE_UUID}"
    fi
fi

[[ "${GRUB_LINUX_PARAMS}" == "" ]] && GRUB_LINUX_PARAMS="${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"

for _KERNEL_ in ${list} ; do
    
    echo "Found linux image: ${_KERNEL_}" >&2
    
    basename="$(basename "${_KERNEL_}")"
    dirname="$(dirname "${_KERNEL_}")"
    REAL_DIR="$(make_system_path_relative_to_its_root "${dirname}")"
  
    _KERNEL_FILE_="$(echo ${_KERNEL_} | sed 's,/boot/,,g')"
    _KERNEL_PKG_="pkg-$(echo ${_KERNEL_FILE_} | sed 's,vmlinuz-,,g')"
    
    _INITRAMFS_="${_KERNEL_FILE_/vmlinuz-/initramfs-}.img"
    
    if [[ -e "/boot/${_INITRAMFS_}" ]]; then
    
    echo "Found initramfs image: /boot/${_INITRAMFS_}" >&2
    
cat << EOF

menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel" ${CLASS} {
    $(save_default_entry)
    if [ x\$feature_all_video_module = xy ]; then
        insmod all_video
    fi
    set gfxpayload=keep
    insmod ${BOOT_PART_FS}
    if [ x\$feature_platform_search_hint = xy ]; then
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
    else
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_FS_UUID}
    fi
    echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
    linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
    echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel initramfs ...'
    initrd ${REAL_DIR}/${_INITRAMFS_}
}

EOF
    fi
    
    _INITRAMFS_FALLBACK_="${_KERNEL_FILE_/vmlinuz-/initramfs-}-fallback.img"
    
    if [[ -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then
    
    echo "Found fallback initramfs image: /boot/${_INITRAMFS_FALLBACK_}" >&2
    
cat << EOF

menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel (fallback initramfs)" ${CLASS} {
    $(save_default_entry)
    if [ x\$feature_all_video_module = xy ]; then
        insmod all_video
    fi
    set gfxpayload=keep
    insmod ${BOOT_PART_FS}
    if [ x\$feature_platform_search_hint = xy ]; then
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
    else
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_FS_UUID}
    fi
    echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
    linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
    echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel fallback initramfs ...'
    initrd ${REAL_DIR}/${_INITRAMFS_FALLBACK_}
}

EOF
    fi
    
    if [[ ! -e "/boot/${_INITRAMFS_}" ]] && [[ ! -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then
cat << EOF

menuentry "Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel (no initramfs)" ${CLASS} {
    $(save_default_entry)
    if [ x\$feature_all_video_module = xy ]; then
        insmod all_video
    fi
    set gfxpayload=keep
    insmod ${BOOT_PART_FS}
    if [ x\$feature_platform_search_hint = xy ]; then
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}
    else
        search --no-floppy --fs-uuid  --set=root ${BOOT_PART_FS_UUID}
    fi
    echo 'Loading Parabola GNU/Linux-libre ${_KERNEL_PKG_} kernel ...'
    linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
}

EOF
    fi
    
done