I am working on a script that can be used to compile a standard kernel source file you might download from The Linux Kernel Archives. I am looking for all comments concerning this script.
If you are new to Linux or you have no need to update your kernel then please do not use this file. It is hoped that someone with experience updating their kernel can provide assistance in this script file creation project.
To create the script, copy and paste the following code into a text editor and save it as the file sakc in the folder /home/username/bin:
#!/bin/bash
#: Title : S.A.K.C - SuSE Automated Kernel Compiler
#: Date Created: Fri Sep 3 14:26:16 CDT 2010
#: Last Edit : Sat Sep 4 10:47:00 CDT 2010
#: Author : J. McDaniel
#: Version : 1.00
#: Description : Compile Kernel & add to Grub Menu.lst
#: Options : Name of Source File $1
#
# Written for the openSUSE forums on 9-4-2010
#
echo
echo "S.A.K.C - SuSE Automated Kernel Compiler"
echo
#
# Make sure script was not started as root
#
if "$HOME" == "/root" ] ; then
echo
echo "Do Not Start $0 as a root user!"
echo
read -p "Press <enter> to exit..."
exit 1
fi
#
# Make sure we got kernel source file name as a command line argument
#
if $# -eq 0 ] ; then
echo
echo "Command Syntax is: $0 kernel_source_file_name.tar.bz2"
echo
read -p "Press <enter> to exit..."
exit 2
fi
FILE=$1
#
# Determine if kernel file-name is present
#
if ! -e $FILE ] ; then
echo
echo "The Kernel Source file $1 was not Found!"
echo
read -p "Press <enter> to exit..."
exit 3
fi
# Determine how long the kernel file name is
NUM=${#FILE}
# Set ext1 for the last three Characters of file name for comparison
ext1="${FILE:$(($NUM-3))}"
#
# Convert bz2 file to a tar file
#
if "$ext1" == "bz2" ] ; then
echo
echo "Converting kernel bz2 file to a tar file. Please wait...."
echo
# Convert options are -d=Decompress v=verbose k=keep orginal file f=overwrite existing files
bunzip2 -dvkf $FILE
tar1="${FILE:0:$(($NUM-4))}"
else
tar1="$FILE"
fi
echo
echo "Extracting Kernel Tar Files. Please wait...."
echo
#
# Untar options are -x=extract files v=verbose f=use $tar1 as archive file
#
tar -xvf $tar1 > nul
#
# Determine new Kernel named folder and change to it
#
NUM=${#tar1}
folder="${tar1:0:$(($NUM-4))}"
cd $folder
echo
echo "Creating your kernel Configuration Files. Please wait..."
echo
cp /proc/config.gz .
gunzip config.gz
cp config .config
echo
echo "You may be required to press <enter> more than once to accept a default."
echo "Please look at your computer terminal screen from time to time."
echo
echo "Executing the Make Command. This can take A LONG TIME. Please wait..."
echo
read -p "If you are ready then Press <enter> to continue..."
echo
make
script_exit_value=$?
if "${script_exit_value}" -ne "0" ] ; then
echo
echo "Error Code Reported During Make Process: "$script_exit_value
echo
exit 4
fi
echo
echo "Now Creating and adding in your new kernel file to your Grub menu.lst file."
echo "this requires the root user password. Please enter the password when requested."
echo
sudo make modules_install install
echo
echo "Kernel Creation Process is complete..."
echo
exit 0
# End Of Script
To make the file executable, perform the following terminal command:
chmod +x ~/bin/sakc
To use the script file, go to The Linux Kernel Archives and download the kernel version you wish to use. Let us assume the kernel file is called linux-2.6.35.4.tar.bz2 and we are downloading the kernel source file into the folder /home/username/Downloads.
To use the script file to create a new kernel selection in your menu.lst file, perform the following terminal commands using konsole or other terminal program as a normal user. Do not become root or use this script file as root, it will not work. When the make command is run, it can take a VERY LONG TIME, up to an hour or more to run.
cd ~/Downloads
sakc linux-2.6.35.4.tar.bz2
That is it if all works as planned. You should be able to reboot and find a new kernel selection in your Grub menu.lst file. Your old kernel selection should also still be there. If you are loading the nVidia Proprietary Binary Driver, you are going to need to enter run level three on reboot and reload this driver. Be aware that newer kernels may not work with your video driver and other problems may also exist.
suselizard32 I have installed the latest kernel version 2.6.35.4 on two different computers using this script. I am hoping to hear from anyone that uses this script and as to their success or failure of the kernel installation due to this script file. Of course, this only installs the kernel and it does not guaranty that the kernel will work properly with your computer, but it should do no harm to your system, allowing you to go back to your previous kernel if you wish.
I have mode some additional modifications to my script. The instructions on creating and using this script has not changed from my first post. Here is the new scrip code:
#!/bin/bash
#: Title : S.A.K.C - SuSE Automated Kernel Compiler
#: Date Created: Fri Sep 3 14:26:16 CDT 2010
#: Last Edit : Sun Sep 6 12:17:00 CDT 2010
#: Author : J. McDaniel
#: Version : 1.02
#: Description : Compile Kernel & add to Grub Menu.lst
#: Options : Name of Source File $1
#
# Written for the openSUSE forums on 9-4-2010
#
echo
echo "S.A.K.C - SuSE Automated Kernel Compiler"
echo
#
# Make sure script was not started as root
#
if "$HOME" == "/root" ] ; then
echo
echo "Do Not Start $0 as a root user!"
echo
read -p "Press <enter> to exit..."
exit 1
fi
#
# Make sure we got kernel source file name as a command line argument
#
if $# -eq 0 ] ; then
echo
echo "Command Syntax is: $0 kernel_source_file_name.tar.bz2"
echo
read -p "Press <enter> to exit..."
exit 2
fi
FILE=$1
#
# Determine if kernel file-name is present
#
if ! -e $FILE ] ; then
echo
echo "The Kernel Source file $1 was not Found!"
echo
read -p "Press <enter> to exit..."
exit 3
fi
# Determine how long the kernel file name is
NUM=${#FILE}
# Set ext1 for the last three Characters of .bz2 file name for comparison
ext1="${FILE:$(($NUM-3))}"
#
# Convert bz2 file to a tar file
#
if "$ext1" == "bz2" ] ; then
echo
echo "Converting kernel bz2 file to a tar file. Please wait...."
echo
# Convert options are -d=Decompress v=verbose k=keep orginal file f=overwrite existing files
bunzip2 -dvkf $FILE
tar1="${FILE:0:$(($NUM-4))}"
else
tar1="$FILE"
fi
# Determine how long the kernel file name is without .bz2
NUM=${#tar1}
# Set ext1 for the last three Characters of .tar file name for comparison
ext1="${tar1:$(($NUM-3))}"
if "$ext1" == "tar" ] ; then
echo
echo "Extracting Kernel Tar Files. Please wait...."
echo
#
# Untar options are -x=extract files v=verbose f=use $tar1 as archive file
#
tar -xvf $tar1 >nul
else
echo
echo "The Kernel Source file $tar does not end with .tar ..."
echo
read -p "Press <enter> to exit..."
exit 3
fi
#
# Determine new Kernel named folder and change to it
#
folder="${tar1:0:$(($NUM-4))}"
cd $folder
echo
echo "Kernel Configuration Process ..."
echo
echo "You may be required to press <enter> more than once to accept a new Kernel default."
echo "Any new hardware detection kernel modules added from your existing kernel - "
echo "will ask if they should be included as NEW. Press <enter> for this default."
echo
read -p "If you are ready to begin then Press the <enter> key to continue... (CTRL-C to abort)"
echo
echo "Creating your kernel Configuration Files. Please wait..."
echo
# Copy the file config.gz from the /proc folder to default Kernel Source folder
cp /proc/config.gz .
# UnZip file config.gz to the file config
gunzip config.gz
# Copy config to .config in default Kernel Source folder
cp config .config
# Allow you to Answer Questions on all new Kernel Options, missing from your old kernel/Configuration
make oldconfig
echo
echo "Would you like to modify/view your kernel configuration before it is compiled?"
echo
read -p "Please type a y, then press <enter> were y<enter>=yes and pressing just <enter> means no: " CHOICE
if "$CHOICE" == "y" ] ; then
make menuconfig
fi
echo
echo "Kernel Configurations Files are Completed."
echo
echo "Ready to Execute the Make Command. This can take A VERY LONG TIME...Up to an Hour."
echo
read -p "If you are ready to begin then Press the <enter> key to continue... (CTRL-C to abort)"
echo
make > nul
script_exit_value=$?
if "${script_exit_value}" -ne "0" ] ; then
echo
echo "Error Code Reported During Make Process: "$script_exit_value
echo
exit 4
fi
echo
echo "Now Creating and adding in your new kernel file to your Grub menu.lst file."
echo "this requires the root user password. Please enter the password when requested."
echo
# Create kernel modules & Copy three files into /boot directory & modify Grub menu.lst file as a root user...
sudo make modules_install install
echo
echo "Kernel Creation Process is complete..."
echo
exit 0
# End Of Script
This new script adds more comments and two new commands which are; “make oldconfig” and “make menuconfig”. By using “make oldconfig”, you can answer all questions about new kernel options, before leaving your PC to compile the code, which can take a while. Second, by adding in “make menuconfig”, experienced users who wish to make additional kernel configuration changes, may do so if they want to. If anyone has a problem with these two new commands, please let me know what they are.
I also ran into a problem on one machine when trying to execute the sudo command near the end of the script. The PC would simply not wait for me to enter the root password. I had to change back to the new kernel folder manually and execute the full sudo install command. I would like to know if anyone has run into this odd problem. And as always, let me know if this script worked for you or not. I really want to know.
> #
> # Make sure script was not started as root
> #
> if “$HOME” == “/root” ] ; then
> echo
> echo “Do Not Start $0 as a root user!”
> echo
> read -p “Press <enter> to exit…”
> exit 1
> fi
zcat /proc/config.gz >.config
This works like a champ and I have placed it into my master copy. Thanks you for this suggestion pjessen.
> #
> # Make sure script was not started as root
> #
> if “$HOME” == “/root” ] ; then
> echo
> echo “Do Not Start $0 as a root user!”
> echo
> read -p “Press <enter> to exit…”
> exit 1
> fi
I would test $UID instead.
When running as a standard user “echo $UID” displays 1000. How do I use this in lue of the /root test I have here?
if $UID -eq 0 ] ; then
So, if you are a root user, your $UID = 0. So putting in this code works like a champ pjessen. However, why do you think this is better than the check that I was using? I am asking this question because I do not know the answer, so help me to understand why. And again, thank you so much for your comments.
>
>> if $UID -eq 0 ] ; then
>
> So, if you are a root user, your $UID = 0.
> So putting in this code works like a champ pjessen. However, why do
> you think this is better than the check that I was using? I am asking
> this question because I do not know the answer, so help me to
> understand why. And again, thank you so much for your comments.
Hi jdmcdaniel3
your initial code worked on the assumption that roots home directory
will always be /root - this is not a safe assumption to make. Testing
for uid=0 is guarnateed to work.
That explains it then in very simple terms pjessen. I have made the following code part of my master copy then.
if $UID -eq 0 ] ; then
While I have your attention, do you have any comments concerning the use of “make oldconfig” or “make menuconfig” in this script you would like to add? Any info could be useful.
>
> That explains it then in very simple terms pjessen. I have made the
> following code part of my master copy then.
>
>
> Code:
> --------------------
> if $UID -eq 0 ] ; then
> --------------------
> While I have your attention, do you have any comments concerning the
> use of “make oldconfig” or “make menuconfig” in this script you would
> like to add? Any info could be useful.
There’s not much to say. Doing a make menuconfig seems to be in stark
contrast to using your script for building the kernel - i.e. if one
knows how to configure the kernel, one will probably also know how to
build it.
One improvement for your script - you don’t need to unzip and untar in
two separate steps, tar has methods for both gzip and bzip2 built in.
Once again pjessen I thank you for your comments. I was thinking on the unzip command someone might input a tar file directly and not all would be bz2, but I guess I am not all that sure this would happen as the files from kernel.org are all bz2 types. This is why I made it two steps in the original script. As for using make menuconfig, I was hoping that even people with lots of experience might give in to using a simple script if it would work for them, but not sure about that either.
I think its a nice option for users. Especially with the last kernels issues it could be useful to some. I just compiled a fresh 2.6.35.4-12-desktop kernel using S.A.K.C didn’t make any changes to config.
Is there much advantage to defaulting to no for new configs where m could be used? I’m asking because I dunno. I’d assume a leaner kernel but… portability, new hardware. I spose recompiling to enable new hardware wouldn’t be too big of deal for most folks.
Using n or No can make a leaner and faster kernel, but not putting in something you needed, could be a problem also. You would think New, means it was not used before, but perhaps it is replacing something. My thoughts are go with No if you want to try it and reinstall kernel if it does not work. However, when installing the same kernel again, there has to be something else (a different kernel version still loaded) there to fall back on should you create a problem.
Yeah thats a nice touch. Nothing worse then spending 2 hours compiling a kernel and getting: Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
That was the result of my first/last experience using kernel check on another system a while back. It did have a very pretty GUI though
There is something to be said for K.I.S.S. methods.
sixonetonoffun thanks for your comments. I think that the sakc script file is fairly simple while providing enough value to inspire someone to use and recommend it to another openSUSE user. I don’t know about you, but I really have trouble remembering all of the commands one could need to compile the kernel, unless you do it a lot, so the script keeps it right and doing the very same thing every time.
Any other comments or suggestions about sakc are willingly accepted here.
OK, just to incorporate the latest two changes into the S.A.K.C. script code:
#!/bin/bash
#: Title : S.A.K.C - SuSE Automated Kernel Compiler
#: Date Created: Fri Sep 03 14:26:16 CDT 2010
#: Last Edit : Sun Sep 10 10:31:00 CDT 2010
#: Author : J. McDaniel
#: Version : 1.03
#: Description : Compile Kernel & add to Grub Menu.lst
#: Options : Name of Source File $1
#
# Written for the openSUSE forums on 9-4-2010
#
echo
echo "S.A.K.C - SuSE Automated Kernel Compiler"
echo
#
# Make sure script was not started as root looking now at the user $UID
#
if $UID -eq 0 ] ; then
echo
echo "Do Not Start $0 as a root user!"
echo
read -p "Press <enter> to exit..."
exit 1
fi
#
# Make sure we got kernel source file name as a command line argument
#
if $# -eq 0 ] ; then
echo
echo "Command Syntax is: $0 kernel_source_file_name.tar.bz2"
echo
read -p "Press <enter> to exit..."
exit 2
fi
FILE=$1
#
# Determine if kernel file-name is present
#
if ! -e $FILE ] ; then
echo
echo "The Kernel Source file $1 was not Found!"
echo
read -p "Press <enter> to exit..."
exit 3
fi
# Determine how long the kernel file name is
NUM=${#FILE}
# Set ext1 for the last three Characters of .bz2 file name for comparison
ext1="${FILE:$(($NUM-3))}"
#
# Convert bz2 file to a tar file
#
if "$ext1" == "bz2" ] ; then
echo
echo "Converting kernel bz2 file to a tar file. Please wait...."
echo
# Convert options are -d=Decompress v=verbose k=keep orginal file f=overwrite existing files
bunzip2 -dvkf $FILE
tar1="${FILE:0:$(($NUM-4))}"
else
tar1="$FILE"
fi
# Determine how long the kernel file name is without .bz2
NUM=${#tar1}
# Set ext1 for the last three Characters of .tar file name for comparison
ext1="${tar1:$(($NUM-3))}"
if "$ext1" == "tar" ] ; then
echo
echo "Extracting Kernel Tar Files. Please wait...."
echo
#
# Untar options are -x=extract files v=verbose f=use $tar1 as archive file
#
tar -xvf $tar1 >nul
else
echo
echo "The Kernel Source file $tar does not end with .tar ..."
echo
read -p "Press <enter> to exit..."
exit 3
fi
#
# Determine new Kernel named folder and change to it
#
folder="${tar1:0:$(($NUM-4))}"
cd $folder
echo
echo "Kernel Configuration Process ..."
echo
echo "You may be required to press <enter> more than once to accept a new Kernel default."
echo "Any new hardware detection kernel modules added from your existing kernel - "
echo "will ask if they should be included as NEW. Press <enter> for this default."
echo
read -p "If you are ready to begin then Press the <enter> key to continue... (CTRL-C to abort)"
echo
echo "Creating your kernel Configuration Files. Please wait..."
echo
# UnZip the file config.gz from the /proc folder to the default kernel Source folder as the file .config
zcat /proc/config.gz >.config
# Allow you to Answer Questions on all new Kernel Options, missing from your old kernel/Configuration
make oldconfig
echo
echo "Would you like to modify/view your kernel configuration before it is compiled?"
echo
read -p "Please type a y, then press <enter> were y<enter>=yes and pressing just <enter> means no: " CHOICE
if "$CHOICE" == "y" ] ; then
make menuconfig
fi
echo
echo "Kernel Configurations Files are Completed."
echo
echo "Ready to Execute the Make Command. This can take A VERY LONG TIME...Up to an Hour."
echo
read -p "If you are ready to begin then Press the <enter> key to continue... (CTRL-C to abort)"
echo
make > nul
script_exit_value=$?
if "${script_exit_value}" -ne "0" ] ; then
echo
echo "Error Code Reported During Make Process: "$script_exit_value
echo
exit 4
fi
echo
echo "Now Creating and adding in your new kernel file to your Grub menu.lst file."
echo "this requires the root user password. Please enter the password when requested."
echo
# Create kernel modules & Copy three files into /boot directory & modify Grub menu.lst file as a root user...
sudo make modules_install install
echo
echo "Kernel Creation Process is complete..."
echo
exit 0
# End Of Script
Just save the file as before and don’t forget to make it executable if you started with this version first, as I talk about in my first message.
I already compiled the kernel, worked smooth I just would feel easier if I still wouldn’t know about all this warnings
I assume, I have to compile the NVIDIA 260 beta driver. What are the kernel sources I have to pass? The linux-2.6.35.7 directory
under my download directory?
So road-movie I also have kernel 2.6.35.7 installed and I am using the standard released 256.53 nVidia driver, loaded the hard way. It works just fine. If you were to go for the 2.6.36 kernel, you would have to load the beta nVidia driver, but not for what we are using.
As for the large display of information from the kernel install, it just seems normal and nothing to worry about. Fatal compile errors will lead to nothing being placed into your menu.lst file and when it does compile, all other menu.lst entrees remain unmodified. It does place itself first in the list and it is obvious compiling and running a new kernel in this way is not for total newbies. Still, the intent of the script is to do no hard, allowing you to still have all of the functionality you had before you ran sakc. If you are smart enough to install the nVidia driver the hard way, you understand that each new kernel must have the nVidia module installed anew.
Happy to hear the script file worked well for you. Don’t forget to tell your fellow openSUSE users as well.