[prev in list] [next in list] [prev in thread] [next in thread]
List: gentoo-dev
Subject: [gentoo-dev] Genkernel
From: Marco Romano <marco.romano () mobyt ! it>
Date: 2003-09-30 12:48:11
[Download RAW message or body]
Hi guys, this is an interactive version of genkernel with some other features
(based on Robin H. Johnson version (1.8))
genkernel-intercative -h (to see help)
genkernel-intercative -i (start in intercative mode)
Bye,
Marco.
--
Mobyt srl
Via Aldighieri, 25/25B
44100 Ferrara - Italy
--------------------------------
Phone : +39 0532 207296
Fax : +39 0532 242952
E-mail: sms@mobyt.it
Web: http://www.mobyt.it
--------------------------------
A Widestore Company.
["genkernel-interactive" (application/x-shellscript)]
#!/bin/bash
# Bob Johnson, 23 March 2003 <livewire@gentoo.org>
# Daniel Robbins, ? 2003 <drobbins@gentoo.org>
# Robin Johnson, 28 September 2003 <robbat2@gentoo.org>
# Marco Romano, 30 September 2003 <marco.romano@mobyt.it>
# Copyright 2002 Gentoo Technologies, Inc; http://www.gentoo.org
# Released under the GNU General Public License version 2
die() {
[ -n "$1" ] && echo "$1"
exit 1
}
f_case() {
/usr/bin/clear && echo -e "\nOk!\n"
}
GK_VERSION=1.8.1
GK_SHARE=/usr/share/genkernel
[ ! -e /sbin/functions.sh ] && die "Can't find /sbin/functions.sh; exiting."
source /sbin/functions.sh
TEMP=/tmp
CONFIG=/etc/kernels
[ ! -e /etc/kernels/settings ] && die "Can't find /etc/kernels/settings; exiting."
source /etc/kernels/settings
BUSYBOX_TARBALL=${GK_SHARE}/busybox-0.60.5.tar.bz2
BUSYBOX_DIR=busybox-0.60.5
MAKEOPTS="$(portageq envvar MAKEOPTS)"
doheader() {
cat <<EOF
Gentoo Linux genkernel, version ${GK_VERSION}
Copyright 2003 Gentoo Technologies, Inc., Bob Johnson, Daniel Robbins, Robin \
Johnson, Marco Romano Distributed under the GNU General Public License version 2
EOF
}
dohelp() {
doheader 1>&2
cat 1>&2 <<EOF
Syntax:
genkernel [-c|--config] [-b|--bootsplash BOOTSPLASHINITRD] [-d|--kernel-directory \
DIRECTORY] \\ [-h|--help] [-k|--kernel-version VERSION] [-p|--package] \
[-s|--skip-mrproper] \\ [-l|--list-kernel] [-i|--interactive]
Parameters:
-c|--config - Provides the ncurses configuration for the kernel.
-b|--bootsplash BOOTSPLASHINITRD - Build bootsplash support into the initrd.
-d|--kernel-directory DIRECTORY - Specify a non-standard path to the kernel sources.
-h|--help - This page.
-k|--kernel-version VERSION - Run genkernel against a specific kernel version.
-p|--package - Create a tarball of the kernel et al after building it.
-s|--skip-mrproper - Skip the 'make mrproper' stage of the kernel build (useful for \
kernel tweaking).
-l|--list-kernel - List all kernel and start the interactive mode
-i|--interactive - Start genkernel in (simple) interactive mode
EOF
}
# this was in the old code, seems obsolete as it isn't used
#KERNEL=$1
# parameter defaults
MENUCONFIG="no"
SKIP_MRPROPER="no"
LIST_SYSKERNEL="no"
PACKAGE="no"
BOOTSPLASH="no"
KD=""
KV=""
INTERACTIVE="no"
# special vars
KD_GENERATED="yes"
KV_GENERATED="yes"
GETOPT_TEMP=`getopt -o cb:d:hk:plis --long \
config,bootsplash:,help,kernel-version:,kernel-directory:,package,list-kernel,interactive,skip-mrproper \
-- "$@"` if [ $? != 0 ] ; then die "getopt error!" ; fi
# Note the quotes around `$GETOPT_TEMP': they are essential!
eval set -- "${GETOPT_TEMP}"
while true; do
case "${1}" in
-c|--config) MENUCONFIG="yes" ; shift ;;
-b|--bootsplash) BOOT_SPLASH_INITRD="${2}" ; BOOTSPLASH="yes" ; shift 2 ;;
-d|--kernel-directory) KD="${2}" ; KD_GENERATED="no" ; shift 2 ;;
-h|--help) dohelp ; die ;;
-k|--kernel-version) KV="${2}" ; KV_GENERATED="no" ; shift 2 ;;
-p|--package) PACKAGE="yes" ; shift ;;
-s|--skip-mrproper) SKIP_MRPROPER="yes" ; shift ;;
-l|--list-kernel) LIST_SYSKERNEL="yes"; shift ;;
-i|--interactive) INTERACTIVE="yes"; shift ;;
--) shift ; break ;;
*) die "Invalid argument!" ;;
esac
done
#function for interactive mode
start_int_mode() {
#boolean var
local MP=0
local MC=0
local MT=0
while [ "${SELECT}" != "9" ]; do
echo -e "Press CTRL+C to quit\n";
echo -e "[*] Select option\n"
echo -e "\t1) Set Kernel Directory"
echo -e "\t2) Set Kernel Version"
echo -e "\t3) Skip mrproper";
echo -e "\t4) Enable ncurses kernel configuration";
echo -e "\t5) Build bootsplash support into the initrd";
echo -e "\t6) Listing all kernel in portage tree";
echo -e "\t7) Create tarball of kernel";
echo -e "\t8) See Help";
echo -e "\t9) Start building\n";
echo -e "Make your choice :"
read SELECT
case "${SELECT}" in
1)
echo -e "\n\tInsert Kernel Directory [now: $KD]"
read KD
if [ "${KD}" = "" ];
then
echo -e "Nothing is changed... come back to default\n"
KD_GENERATED="yes"
sleep 1
else
KD_GENERATED="no"
fi
f_case;;
2)
echo -e "\n\tInsert Kernel Version [now: $KV]"
read KV
if [ "${KV}" = "" ];
then
echo -e "Nothing is changed... come back to default\n"
KV_GENERATED="yes"
sleep 1
else
KV_GENERATED="no"
fi
f_case;;
3)
if [ ${MP} -eq 0 ]
then
MP=1
SKIP_MRPROPER="yes"
/usr/bin/clear && echo -e "\n\tOk mrproper will be skipped\n"
else
MP=0
SKIP_MRPROPER="no"
/usr/bin/clear && echo -e "\n\tOk mrproper will be not skipped\n"
fi
echo -e "\nOk!\n";;
4)
if [ ${MC} -eq 0 ]
then
MC=1
MENUCONFIG="yes"
/usr/bin/clear && echo -e "\n\tOk menuconfig enabled\n"
else
MC=0
MENUCONFIG="no"
/usr/bin/clear && echo -e "\n\tOk menuconfig disabled\n"
fi
echo -e "\nOk!\n";;
5)
echo -e "\n\tInsert path to the bootsplash initrd commands [now: \
${BOOT_SPLASH_INITRD}]" read BOOT_SPLASH_INITRD
if [ "${BOOT_SPLASH_INITRD}" = "" ];
then
echo -e "Nothing is changed... come back to default\n"
BOOTSPLASH="no"
sleep 1
else
BOOTSPLASH="yes"
fi
f_case;;
6)
/usr/bin/clear
echo -e "\nIn /usr/portage/sys-kernel/ there are/is :\n"
list_sk /usr/portage/sys-kernel/
echo -e "\nIn /usr/src there are/is :\n"
list_sk /usr/src/
echo -e "\n- End -\n\n"
echo -e "\tDo you want to merge a kernel ? [y|n]"
read RESP
if [ "${RESP}" = "y" -o "${RESP}" = "Y" ]
then
echo -e "\n\tInsert kernel name"
read K_NAME
merge $K_NAME
else
echo -e "\n\tNo!\n"
fi
f_case;;
7)
if [ ${MT} -eq 0 ]
then
MT=1
PACKAGE="yes"
/usr/bin/clear && echo -e "\n\tOk package (tar) enabled\n"
else
MT=0
PACKAGE="no"
/usr/bin/clear && echo -e "\n\tOk package (tar) disabled\n"
fi
echo -e "\nOk!\n";;
8)
/usr/bin/clear && dohelp
;;
9)
/usr/bin/clear && echo -e "\nGo...\n";;
esac
done
}
#listing first argument
list_sk() {
local LS=`which ls`
for i in `${LS} $1`;
do echo -e "\t[*] $i";
done
}
merge() {
local RESPONSE
/usr/bin/emerge -pv $1
echo -e "\n\tDo you want to continue ? [y|n]"
read RESPONSE
if [ "${RESPONSE}" = "y" -o "${RESPONSE}" = "Y" ]
then
echo -e "\tOk... let's going to merge\n"
/usr/bin/clear && /usr/bin/emerge $1
echo -e "\nIn /usr/src there are :\n"
list_sk /usr/src/
echo -e "\n- End -\n\n"
else
echo -e "\tOk, exit!\n"
fi
}
# this is the usual case when no KD/KV is provided
generate_KV() {
if [ ! -e /usr/src/linux ]
then
echo "/usr/src/linux doesn't seem to exist. Please emerge your favorite"
echo "kernel source tree first. (see -l option)"
die
fi
if [ ! -h /usr/src/linux ]
then
echo "/usr/src/linux is not a symbolic link. Please make sure it is a"
echo "symbolic link to your preferred kernel source tree."
die
fi
KD=`readlink -f /usr/src/linux`
KV="${KD##*/}"
KV="${KV##linux-}"
}
# this is the special case when KV/KD were specified
check_KV() {
# KV was specified but not KD, so we generate KD
[ -z "${KD}" ] && KD="/usr/src/linux-${KV}"
# KD was specified but not KV, so we generate KV
if [ -z "${KV}" -a -n "${KD}" ]
then
KV="${KD##*/}"
KV="${KV##linux-}"
fi
# check KD value
if [ ! -d "${KD}" ]
then
echo "The specified kernel directory (${KD}) does not exist!"
if [ "${KD_GENERATED}" == "yes" ]
then
echo "Use the --kernel-directory option if your source is not at ${KD}"
else
echo "Please correct your parameter to --kernel-directory"
fi
die
fi
}
if [ "${INTERACTIVE}" = "yes" ]
then
echo -e "\nStart Interactive mode...\n\n"
start_int_mode
fi
if [ "${LIST_SYSKERNEL}" = "yes" ]
then
echo -e "\nIn /usr/portage/sys-kernel/ there are/is :\n"
list_sk /usr/portage/sys-kernel/
echo -e "\nIn /usr/src there are/is :\n"
list_sk /usr/src/
echo -e "\n- End -\n\n"
echo -e "\tDo you want to merge a kernel ? [y|n]"
read RESP
if [ "${RESP}" = "y" -o "${RESP}" = "Y" ]
then
echo -e "\n\tInsert kernel name"
read K_NAME
merge $K_NAME
else
echo -e "\n\tOk, Bye!\n"
fi
start_int_mode
fi
if [ "${KD_GENERATED}" = "yes" -a "${KV_GENERATED}" = "yes" ]
then
generate_KV
else
check_KV
fi
check_bootsplash() {
if [ ! -s "${BOOT_SPLASH_INITRD}" ]; then
eerror "BOOT_SPLASH_INITRD must be the path to the bootsplash initrd commands"
die
fi
}
[ "${BOOTSPLASH}" = "yes" ] && check_bootsplash
root_device() {
local myroot
local mylink
myroot=`awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' /etc/fstab`
if [ ! -e "$myroot" ]
then
echo "I can't find the root device specified in /etc/fstab: ${myroot}."
echo "Please configure your /etc/fstab file correctly, and then try again. "
die
fi
mylink="`readlink $myroot`"
if [ $? -eq 0 ]
then
#expanded a symlink....
myroot="$mylink"
fi
ROOT_DEVICE=$myroot
}
configuration() {
doheader
echo
echo "Settings:"
# echo " root device: ${ROOT_DEVICE}"
if [ "$MAKEOPTS" = "" ]
then
echo " make options: (none) (set in make.conf)"
else
echo " make options: ${MAKEOPTS} (from Portage/make.conf)"
fi
echo " source tree: ${KD}"
echo -n " config type: "
if [ -e ${CONFIG}/config-${KV} ]
then
echo -e "gentoo (customized)\n config loc: ${CONFIG}/config-${KV}"
elif [ -e ${KD}/kernel-config ]
then
echo -e "gentoo (default)\n config loc: ${KD}/kernel-config"
else
echo -e "non-gentoo (default)\n config loc: ${CONFIG}/default-config"
fi
echo -n " initrd config: "
if [ -e ${KD}/settings ]
then
echo "(kernel) ${KD}/settings"
source ${KD}/settings || die "Error sourcing ${KD}/settings; exiting."
else
echo "(default) ${CONFIG}/settings"
source ${CONFIG}/settings || die "Error sourcing ${CONFIG}/settings; exiting."
fi
echo
cd ${KD}
if [ "${SKIP_MRPROPER}" = "no" ]; then
ebegin "Running \"make mrproper\""
#running make mrproper fixes unresolved symbol stuff when switching CPU types with
#the custom configure option.
make mrproper > /dev/null
eend
else
einfo "Skipping mrproper as requested"
ewarn "If you have problems compiling or running the kernel,"
ewarn "it is recommended that you ensure mrproper is run again"
fi
if [ -e ${CONFIG}/config-${KV} ]
then
cp -f ${CONFIG}/config-${KV} ${KD}/.config || die "couldn't copy 1"
elif [ -e ${KD}/kernel-config ]
then
cp -f ${KD}/kernel-config ${KD}/.config || die "couldn't copy 2"
else
cp -f ${CONFIG}/default-config ${KD}/.config || die "couldn't copy 3"
fi
ebegin "Running \"make oldconfig\""
while true;do echo -e "\n";done|make oldconfig >/dev/null
eend
if [ "$MENUCONFIG" = "yes" ]
then
echo
echo "You will now be able to make customizations to your kernel configuration."
echo "Any changes you make will be saved in ${CONFIG}/config-${KV}."
echo "Your changes will also be used automatically the next time you use"
echo "genkernel to build the ${KV} kernel."
echo
echo "Hit enter to begin."
read
make menuconfig
if [ $? -eq 0 ]
then
cp ${KD}/.config ${CONFIG}/config-${KV}
else
echo "Error running \"make menuconfig\"; exiting."
die
fi
fi
}
compile() {
local compile
ebegin "Logging to /var/log/genkernel.log"; eend;
ebegin "Starting ${KV} build"; eend
ebegin "Running \"make dep\""
make dep >/var/log/genkernel.log 2>&1 ||die; eend
ebegin "Running \"make bzImage\""
make $MAKEOPTS bzImage >/var/log/genkernel.log 2>&1 || die; eend
ebegin "Running \"make modules\""
make $MAKEOPTS modules >/var/log/genkernel.log 2>&1 || die; eend
ebegin "Running \"make modules_install\""
make modules_install >/var/log/genkernel.log 2>&1 || die; eend
local BOOT_MOUNTED="no"
[ -z "$(mount |egrep 'on /boot\>')" ] && BOOT_MOUNTED="yes"
[ "${BOOT_MOUNTED}" = "no" ] && mount /boot > /dev/null 2>&1
ebegin "Moving bzImage to /boot/kernel-${KV}"
cp arch/i386/boot/bzImage /boot/kernel-${KV} || die; eend
ebegin "Copying System.map to /boot/System.map-${KV}"
cp System.map /boot/System.map-${KV}
rm -f /boot/System.map.old
if [ -L /boot/System.map ]
then
rm /boot/System.map
elif [ -e /boot/System.map ]
then
mv -f /boot/System.map /boot/System.map.old
fi
ln -s System.map-${KV} /boot/System.map
eend
}
busybox() {
local busy
ebegin "Building busybox"
cd ${TEMP}
rm -rf ${BUSYBOX_DIR}
tar -xjf ${BUSYBOX_TARBALL}
cd ${BUSYBOX_DIR}
cp Config.h Config.h.orig
sed -e "s://#define BB_INSMOD:#define BB_INSMOD:" \
-e "s://#define BB_PIVOT_ROOT:#define BB_PIVOT_ROOT:" \
-e "s://#define BB_LOADKMAP:#define BB_LOADKMAP:" \
-e "s://#define BB_LOSETUP:#define BB_LOSETUP:" \
-e "s://#define BB_RMMOD:#define BB_RMMOD:" Config.h.orig > Config.h
make clean
make DOSTATIC=true
install -d ${TEMP}/kernel-initrd
dd if=/dev/zero of=${TEMP}/initrd bs=1k count=5000
mke2fs -F -q -N5000 ${TEMP}/initrd
mount -t ext2 -o loop ${TEMP}/initrd ${TEMP}/kernel-initrd
install -d ${TEMP}/kernel-initrd/{bin,etc,usr,proc,tmp,.initrd,new_root}
ln -s bin ${TEMP}/kernel-initrd/sbin
ln -s ../bin ${TEMP}/kernel-initrd/usr/bin
ln -s ../bin ${TEMP}/kernel-initrd/usr/sbin
install -d ${TEMP}/kernel-initrd/keymaps
cp ${GK_SHARE}/keymaps/key.lst ${TEMP}/kernel-initrd/keymaps
tar xzf ${GK_SHARE}/keymaps/bin-keymaps.tar.gz -C \
${TEMP}/kernel-initrd/keymaps
(mkdir ${TEMP}/kernel-initrd/dev;cd ${TEMP}/kernel-initrd/dev;MAKEDEV \
generic-i386;MAKEDEV scd) cat >${TEMP}/kernel-initrd/etc/fstab <<EOF
/dev/ram0 / auto defaults
proc /proc proc defaults 0 0
EOF
cp ${TEMP}/${BUSYBOX_DIR}/busybox ${TEMP}/kernel-initrd/bin
for i in '[' ash basename cat chroot clear cp dirname echo env false find \
grep gunzip gzip insmod ln ls loadkmap losetup lsmod mkdir mknod modprobe \
more mount mv \
pivot_root ps awk pwd rm rmdir rmmod sh sleep tar test touch true umount \
uname \ xargs yes zcat chmod chown; do
rm -f ${TEMP}/kernel-initrd/bin/$i
ln ${TEMP}/kernel-initrd/bin/busybox ${TEMP}/kernel-initrd/bin/$i
done
eend
}
initrd() {
ebegin "Creating initrd"
local modc i mods mymod
for modc in storage firewire ataraid pcmcia usb
do
install -d ${TEMP}/kernel-initrd/modules/${modc}
mods=`echo $modc | tr [:lower:] [:upper:]`_MODULES
for i in ${!mods}
do
mymod=`find /lib/modules/${KV} -name "${i}.o"`
if [ -z "${mymod}" ]
then
echo "Warning: ${i}.o not found; skipping..."
continue
fi
cp $mymod ${TEMP}/kernel-initrd/modules/${modc}
done
done
#tweak our storage module settings based on our initrd
cat ${GK_SHARE}/linuxrc | sed -e "s/##STORAGE_MODULES##/${STORAGE_MODULES}/" \
\
-e "s/##FIREWIRE_MODULES##/${FIREWIRE_MODULES}/" \
-e "s/##ATARAID_MODULES##/${ATARAID_MODULES}/" \
-e "s/##PCMCIA_MODULES##/${PCMCIA_MODULES}/" \
-e "s/##USB_MODULES##/${USB_MODULES}/" \
> ${TEMP}/kernel-initrd/linuxrc
chmod +x ${TEMP}/kernel-initrd/linuxrc
umount ${TEMP}/initrd
if [ "${BOOTSPLASH}" = "yes" ]
then
ebegin "Adding Bootsplash Initrd"
cat ${BOOT_SPLASH_INITRD} >> ${TEMP}/initrd || die
cp -f ${TEMP}/initrd /boot/initrd-${KV}
eend
else
gzip -f -9 ${TEMP}/initrd
mv -f ${TEMP}/initrd.gz /boot/initrd-${KV}
eend
fi
}
buildpkg() {
local build
if [ "${PACKAGE}" = "yes" ]
then
ebegin "Building Kernel Package"
mkdir ${TEMP}/genkernel
cp /boot/kernel-${KV} ${TEMP}/genkernel
cp /boot/initrd-${KV} ${TEMP}/genkernel
cp -rf /lib/modules/${KV} ${TEMP}/genkernel
cp -f /usr/src/linux-${KV}/.config ${TEMP}/genkernel/config
cd ${TEMP}
tar -jcvf /root/kernel-${KV}.tar.bz2 genkernel 2>&1 || die
rm -rf ${TEMP}/genkernel
echo $WARN " * Copied Kernel package to /root/kernel-${KV}.tar.bz2"
eend
fi
}
finish() {
echo
einfo "Build completed successfully!"
echo
einfo "Please specify /boot/kernel-${KV} and /boot/initrd-${KV}"
einfo "when customizing your boot loader configuration files."
echo
einfo "A detailed log can be found at /var/log/genkernel.log."
rm -rf /tmp/KV
rm -rf ${TEMP}/kernel-initrd
rm -rf ${TEMP}/${BUSYBOX_DIR}
}
#root_device
configuration
compile
ebegin "Building busybox"
busybox >/var/log/genkernel.log 2>&1
eend
ebegin "Creating initrd"
initrd >/var/log/genkernel.log 2>&1
eend
buildpkg
finish
exit 0
--
gentoo-dev@gentoo.org mailing list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic