143 lines
4.7 KiB
Plaintext
143 lines
4.7 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
##
|
||
|
## grub-mkconfig helper script specific to Arch Linux
|
||
|
## Contributed by "Keshav Padram Amburay" <the ddoott ridikulus ddoott rat aatt geemmayil ddoott ccoomm>
|
||
|
##
|
||
|
## Script based on do_grub_config() function in Arch Linux 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.
|
||
|
##
|
||
|
|
||
|
set -e
|
||
|
|
||
|
prefix="/usr"
|
||
|
exec_prefix="/usr"
|
||
|
datarootdir="/usr/share"
|
||
|
sysconfdir="/etc"
|
||
|
|
||
|
. "${datarootdir}/grub/grub-mkconfig_lib"
|
||
|
|
||
|
. "${sysconfdir}/default/grub"
|
||
|
|
||
|
export TEXTDOMAIN="grub"
|
||
|
export TEXTDOMAINDIR="${datarootdir}/locale"
|
||
|
|
||
|
CLASS="--class arch-linux --class arch --class gnu-linux --class gnu --class os"
|
||
|
|
||
|
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)"
|
||
|
BOOT_PART_FS="$(grub-probe --target="fs" "/boot" 2>/dev/null)"
|
||
|
|
||
|
ROOT_PART_FS_UUID="$(grub-probe --target="fs_uuid" "/" 2>/dev/null)"
|
||
|
ROOT_PART_HINTS_STRING="$(grub-probe --target="hints_string" "/" 2>/dev/null)"
|
||
|
ROOT_PART_FS="$(grub-probe --target="fs" "/" 2>/dev/null)"
|
||
|
|
||
|
if [[ "${ROOT_PART_FS_UUID}" == "${BOOT_PART_FS_UUID}" ]]; then
|
||
|
SUBDIR="/boot"
|
||
|
else
|
||
|
SUBDIR=""
|
||
|
fi
|
||
|
|
||
|
if [[ "${GRUB_LINUX_ROOT_DEVICE}" == "" ]]; then
|
||
|
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 $(ls /boot/vmlinuz-linux*) ; do
|
||
|
|
||
|
echo "Found linux image: ${_KERNEL_}" >&2
|
||
|
|
||
|
_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 "Arch Linux ${_KERNEL_PKG_} kernel" ${CLASS} {
|
||
|
load_video
|
||
|
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 Arch Linux ${_KERNEL_PKG_} kernel ...'
|
||
|
linux ${SUBDIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
|
||
|
echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel initramfs ...'
|
||
|
initrd ${subdir}/${_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 "Arch Linux ${_KERNEL_PKG_} kernel (fallback initramfs)" ${CLASS} {
|
||
|
load_video
|
||
|
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 Arch Linux ${_KERNEL_PKG_} kernel ...'
|
||
|
linux ${SUBDIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
|
||
|
echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel fallback initramfs ...'
|
||
|
initrd ${subdir}/${_INITRAMFS_FALLBACK_}
|
||
|
}
|
||
|
|
||
|
EOF
|
||
|
fi
|
||
|
|
||
|
if [[ ! -e "/boot/${_INITRAMFS_}" ]] && [[ ! -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then
|
||
|
cat << EOF
|
||
|
|
||
|
menuentry "Arch Linux ${_KERNEL_PKG_} kernel (no initramfs)" ${CLASS} {
|
||
|
load_video
|
||
|
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 Arch Linux ${_KERNEL_PKG_} kernel ...'
|
||
|
linux ${SUBDIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS}
|
||
|
}
|
||
|
|
||
|
EOF
|
||
|
fi
|
||
|
|
||
|
done
|