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" ...
- 11-27-2005 #1Linux 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,
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.Code:install-kernel <kernel-version> <grub/lilo> <boot mount point> <root mount point>
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:
...will show you the following information...Code:install-kernel -s (--show)
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")
will show a summary of what i've explained aboveCode:install-kernel -h (--help)
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,
(/usr/sbin/ may be /sbin/ on some distributions)Code:mv /dir/to/file /usr/sbin/
(once again, this may be /sbin/ instead)Code:chmod a=w+r+x /usr/sbin/install-kernel
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
- 11-27-2005 #2Linux 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
- 11-27-2005 #3Linux Enthusiast
- Join Date
- Jun 2005
- Location
- Odessa, FL
- Posts
- 586
ok, thanks
Originally Posted by jaboua 
let me know how it goes when you try it
- 11-30-2005 #4Linux 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
- 12-03-2005 #5Linux 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 [ $# -eq 0 ]; then echo "Error: must have a valid modifier" echo "Usage: install-kernel <kernel-version> <grub/lilo> <boot mount point> <root mount point>" echo "-h or --help for help file" exit 0 fi if [ "$1" = "-h" -o "$1" = "--help" ]; then echo "COMMAND PURPOSE" echo "install-kernel -h (--help) this help file" echo "install-kernel -s (--show) 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: if no bootloader is specified, grub will be chosen automatically" echo "NOTE: the boot mount point must be like in the following example: hda1. In this case, it's the first harddrive (what the 'a' stands for) and first partition (what the '1' means). if no mount point is specified, hda1 will automatically be assigned" echo "NOTE: if no boot mount point is given, than it is assumed to be the root mount point" exit 0 fi if [ "$1" = "-s" -o "$1" = "--show" ]; then echo "Kernel currently in use:" uname -r echo "" echo "Current kernel version symlinked to /usr/src/linux:" ls -l /usr/src/linux echo "" echo "Currently viable kernel sources:" ls /usr/src exit 0 fi version=$1 kernel_number=${version:0:3} loader=$2 mount_point=$3 root_mount_point=$4 loader_mount_point=${loader:0:2} if [ "$loader_mount_point" = "hd" ]; then loader="grub" mount_point="$2" root_mount_point="$3" fi if [ -z "$mount_point" ]; then mount_point="hda1" fi if [ -z "$root_mount_point" ]; then root_mount_point="$mount_point" fi drive=${mount_point:2:1} partition=${mount_point:3:2} if [ "$drive" = "a" ]; then grub_drive="0" elif [ "$drive" = "b" ]; then grub_drive="1" elif [ "$drive" = "c" ]; then grub_drive="2" elif [ "$drive" = "d" ]; then grub_drive="3" elif [ "$drive" = "e" ]; then grub_drive="4" elif [ "$drive" = "f" ]; then grub_drive="5" elif [ "$drive" = "g" ]; then grub_drive="6" elif [ "$drive" = "h" ]; then grub_drive="7" elif [ "$drive" = "i" ]; then grub_drive="8" elif [ "$drive" = "j" ]; then grub_drive="9" elif [ "$drive" = "k" ]; then grub_drive="10" elif [ "$drive" = "l" ]; then grub_drive="11" elif [ "$drive" = "m" ]; then grub_drive="12" elif [ "$drive" = "n" ]; then grub_drive="13" elif [ "$drive" = "o" ]; then grub_drive="14" elif [ "$drive" = "p" ]; then grub_drive="15" elif [ "$drive" = "q" ]; then grub_drive="16" elif [ "$drive" = "r" ]; then grub_drive="17" elif [ "$drive" = "s" ]; then grub_drive="18" elif [ "$drive" = "t" ]; then grub_drive="19" elif [ "$drive" = "u" ]; then grub_drive="20" elif [ "$drive" = "v" ]; then grub_drive="21" elif [ "$drive" = "w" ]; then grub_drive="22" elif [ "$drive" = "x" ]; then grub_drive="23" elif [ "$drive" = "y" ]; then grub_drive="24" elif [ "$drive" = "z" ]; then grub_drive="25" fi if [ "$partition" = "1" ]; then grub_partition="0" elif [ "$partition" = "2" ]; then grub_partition="1" elif [ "$partition" = "3" ]; then grub_partition="2" elif [ "$partition" = "4" ]; then grub_partition="3" elif [ "$partition" = "5" ]; then grub_partition="4" elif [ "$partition" = "6" ]; then grub_partition="5" elif [ "$partition" = "7" ]; then grub_partition="6" elif [ "$partition" = "8" ]; then grub_partition="7" elif [ "$partition" = "9" ]; then grub_partition="8" elif [ "$partition" = "10" ]; then grub_partition="9" elif [ "$partition" = "11" ]; then grub_partition="10" elif [ "$partition" = "12" ]; then grub_partition="11" elif [ "$partition" = "13" ]; then grub_partition="12" elif [ "$partition" = "14" ]; then grub_partition="13" elif [ "$partition" = "15" ]; then grub_partition="14" elif [ "$partition" = "16" ]; then grub_partition="15" elif [ "$partition" = "17" ]; then grub_partition="16" elif [ "$partition" = "18" ]; then grub_partition="17" elif [ "$partition" = "19" ]; then grub_partition="18" elif [ "$partition" = "20" ]; then grub_partition="19" elif [ "$partition" = "21" ]; then grub_partition="20" elif [ "$partition" = "22" ]; then grub_partition="21" elif [ "$partition" = "23" ]; then grub_partition="22" elif [ "$partition" = "24" ]; then grub_partition="23" elif [ "$partition" = "25" ]; then grub_partition="24" elif [ "$partition" = "26" ]; then grub_partition="25" fi if [ -z "$2" ]; then loader="grub" fi echo "Cleaning out /tmp/linux-$version" rm -rf /tmp/linux-$version* if [ "$kernel_number" = "2.4" ]; 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 [ -d $checklin ]; then echo "OK: $checklin exists...using a previous .config file :)" else echo "Warning: $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://www.kernel.org/pub/linux/kernel/v$kernel_number/" cd /tmp/ wget http://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 [ -d $checkdir ]; then echo "OK: $checkdir exists :)" else echo "Error: $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 [ -z /usr/src/linux/arch/i386/boot/bzImage ]; then echo "Error: /usr/src/linux/arch/i386/boot/bzImage does not exist" echo "EXITING" exit 1 fi if [ -z /usr/src/linux/.config ]; then echo "Error: /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 [ "$loader" = "grub" ]; 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 (hd$grub_drive,$grub_partition)" >> ./grub.conf if [ "$mount_point" = "$root_mount_point" ]; 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 [ "$loader" = "lilo" ]; 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 [ "$mount_point" = "$root_mount_point" ]; 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 [ "$kernel_number" = "2.6" ]; 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 [ -d $checklin ]; then echo "OK: $checklin exists...using a previous .config file :)" else echo "Warning: $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://www.kernel.org/pub/linux/kernel/v$kernel_number/" cd /tmp/ wget http://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 [ -d $checkdir ]; then echo "OK: $checkdir exists :)" else echo "Error: $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 [ -z /usr/src/linux/arch/i386/boot/bzImage ]; then echo "Error: /usr/src/linux/arch/i386/boot/bzImage does not exist" echo "EXITING" exit 1 fi if [ -z /usr/src/linux/.config ]; then echo "Error: /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 [ $loader = "grub" ]; 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 (hd$grub_drive,$grub_partition)" >> ./grub.conf if [ "$mount_point" = "$root_mount_point" ]; 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 [ $loader = "lilo" ]; 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 [ "$mount_point" = "$root_mount_point" ]; 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
- 01-22-2006 #6Linux 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 "'s and such... Could you please upload it somewhere else?


Reply With Quote
