parent
ebc7806e16
commit
ce1e10241b
@ -1,39 +0,0 @@
|
|||||||
# $Id$
|
|
||||||
|
|
||||||
DEPENDENCIES:
|
|
||||||
- GCC and binutils
|
|
||||||
- GNU Bash
|
|
||||||
- PaX Utilities
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
See http://www.gentoo.org/doc/en/genkernel.xml or
|
|
||||||
issue ``genkernel --help''.
|
|
||||||
|
|
||||||
PORTING:
|
|
||||||
To port to other arches:
|
|
||||||
|
|
||||||
# cd /usr/share/genkernel
|
|
||||||
# cp -Rp x86 ${myarch}
|
|
||||||
# mkdir /usr/share/genkernel/pkg/${myarch}
|
|
||||||
|
|
||||||
Modify what is needed in the /usr/share/genkernel/${myarch}
|
|
||||||
directory, as well making a generic kernel-config.
|
|
||||||
|
|
||||||
IMPORTANT KERNEL NOTES:
|
|
||||||
- You MUST have /dev/pts turned on.
|
|
||||||
- To boot genkernel properly, the kernel config must have
|
|
||||||
Initial RAM disk support.
|
|
||||||
|
|
||||||
BOOTING A KERNEL WITH INITRD:
|
|
||||||
|
|
||||||
GRUB:
|
|
||||||
root= needs to point to your root partition
|
|
||||||
vga= should be the resolution you want your screen. 0x317 is
|
|
||||||
1024x768 - 16bpp and you'll get a pretty splash if
|
|
||||||
configured properly
|
|
||||||
|
|
||||||
GRUB EXAMPLE ENTRY:
|
|
||||||
title=2.6.0 [ Genkernel ]
|
|
||||||
root (hd0,0)
|
|
||||||
kernel (hd0,0)/boot/kernel-2.6.0-gentoo root=/dev/hda3 vga=0x317
|
|
||||||
initrd (hd0,0)/boot/initrd-2.6.0-gentoo
|
|
File diff suppressed because it is too large
Load Diff
@ -1,177 +1,177 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
set_bootloader() {
|
set_bootloader() {
|
||||||
case "${BOOTLOADER}" in
|
case "${BOOTLOADER}" in
|
||||||
grub)
|
grub)
|
||||||
set_bootloader_grub
|
set_bootloader_grub
|
||||||
;;
|
;;
|
||||||
grub2)
|
grub2)
|
||||||
set_bootloader_grub2
|
set_bootloader_grub2
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
print_warning "Bootloader ${BOOTLOADER} is not currently supported"
|
print_warning "Bootloader ${BOOTLOADER} is not currently supported"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_read_fstab() {
|
set_bootloader_read_fstab() {
|
||||||
local ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab)
|
local ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab)
|
||||||
local BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab)
|
local BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab)
|
||||||
|
|
||||||
# If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as /
|
# If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as /
|
||||||
[ -z "${BOOTFS}" ] && BOOTFS=${ROOTFS}
|
[ -z "${BOOTFS}" ] && BOOTFS=${ROOTFS}
|
||||||
|
|
||||||
echo "${ROOTFS} ${BOOTFS}"
|
echo "${ROOTFS} ${BOOTFS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub_read_device_map() {
|
set_bootloader_grub_read_device_map() {
|
||||||
# Read GRUB device map
|
# Read GRUB device map
|
||||||
[ ! -d ${TEMP} ] && mkdir ${TEMP}
|
[ ! -d ${TEMP} ] && mkdir ${TEMP}
|
||||||
echo "quit" | grub --batch --device-map=${TEMP}/grub.map &>/dev/null
|
echo "quit" | grub --batch --device-map=${TEMP}/grub.map &>/dev/null
|
||||||
echo "${TEMP}/grub.map"
|
echo "${TEMP}/grub.map"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub2() {
|
set_bootloader_grub2() {
|
||||||
local GRUB_CONF
|
local GRUB_CONF
|
||||||
for candidate in \
|
for candidate in \
|
||||||
"${BOOTDIR}/grub2/grub.cfg" \
|
"${BOOTDIR}/grub2/grub.cfg" \
|
||||||
"${BOOTDIR}/grub/grub.cfg" \
|
"${BOOTDIR}/grub/grub.cfg" \
|
||||||
; do
|
; do
|
||||||
if [[ -e "${candidate}" ]]; then
|
if [[ -e "${candidate}" ]]; then
|
||||||
GRUB_CONF=${candidate}
|
GRUB_CONF=${candidate}
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "${GRUB_CONF}" ]]; then
|
if [[ -z "${GRUB_CONF}" ]]; then
|
||||||
print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first."
|
print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_info 1 "You can customize Grub2 parameters in /etc/default/grub."
|
print_info 1 "You can customize Grub2 parameters in /etc/default/grub."
|
||||||
print_info 1 "Running grub2-mkconfig to create ${GRUB_CONF}..."
|
print_info 1 "Running grub2-mkconfig to create ${GRUB_CONF}..."
|
||||||
grub2-mkconfig -o "${GRUB_CONF}"
|
grub2-mkconfig -o "${GRUB_CONF}"
|
||||||
[ "${BUILD_RAMDISK}" -ne 0 ] && sed -i 's/ro single/ro debug/' "${GRUB_CONF}"
|
[ "${BUILD_RAMDISK}" -ne 0 ] && sed -i 's/ro single/ro debug/' "${GRUB_CONF}"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub() {
|
set_bootloader_grub() {
|
||||||
local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
|
local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
|
||||||
|
|
||||||
print_info 1 "Adding kernel to ${GRUB_CONF}..."
|
print_info 1 "Adding kernel to ${GRUB_CONF}..."
|
||||||
|
|
||||||
if [ ! -e ${GRUB_CONF} ]
|
if [ ! -e ${GRUB_CONF} ]
|
||||||
then
|
then
|
||||||
local GRUB_BOOTFS
|
local GRUB_BOOTFS
|
||||||
if [ -n "${BOOTFS}" ]
|
if [ -n "${BOOTFS}" ]
|
||||||
then
|
then
|
||||||
GRUB_BOOTFS=$BOOTFS
|
GRUB_BOOTFS=$BOOTFS
|
||||||
else
|
else
|
||||||
GRUB_BOOTFS=$(set_bootloader_read_fstab | cut -d' ' -f2)
|
GRUB_BOOTFS=$(set_bootloader_read_fstab | cut -d' ' -f2)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get the GRUB mapping for our device
|
# Get the GRUB mapping for our device
|
||||||
local GRUB_BOOT_DISK1=$(echo ${GRUB_BOOTFS} | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
|
local GRUB_BOOT_DISK1=$(echo ${GRUB_BOOTFS} | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
|
||||||
local GRUB_BOOT_DISK=$(awk '{if ($2 == "'${GRUB_BOOT_DISK1}'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${TEMP}/grub.map)
|
local GRUB_BOOT_DISK=$(awk '{if ($2 == "'${GRUB_BOOT_DISK1}'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${TEMP}/grub.map)
|
||||||
local GRUB_BOOT_PARTITION=$(($(echo ${GRUB_BOOTFS} | sed -e 's#/dev/.\+\([[:digit:]]?*\)#\1#') - 1))
|
local GRUB_BOOT_PARTITION=$(($(echo ${GRUB_BOOTFS} | sed -e 's#/dev/.\+\([[:digit:]]?*\)#\1#') - 1))
|
||||||
|
|
||||||
if [ -n "${GRUB_BOOT_DISK}" -a -n "${GRUB_BOOT_PARTITION}" ]
|
if [ -n "${GRUB_BOOT_DISK}" -a -n "${GRUB_BOOT_PARTITION}" ]
|
||||||
then
|
then
|
||||||
|
|
||||||
# Create grub configuration directory and file if it doesn't exist.
|
# Create grub configuration directory and file if it doesn't exist.
|
||||||
[ ! -d `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}`
|
[ ! -d `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}`
|
||||||
|
|
||||||
touch ${GRUB_CONF}
|
touch ${GRUB_CONF}
|
||||||
echo 'default 0' >> ${GRUB_CONF}
|
echo 'default 0' >> ${GRUB_CONF}
|
||||||
echo 'timeout 5' >> ${GRUB_CONF}
|
echo 'timeout 5' >> ${GRUB_CONF}
|
||||||
echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${GRUB_CONF}
|
echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${GRUB_CONF}
|
||||||
echo >> ${GRUB_CONF}
|
echo >> ${GRUB_CONF}
|
||||||
|
|
||||||
# Add grub configuration to grub.conf
|
# Add grub configuration to grub.conf
|
||||||
echo "# Genkernel generated entry, see GRUB documentation for details" >> ${GRUB_CONF}
|
echo "# Genkernel generated entry, see GRUB documentation for details" >> ${GRUB_CONF}
|
||||||
echo "title=Gentoo Linux ($KV)" >> ${GRUB_CONF}
|
echo "title=Gentoo Linux ($KV)" >> ${GRUB_CONF}
|
||||||
echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
|
echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
|
||||||
if [ "${BUILD_INITRD}" = '1' ]
|
if [ "${BUILD_INITRD}" = '1' ]
|
||||||
then
|
then
|
||||||
if [ "${PAT}" -gt '4' ]
|
if [ "${PAT}" -gt '4' ]
|
||||||
then
|
then
|
||||||
echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF}
|
echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo >> ${GRUB_CONF}
|
echo >> ${GRUB_CONF}
|
||||||
else
|
else
|
||||||
print_error 1 "Error! ${BOOTDIR}/grub/grub.conf does not exist and the correct settings can not be automatically detected."
|
print_error 1 "Error! ${BOOTDIR}/grub/grub.conf does not exist and the correct settings can not be automatically detected."
|
||||||
print_error 1 "Please manually create your ${BOOTDIR}/grub/grub.conf file."
|
print_error 1 "Please manually create your ${BOOTDIR}/grub/grub.conf file."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
# The grub.conf already exists, so let's try to duplicate the default entry
|
# The grub.conf already exists, so let's try to duplicate the default entry
|
||||||
if set_bootloader_grub_check_for_existing_entry "${GRUB_CONF}"; then
|
if set_bootloader_grub_check_for_existing_entry "${GRUB_CONF}"; then
|
||||||
print_warning 1 "An entry was already found for a kernel/initramfs with this name...skipping update"
|
print_warning 1 "An entry was already found for a kernel/initramfs with this name...skipping update"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set_bootloader_grub_duplicate_default "${GRUB_CONF}"
|
set_bootloader_grub_duplicate_default "${GRUB_CONF}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub_duplicate_default_replace_kernel_initrd() {
|
set_bootloader_grub_duplicate_default_replace_kernel_initrd() {
|
||||||
sed -r -e "/^[[:space:]]*kernel/s/kernel-[[:alnum:][:punct:]]+/kernel-${KNAME}-${ARCH}-${KV}/" - |
|
sed -r -e "/^[[:space:]]*kernel/s/kernel-[[:alnum:][:punct:]]+/kernel-${KNAME}-${ARCH}-${KV}/" - |
|
||||||
sed -r -e "/^[[:space:]]*initrd/s/init(rd|ramfs)-[[:alnum:][:punct:]]+/init\1-${KNAME}-${ARCH}-${KV}/"
|
sed -r -e "/^[[:space:]]*initrd/s/init(rd|ramfs)-[[:alnum:][:punct:]]+/init\1-${KNAME}-${ARCH}-${KV}/"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub_check_for_existing_entry() {
|
set_bootloader_grub_check_for_existing_entry() {
|
||||||
local GRUB_CONF=$1
|
local GRUB_CONF=$1
|
||||||
if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" &&
|
if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" &&
|
||||||
grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}"
|
grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}"
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
set_bootloader_grub_duplicate_default() {
|
set_bootloader_grub_duplicate_default() {
|
||||||
local GRUB_CONF=$1
|
local GRUB_CONF=$1
|
||||||
local GRUB_CONF_TMP="${GRUB_CONF}.tmp"
|
local GRUB_CONF_TMP="${GRUB_CONF}.tmp"
|
||||||
|
|
||||||
line_count=$(wc -l < "${GRUB_CONF}")
|
line_count=$(wc -l < "${GRUB_CONF}")
|
||||||
line_nums="$(grep -n "^title" "${GRUB_CONF}" | cut -d: -f1)"
|
line_nums="$(grep -n "^title" "${GRUB_CONF}" | cut -d: -f1)"
|
||||||
if [ -z "${line_nums}" ]; then
|
if [ -z "${line_nums}" ]; then
|
||||||
print_error 1 "No current 'title' entries found in your grub.conf...skipping update"
|
print_error 1 "No current 'title' entries found in your grub.conf...skipping update"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
line_nums="${line_nums} $((${line_count}+1))"
|
line_nums="${line_nums} $((${line_count}+1))"
|
||||||
|
|
||||||
# Find default entry
|
# Find default entry
|
||||||
default=$(sed -rn '/^[[:space:]]*default[[:space:]=]/s/^.*default[[:space:]=]+([[:alnum:]]+).*$/\1/p' "${GRUB_CONF}")
|
default=$(sed -rn '/^[[:space:]]*default[[:space:]=]/s/^.*default[[:space:]=]+([[:alnum:]]+).*$/\1/p' "${GRUB_CONF}")
|
||||||
if [ -z "${default}" ]; then
|
if [ -z "${default}" ]; then
|
||||||
print_warning 1 "No default entry found...assuming 0"
|
print_warning 1 "No default entry found...assuming 0"
|
||||||
default=0
|
default=0
|
||||||
fi
|
fi
|
||||||
if ! echo ${default} | grep -q '^[0-9]\+$'; then
|
if ! echo ${default} | grep -q '^[0-9]\+$'; then
|
||||||
print_error 1 "We don't support non-numeric (such as 'saved') default values...skipping update"
|
print_error 1 "We don't support non-numeric (such as 'saved') default values...skipping update"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Grub defaults are 0 based, cut is 1 based
|
# Grub defaults are 0 based, cut is 1 based
|
||||||
# Figure out where the default entry lives
|
# Figure out where the default entry lives
|
||||||
startstop=$(echo ${line_nums} | cut -d" " -f$((${default}+1))-$((${default}+2)))
|
startstop=$(echo ${line_nums} | cut -d" " -f$((${default}+1))-$((${default}+2)))
|
||||||
startline=$(echo ${startstop} | cut -d" " -f1)
|
startline=$(echo ${startstop} | cut -d" " -f1)
|
||||||
stopline=$(echo ${startstop} | cut -d" " -f2)
|
stopline=$(echo ${startstop} | cut -d" " -f2)
|
||||||
|
|
||||||
# Write out the bits before the default entry
|
# Write out the bits before the default entry
|
||||||
sed -n 1,$((${startline}-1))p "${GRUB_CONF}" > "${GRUB_CONF_TMP}"
|
sed -n 1,$((${startline}-1))p "${GRUB_CONF}" > "${GRUB_CONF_TMP}"
|
||||||
|
|
||||||
# Put in our title
|
# Put in our title
|
||||||
echo "title=Gentoo Linux (${KV})" >> "${GRUB_CONF_TMP}"
|
echo "title=Gentoo Linux (${KV})" >> "${GRUB_CONF_TMP}"
|
||||||
|
|
||||||
# Pass the default entry (minus the title) through to the replacement function and pipe the output to GRUB_CONF_TMP
|
# Pass the default entry (minus the title) through to the replacement function and pipe the output to GRUB_CONF_TMP
|
||||||
sed -n $((${startline}+1)),$((${stopline}-1))p "${GRUB_CONF}" | set_bootloader_grub_duplicate_default_replace_kernel_initrd >> "${GRUB_CONF_TMP}"
|
sed -n $((${startline}+1)),$((${stopline}-1))p "${GRUB_CONF}" | set_bootloader_grub_duplicate_default_replace_kernel_initrd >> "${GRUB_CONF_TMP}"
|
||||||
|
|
||||||
# Finish off with everything including the previous default entry
|
# Finish off with everything including the previous default entry
|
||||||
sed -n ${startline},${line_count}p "${GRUB_CONF}" >> "${GRUB_CONF_TMP}"
|
sed -n ${startline},${line_count}p "${GRUB_CONF}" >> "${GRUB_CONF_TMP}"
|
||||||
|
|
||||||
cp "${GRUB_CONF}" "${GRUB_CONF}.bak"
|
cp "${GRUB_CONF}" "${GRUB_CONF}.bak"
|
||||||
cp "${GRUB_CONF_TMP}" "${GRUB_CONF}"
|
cp "${GRUB_CONF_TMP}" "${GRUB_CONF}"
|
||||||
rm "${GRUB_CONF_TMP}"
|
rm "${GRUB_CONF_TMP}"
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue