#!/bin/sh # # Kernel customized install script # # Put it in ~/bin or /sbin # # Author: Adam Drzewiecki # e-mail: A.Drzewiecki@ztpnet.pl # WWW: http://drzewiecki.zgora.pl # # Remarks: # # Arguments provided by linux/arch/.../install.sh: # $1 - kernel version # $2 - kernel image (path & filename) # $3 - kernel map (path & filename, usually only filename) # $4 - install path (empty if path is /) # # Last modified: 09 Feb 2009 # # Read mkinitrd configuration file, if exists if [ -f /etc/mkinitrd.conf ] ; then . /etc/mkinitrd.conf fi # Kernel version is taken from the first argument, not from KERNEL_VERSION from mkinitrd.conf VERSION="$1" # Use argument script KERNEL_IMAGE="$2" KERNEL_MAP="$3" INSTALL_PATH="$4" # Symlink names for vmlinuz, System.map and initial ramdisk VMLINUZ="vmlinuz" MAP="System.map" INITRD="initrd.img" # Filename of initial ramdisk INITRD_FILE="initrd-$VERSION.img" # Copy image and map with new names to install path, preserve old files: # kernel image if [ -e $INSTALL_PATH/$VMLINUZ-$VERSION ]; then cp -f $INSTALL_PATH/$VMLINUZ-$VERSION $INSTALL_PATH/$VMLINUZ-$VERSION.old fi cp -f $KERNEL_IMAGE $INSTALL_PATH/$VMLINUZ-$VERSION # kernel map if [ -e $INSTALL_PATH/$MAP-$VERSION ]; then cp -f $INSTALL_PATH/$MAP-$VERSION $INSTALL_PATH/$MAP-$VERSION.old fi cp -f $KERNEL_MAP $INSTALL_PATH/$MAP-$VERSION # Create symlinks vmlinuz and System.map to new image and map, respectively. # If destination files exists and are not symlinks, preserve them in .old files. if [ -e $INSTALL_PATH/$VMLINUZ -a ! -h $INSTALL_PATH/$VMLINUZ ]; then cp -f $INSTALL_PATH/$VMLINUZ $INSTALL_PATH/$VMLINUZ.old fi ln -fs $INSTALL_PATH/$VMLINUZ-$VERSION $INSTALL_PATH/$VMLINUZ if [ -e $INSTALL_PATH/$MAP -a ! -h $INSTALL_PATH/$MAP ]; then cp -f $INSTALL_PATH/$MAP $INSTALL_PATH/$MAP.old fi ln -fs $INSTALL_PATH/$MAP-$VERSION $INSTALL_PATH/$MAP # # If exists mkinitrd and proper configuration file, create initial ramdisk # if [ -x /sbin/mkinitrd -a -f /etc/mkinitrd.conf -a -n "$MODULE_LIST" ]; then # Searching for current root device ROOT_DEV=$(mount | grep -w "on /" | cut -d " " -f 1) # If ROOT_DEV is a symlink, find real device file if [ -h $ROOT_DEV ] ; then ROOT_DEV=$(readlink -e $ROOT_DEV) fi # Searching for filesystem of current root device ROOT_FS=$(grep -E "($ROOT_DEV|/dev/root)" /proc/mounts | cut -d " " -f 3) # # Configuration for mkinitrd # # Clear build tree (-c), ignoring CLEAR_TREE from mkinitrd.conf # Use mkinitrd.conf (-F) ARGS="-c -F" # Prepare initrd for new kernel, one must ignore KERNEL_VERSION from mkinitrd.conf ARGS="$ARGS -k $VERSION" # If root device is detected, add argument for it if [ -n $ROOT_DEV ] ; then ARGS="$ARGS -r $ROOT_DEV" fi # If root filesystem is detected, add argument for it if [ -n $ROOT_FS ] ; then ARGS="$ARGS -f $ROOT_FS" fi # Add output file argument, ignoring OUTPUT_IMAGE form mkinitrd.conf ARGS="$ARGS -o $INSTALL_PATH/$INITRD_FILE" # # Make initrd and preserve old files # # Preserve old image if exists if [ -e $INSTALL_PATH/$INITRD_FILE ] ; then cp -f $INSTALL_PATH/$INITRD_FILE $INSTALL_PATH/$INITRD_FILE.old fi # Create new initrd echo "mkinitrd $ARGS" mkinitrd $ARGS # Remove source tree if [ -n $SOURCE_TREE ] ; then rm -rf $SOURCE_TREE fi # Create universal symlink and preserve old file if exists if [ -e $INSTALL_PATH/$INITRD -a ! -h $INSTALL_PATH/$INITRD ] ; then cp -f $INSTALL_PATH/$INITRD $INSTALL_PATH/$INITRD.old fi ln -fs $INSTALL_PATH/$INITRD_FILE $INSTALL_PATH/$INITRD else echo echo "Warning: skipped creation of initial ramdisk." echo "If you need it, install mkinitrd package and create config file /etc/mkinitrd.conf" echo "You must set at least MODULE_LIST variable with semicolon separated list of modules." echo fi # Update LILO - boot manager, if exists if [ -x /sbin/lilo ]; then /sbin/lilo fi