Find the answer to your Linux question:
Results 1 to 6 of 6
I just recently finished writing a program that will help automate the task of compiling a kernel, with some help from dylunio and Cabhan in the "Linux Programming & Scripting" ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Enthusiast
    Join Date
    Jun 2005
    Location
    Odessa, FL
    Posts
    586

    install-kernel -- A program to help automate installing a vanilla kernel


    I just recently finished writing a program that will help automate the task of compiling a kernel, with some help from dylunio and Cabhan in the "Linux Programming & Scripting" section of this forum.

    How you would run the program:
    as root,
    Code:
    install-kernel <kernel-version> <grub/lilo> <boot mount point> <root mount point>
    kernel-version is the version of the kernel you'd like to install, without "linux-" in front of it. so, if you'd like to install 2.6.14.3 (the newest), you would type: "2.6.14.3" where kernel-version is.
    grub/lilo is where you type what your bootloader is, between the choices of grub and lilo. if left blank, grub will be chosen automatically.
    boot mount point is where you specify where "/boot" is mounted, if necessary. if none is specified than it will use your root mount point "/", which is explained next.
    root mount point is where you specify where your root partition is...where your operating system is.
    if both boot and root mount points aren't specified, than hda1 will be automatically set for both.


    other things you can do:
    Code:
    install-kernel -s &#40;--show&#41;
    ...will show you the following information...
    1) the kernel currently in use (using "uname -r")
    2) the current kernel version symlinked to /usr/src/linux (using "ls -s /usr/src/linux")
    3) the current kernel sources found in /usr/src (using "ls /usr/src")

    Code:
    install-kernel -h &#40;--help&#41;
    will show a summary of what i've explained above

    Who can use it to its full potential:
    any grub/lilo users and any 2.4 or 2.6 kernel users who wish to use stable releases of vanilla kernels

    What this program actually does when installing a kernel (in detail):
    1. It first shows you what version kernel it's looking for (2.4 or 2.6), it states boot is mounted, and it states where root is mounted....before doing anything else
    2. It checks to make sure that /usr/src/linux exists and, if it does, it uses the .config file found in /usr/src/linux
    3. It downloads the kernel you specify from the vanilla kernel sources website, whether it's a 2.4 kernel or a 2.6 kernel
    4. It removes any other instances of a kernel with the same version as the one you're currently downloading (it prevents potential problems from arising later in the install)
    5. It unpacks the kernel source to /usr/src
    6. It makes sure the kernel unpacked ok
    7. It removes the symlink /usr/src/linux
    8. It symlinks your new kernel to /usr/src/linux and copies the .config file (kernel settings from previous kernel) so the new kernel can use it
    9. It compiles it according to your kernel version (2.4 or 2.6)
    10. It copies bzImage and .config to your /boot directory for use by the bootloader
    11. It creates an entry for this kernel in your bootloader's screen (grub or lilo) at the bottom of the list


    In short: It does everything necessary to upgrade a kernel for you, and everything but choose your kernel options when installing a new kernel

    For those interested, LINK TO DOWNLOAD
    It comes out to a little under 13kb

    To install the program:
    as root,
    Code:
    mv /dir/to/file /usr/sbin/
    (/usr/sbin/ may be /sbin/ on some distributions)
    Code:
    chmod a=w+r+x /usr/sbin/install-kernel
    (once again, this may be /sbin/ instead)

    Please leave a message here or send me an e-mail with any comments, suggestions, or bug info.
    My e-mail address is joshsolanes-installkernel@yahoo.com

    I'm especially interested in responses from those who run a v2.4 kernel, who run lilo as their bootloader, or those who don't have a separate /boot partition. I was unable to test those (I don't have my system set up for these options). I checked the code several times more than that of the grub and v2.6 sections for accuracy and making sure it's written correctly, and as far as I can tell it looks perfect. The v2.6 and grub sections definitely work, though, as I installed a few kernels on my machine to test the program

  2. #2
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    Looks nice... I can't try it atm, soon got to do some homwork for my tentamen tomorrow, but I sure will later :P

  3. #3
    Linux Enthusiast
    Join Date
    Jun 2005
    Location
    Odessa, FL
    Posts
    586
    Quote Originally Posted by jaboua
    Looks nice... I can't try it atm, soon got to do some homwork for my tentamen tomorrow, but I sure will later :P
    ok, thanks

    let me know how it goes when you try it

  4. #4
    Linux Enthusiast
    Join Date
    Jun 2005
    Location
    Odessa, FL
    Posts
    586
    *bump*
    has anyone else tried this? what do you think?

    all comments, suggestions, and criticism are welcome. i would really like this to be useful to most people. right now, it works perfect for my system and i did my best to make it work the same for the widest group of people, but can only do so much....i just need some feedback to know what else i should do

    thanks in advance for any and all responses

  5. #5
    Linux Enthusiast
    Join Date
    Jun 2005
    Location
    Odessa, FL
    Posts
    586
    ^^^
    *bump*


    Is it safe to assume that everyone is either: A) afraid of trying this as it relates to the kernel, or B) not interested in this?

    I'm working on adding more features (possibly autofinding grub or lilo, and your root partition....where your current OS is mounted), and possibly a graphical interface, but I need to learn how to make a graphical interface in the meantime.

    If anyone has tried this, or is willing to, please let me know what you think of it and what can be improved. I added as many if-than statements as possible to prevent mistakes from occuring.

    I'll post the code here for those who are interested:
    Code:
    #!/bin/bash
    if &#91; $# -eq 0 &#93;; then
    	echo "Error&#58; must have a valid modifier"
    	echo "Usage&#58; install-kernel <kernel-version> <grub/lilo> <boot mount point> <root mount point>"
    	echo "-h or --help for help file"
    	exit 0
    fi
    
    if &#91; "$1" = "-h" -o "$1" = "--help" &#93;; then
    	echo "COMMAND											PURPOSE"
    	echo "install-kernel -h &#40;--help&#41;								this help file"
    	echo "install-kernel -s &#40;--show&#41;								show current running kernel, kernel sylinked to /usr/src/linux, and the directories under /usr/src"
    	echo "install-kernel <version> <grub/lilo> <boot mount point> <root mount point>		install the kernel linux-<version> with either grub or lilo depending on what you choose, within the given boot and root mount points"
    	echo ""
    	echo "NOTE&#58; if no bootloader is specified, grub will be chosen automatically"
    	echo "NOTE&#58; the boot mount point must be like in the following example&#58; hda1.  In this case, it's the first harddrive &#40;what the 'a' stands for&#41; and first partition &#40;what the '1' means&#41;.  if no mount point is specified, hda1 will automatically be assigned"
    	echo "NOTE&#58; if no boot mount point is given, than it is assumed to be the root mount point"
    	exit 0
    fi
    
    if &#91; "$1" = "-s" -o "$1" = "--show"  &#93;; then
    	echo "Kernel currently in use&#58;"
    	uname -r
    
    	echo ""
    
            echo "Current kernel version symlinked to /usr/src/linux&#58;"
            ls -l /usr/src/linux
    
    	echo ""
    
    	echo "Currently viable kernel sources&#58;"
    	ls /usr/src
    	exit 0
    fi
    
    version=$1
    kernel_number=$&#123;version&#58;0&#58;3&#125;
    
    loader=$2
    
    mount_point=$3
    
    root_mount_point=$4
    
    loader_mount_point=$&#123;loader&#58;0&#58;2&#125;
    if &#91; "$loader_mount_point" = "hd" &#93;; then
            loader="grub"
            mount_point="$2"
    	root_mount_point="$3"
    fi
    
    if &#91; -z "$mount_point" &#93;; then
    	mount_point="hda1"
    fi
    
    if &#91; -z "$root_mount_point" &#93;; then
    	root_mount_point="$mount_point"
    fi
    
    drive=$&#123;mount_point&#58;2&#58;1&#125;
    partition=$&#123;mount_point&#58;3&#58;2&#125;
    
    if &#91; "$drive" = "a" &#93;; then
    	grub_drive="0"
    elif &#91; "$drive" = "b" &#93;; then
    	grub_drive="1"
    elif &#91; "$drive" = "c" &#93;; then
            grub_drive="2"
    elif &#91; "$drive" = "d" &#93;; then
            grub_drive="3"
    elif &#91; "$drive" = "e" &#93;; then
            grub_drive="4"
    elif &#91; "$drive" = "f" &#93;; then
            grub_drive="5"
    elif &#91; "$drive" = "g" &#93;; then
            grub_drive="6"
    elif &#91; "$drive" = "h" &#93;; then
            grub_drive="7"
    elif &#91; "$drive" = "i" &#93;; then
            grub_drive="8"
    elif &#91; "$drive" = "j" &#93;; then
            grub_drive="9"
    elif &#91; "$drive" = "k" &#93;; then
            grub_drive="10"
    elif &#91; "$drive" = "l" &#93;; then
            grub_drive="11"
    elif &#91; "$drive" = "m" &#93;; then
            grub_drive="12"
    elif &#91; "$drive" = "n" &#93;; then
            grub_drive="13"
    elif &#91; "$drive" = "o" &#93;; then
            grub_drive="14"
    elif &#91; "$drive" = "p" &#93;; then
            grub_drive="15"
    elif &#91; "$drive" = "q" &#93;; then
            grub_drive="16"
    elif &#91; "$drive" = "r" &#93;; then
            grub_drive="17"
    elif &#91; "$drive" = "s" &#93;; then
            grub_drive="18"
    elif &#91; "$drive" = "t" &#93;; then
            grub_drive="19"
    elif &#91; "$drive" = "u" &#93;; then
            grub_drive="20"
    elif &#91; "$drive" = "v" &#93;; then
            grub_drive="21"
    elif &#91; "$drive" = "w" &#93;; then
            grub_drive="22"
    elif &#91; "$drive" = "x" &#93;; then
            grub_drive="23"
    elif &#91; "$drive" = "y" &#93;; then
            grub_drive="24"
    elif &#91; "$drive" = "z" &#93;; then
            grub_drive="25"
    fi
    
    if &#91; "$partition" = "1" &#93;; then
            grub_partition="0"
    elif &#91; "$partition" = "2" &#93;; then
            grub_partition="1"
    elif &#91; "$partition" = "3" &#93;; then
            grub_partition="2"
    elif &#91; "$partition" = "4" &#93;; then
            grub_partition="3"
    elif &#91; "$partition" = "5" &#93;; then
            grub_partition="4"
    elif &#91; "$partition" = "6" &#93;; then
            grub_partition="5"
    elif &#91; "$partition" = "7" &#93;; then
            grub_partition="6"
    elif &#91; "$partition" = "8" &#93;; then
            grub_partition="7"
    elif &#91; "$partition" = "9" &#93;; then
            grub_partition="8"
    elif &#91; "$partition" = "10" &#93;; then
            grub_partition="9"
    elif &#91; "$partition" = "11" &#93;; then
            grub_partition="10"
    elif &#91; "$partition" = "12" &#93;; then
            grub_partition="11"
    elif &#91; "$partition" = "13" &#93;; then
            grub_partition="12"
    elif &#91; "$partition" = "14" &#93;; then
            grub_partition="13"
    elif &#91; "$partition" = "15" &#93;; then
            grub_partition="14"
    elif &#91; "$partition" = "16" &#93;; then
            grub_partition="15"
    elif &#91; "$partition" = "17" &#93;; then
            grub_partition="16"
    elif &#91; "$partition" = "18" &#93;; then
            grub_partition="17"
    elif &#91; "$partition" = "19" &#93;; then
            grub_partition="18"
    elif &#91; "$partition" = "20" &#93;; then
            grub_partition="19"
    elif &#91; "$partition" = "21" &#93;; then
            grub_partition="20"
    elif &#91; "$partition" = "22" &#93;; then
            grub_partition="21"
    elif &#91; "$partition" = "23" &#93;; then
            grub_partition="22"
    elif &#91; "$partition" = "24" &#93;; then
            grub_partition="23"
    elif &#91; "$partition" = "25" &#93;; then
            grub_partition="24"
    elif &#91; "$partition" = "26" &#93;; then
            grub_partition="25"
    fi 
    
    if &#91; -z  "$2" &#93;; then
    	loader="grub"
    fi
    
    echo "Cleaning out /tmp/linux-$version"
    rm -rf /tmp/linux-$version*
    
    if &#91; "$kernel_number" = "2.4" &#93;; then
    	echo "v$kernel_number kernel on $loader, boot mounted at hd$drive$partition, root mounted at $root_mount_point"
    
            checklin=/usr/src/linux
            echo "***Checking to see if $checklin exists"
            if &#91; -d $checklin &#93;; then
                    echo "OK&#58; $checklin exists...using a previous .config file &#58;&#41;"
            else
                    echo "Warning&#58; $checklin does not exist!!  Not using a pre-made kernel .config file"
            fi
    
    	echo "cp /usr/src/linux/.config /usr/src/"
    	cp /usr/src/linux/.config /usr/src
    
            echo "Downloading kernel source from the http&#58;//www.kernel.org/pub/linux/kernel/v$kernel_number/"
            cd /tmp/
            wget http&#58;//www.kernel.org/pub/linux/kernel/v$kernel_number/linux-$version.tar.bz2 /tmp/
    
            echo "Removing any other instances of this kernel version on your system"
            rm -rf /usr/src/linux-$version/
    
            echo "Unpacking kernel source"
            tar -xjvf ./linux-$version.tar.bz2 -C /usr/src
    
            checkdir=/usr/src/linux-$version
            echo "***Checking to see if $checkdir exists"
            if &#91; -d $checkdir &#93;; then
                    echo "OK&#58; $checkdir exists &#58;&#41;"
            else
                    echo "Error&#58; $checkdir does not exist!!  Report this error to the author of this script immediately"
                    echo "EXITING"
                    exit 1
            fi
    
    	echo "rm /usr/src/linux"
            rm /usr/src/linux
            
    	echo "ln -s /usr/src/linux-$version linux"
            ln -s /usr/src/linux-$version /usr/src/linux
    
            echo "mv /usr/src/.config /usr/src/linux/"
            mv /usr/src/.config /usr/src/linux/
    
            echo "cd /usr/src/linux"
            cd /usr/src/linux
    
            echo "make dep"
            make dep
    
            echo "make bzImage modules modules_install"
            make bzImage modules modules_install
    
    	echo "***Making sure /usr/src/linux/arch/i386/boot/bzImage and /usr/src/linux/.config exist"
    	if &#91; -z /usr/src/linux/arch/i386/boot/bzImage &#93;; then
    		echo "Error&#58; /usr/src/linux/arch/i386/boot/bzImage does not exist"
    		echo "EXITING"
    		exit 1
    	fi
    
    	if &#91; -z /usr/src/linux/.config &#93;; then
                    echo "Error&#58; /usr/src/linux/.config does not exist"
                    echo "EXITING"
                    exit 1	
    	fi
    
    	echo "mount /boot"
    	mount /boot
    
            echo "cp ./arch/i386/boot/bzImage /boot/kernel-$version && cp .config /boot/config-$version"
            cp arch/i386/boot/bzImage /boot/kernel-$version && cp .config /boot/config-$version
    
    	echo "Adding linux-$version to the $loader bootloader menu"
    	if &#91; "$loader" = "grub" &#93;; then
    		cd /boot/grub
    		echo "Making backup of grub.conf at /boot/grub/grub.conf.backup"
    		cp ./grub.conf ./grub.conf.backup
    		echo "Editting grub.conf to include your newly compiled kernel"
    		echo "" >> ./grub.conf
    		echo "title=Linux-$version" >> ./grub.conf
    		echo "root &#40;hd$grub_drive,$grub_partition&#41;" >> ./grub.conf
    		if &#91; "$mount_point" = "$root_mount_point" &#93;; then
                            echo "kernel /boot/kernel-$version root=/dev/$root_mount_point" >> ./grub.conf
                    else
                            echo "kernel /kernel-$version root=/dev/$root_mount_point" >> ./grub.conf
                    fi
    	elif &#91; "$loader" = "lilo" &#93;; then
    		cd /etc/
    		echo "Making backup of lilo.conf at /etc/lilo.conf.backup"
    		cp ./lilo.conf ./lilo.conf.backup
    		echo "Editting lilo.conf to include your newly compiled kernel"
    		echo "" >> ./lilo.conf
                    if &#91; "$mount_point" = "$root_mount_point" &#93;; then
                            echo "Image=/boot/kernel-$version" >> ./lilo.conf
                    else
                            echo "Image=/kernel-$version" >> ./lilo.conf
                    fi
    		echo "label=Linux-$version" >> ./lilo.conf
    		echo "read-only" >> ./lilo.conf
    		echo "root=/dev/$root_mount_point" >> ./lilo.conf
    	fi	
    
            echo "umount /boot"
            umount /boot
    
            echo "DONE!!"
    
            exit 0
    
    fi
    
    if &#91; "$kernel_number" = "2.6" &#93;; then
    	echo "v$kernel_number kernel on $loader, boot mounted at hd$drive$partition, root mounted at $root_mount_point"
    
            checklin=/usr/src/linux
            echo "***Checking to see if $checklin exists"
            if &#91; -d $checklin &#93;; then
                    echo "OK&#58; $checklin exists...using a previous .config file &#58;&#41;"
            else
                    echo "Warning&#58; $checklin does not exist!!  Not using a pre-made kernel .config file"
            fi
    
            echo "cp /usr/src/linux/.config /usr/src/"
            cp /usr/src/linux/.config /usr/src
    
            echo "Downloading kernel source from the http&#58;//www.kernel.org/pub/linux/kernel/v$kernel_number/"
            cd /tmp/
            wget http&#58;//www.kernel.org/pub/linux/kernel/v$kernel_number/linux-$version.tar.bz2 /tmp/
    
            echo "Removing any other instances of this kernel version on your system"
            rm -rf /usr/src/linux-$version/
    
            echo "Unpacking kernel source"
            tar -xjvf ./linux-$version.tar.bz2 -C /usr/src
    
            checkdir=/usr/src/linux-$version
            echo "***Checking to see if $checkdir exists"
            if &#91; -d $checkdir &#93;; then
                    echo "OK&#58; $checkdir exists &#58;&#41;"
            else
                    echo "Error&#58; $checkdir does not exist!!  Report this error to the author of this script immediately"
                    echo "EXITING"
                    exit 1
            fi
    
            echo "rm /usr/src/linux"
            rm /usr/src/linux
    
            echo "ln -s /usr/src/linux-$version linux"
            ln -s /usr/src/linux-$version /usr/src/linux
    
            echo "mv /usr/src/.config /usr/src/linux/"
            mv /usr/src/.config /usr/src/linux/
    
            echo "cd /usr/src/linux"
            cd /usr/src/linux
    
            echo "make menuconfig"
            make menuconfig
    
            echo "make && make modules_install"
            make && make modules_install
    
            echo "***Making sure /usr/src/linux/arch/i386/boot/bzImage and /usr/src/linux/.config exit"
            if &#91; -z /usr/src/linux/arch/i386/boot/bzImage &#93;; then
                    echo "Error&#58; /usr/src/linux/arch/i386/boot/bzImage does not exist"
                    echo "EXITING"
                    exit 1
            fi
    
            if &#91; -z /usr/src/linux/.config &#93;; then
                    echo "Error&#58; /usr/src/linux/.config does not exist"
                    echo "EXITING"
                    exit 1
            fi
    
    	echo "mount /boot"
    	mount /boot     	
    
            echo "cp arch/i386/boot/bzImage /boot/kernel-$version && cp .config /boot/config-$version"
            cp arch/i386/boot/bzImage /boot/kernel-$version && cp .config /boot/config-$version
    
            echo "Adding linux-$version to the $loader bootloader menu"
            if &#91; $loader = "grub" &#93;; then
                    cd /boot/grub
                    echo "Making backup of grub.conf at /boot/grub/grub.conf.backup"
                    cp ./grub.conf ./grub.conf.backup
                    echo "Editting grub.conf to include your newly compiled kernel"
    		echo "" >> ./grub.conf
                    echo "title=Linux-$version" >> ./grub.conf
                    echo "root &#40;hd$grub_drive,$grub_partition&#41;" >> ./grub.conf
                    if &#91; "$mount_point" = "$root_mount_point" &#93;; then
    			echo "kernel /boot/kernel-$version root=/dev/$root_mount_point" >> ./grub.conf
    		else
    			echo "kernel /kernel-$version root=/dev/$root_mount_point" >> ./grub.conf
    		fi
            elif &#91; $loader = "lilo" &#93;; then
                    cd /etc/
                    echo "Making backup of lilo.conf at /etc/lilo.conf.backup"
                    cp ./lilo.conf ./lilo.conf.backup
                    echo "Editting lilo.conf to include your newly compiled kernel"
    		echo "" >> ./lilo.conf
    		if &#91; "$mount_point" = "$root_mount_point" &#93;; then
    	                echo "Image=/boot/kernel-$version" >> lilo.conf
            	else
    			echo "Image=/kernel-$version" >> lilo.conf
    		fi
    	        echo "label=Linux-$version" >> ./lilo.conf
                    echo "read-only" >> ./lilo.conf
                    echo "root=/dev/$root_mount_point" >> ./lilo.conf
            fi
    
            echo "umount /boot"
            umount /boot
    
            echo "DONE!!"
    
            exit 0
    
    fi

  6. #6
    Linux Engineer
    Join Date
    Mar 2005
    Posts
    1,431
    Sorry I haven't replied in a while - been very busy, no time to compile kernel

    I was about to download it yesterday when the link said the file was expired... I'm having a hard time copying the code from the code-field in konqueror, viewing the source of the page includes lots of &quot's and such... Could you please upload it somewhere else?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •