Ok, I'm back after a busy while, and this time I'm going to describe a few things I managed to do while tailoring knoppix to my preferences.
I see there are people asking around about ways to compile / upgrade the kernel, so I'm going to write here everything I've done while adding new kernels to knoppix 5.3.1.
First, I will describe in simple steps how can you compile a (new) kernel in the knoppix environment
Compared to the general way of kernel compilation in Linux, doing this in knoppix is somewhat simplified, in that you don't have to do "make bzImage" and "make modules" anymore.
Suppose we want to add kernel 2.6.12 to the existing 2.6.24.4 in Knoppix 5.3.1.
Well, to do that, I used this particular script, ran under the original Knoppix 5.3.1 environment, in a chroot under a directory where I put the entire knoppix filesystem, uncompressed.
All my remastering takes place under the original Knoppix 5.3.1 environment, that is under X.
So, to be more clear: under the original Knoppix 5.3.1 environment, I mount the original knoppix ISO stored somewhere on my harddrive, I then mount those two big files KNOPPIX and KNOPPIX2 as cloop devices, and I copy their contents to a directory on a partition of my harddrive (let's say /mnt/hda2/KNOPPIX), then I open another konsole window where I chroot to the freshly copied filesystem (chroot /mnt/hda2/KNOPPIX), from there I mount the partition containing my remastering kit (remastering scripts + additional data files used, let's say /dev/hda4), I then change dir to the remastering kit and then I run this script:
Now I will explain every line of this script:Code:#!/bin/sh odir=`pwd` cd /usr/bin rm -f gcc rm -f g++ ln -s gcc-3.3 gcc ln -s g++-3.3 g++ [ -d /lib/modules/2.6.12 ] && echo -en "\n\n---------------------------------------------------------------\nremoving /lib/modules/2.6.12 ..." && rm -rf /lib/modules/2.6.12 && echo "done." rm -rfv /boot/*2.6.12 [ -d /usr/src/linux-2.6.12 ] && echo -n "removing /usr/src/linux-2.6.12 ..." && rm -rf /usr/src/linux-2.6.12 && echo "done." [ -d /usr/share/doc/linux-image-2.6.12 ] && echo -n "removing /usr/share/doc/linux-image-2.6.12 ..." && rm -rf /usr/share/doc/linux-image-2.6.12 && echo "done." [ -d /usr/src/modules/atl1-2.6.12 ] && echo -n "removing /usr/src/modules/atl1-2.6.12 ..." && rm -rf /usr/src/modules/atl1-2.6.12 && echo "done." [ -d /usr/src/modules/aufs-2.6.12 ] && echo -n "removing /usr/src/modules/aufs-2.6.12 ..." && rm -rf /usr/src/modules/aufs-2.6.12 && echo "done." [ -d /usr/src/modules/cloop-2.6.12 ] && echo -n "removing /usr/src/modules/cloop-2.6.12 ..." && rm -rf /usr/src/modules/cloop-2.6.12 && echo "done." echo -e "\n\n######################### COMPILING KERNEL 2.6.12 ################################\n\n" cd /usr/src echo "------------------------- extracting kernel ----------------------------" tar -xjf $odir/kernels/kernel.org/linux-2.6.12.tar.bz2 echo "------------------------- changing /usr/src/linux link -----------------" rm -fv linux ln -sv linux-2.6.12 linux cd /usr/src/linux [ -f $odir/kernels/.config-2.6.12 ] || cp -fpv $odir/kernels/.config-k4.0.2 .config [ -f $odir/kernels/.config-2.6.12 ] && cp -fpv $odir/kernels/.config-2.6.12 .config ############################# KERNEL PATCHING ################################# #patch -p1 </usr/src/modules/aufs-2.6.12/patch/deny_write_access.patch ## >= 2.6.17 #sed -i -e "s/CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH \=/CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH = y/" /usr/src/modules/aufs-2.6.12/local.mk #patch -p0 </usr/src/modules/aufs-2.6.12/patch/put_filp.patch ## >= 2.6.19 #sed -i -e "s/CONFIG_AUFS_PUT_FILP_PATCH \=/CONFIG_AUFS_PUT_FILP_PATCH = y/" /usr/src/modules/aufs-2.6.12/local.mk #patch -p1 </usr/src/modules/aufs-2.6.25/patch/sec_perm-2.6.24.patch ## >= 2.6.24 #sed -i -e "s/CONFIG_AUFS_SEC_PERM_PATCH \=/CONFIG_AUFS_SEC_PERM_PATCH = y/" /usr/src/modules/aufs-2.6.25/local.mk #patch -p0 </usr/src/modules/aufs-2.6.25/patch/splice-2.6.23.patch ## >= 2.6.23 #sed -i -e "s/CONFIG_AUFS_SPLICE_PATCH \=/CONFIG_AUFS_SPLICE_PATCH = y/" /usr/src/modules/aufs-2.6.25/local.mk #patch -p0 </usr/src/modules/aufs-2.6.25/patch/sysfs_get_dentry.patch #sed -i -e "s/CONFIG_AUFS_SYSAUFS \= y/CONFIG_AUFS_SYSAUFS =/" /usr/src/modules/aufs-2.6.25/local.mk ## <= 2.6.24 #sed -i -e "s/CONFIG_AUFS_STAT \=/CONFIG_AUFS_STAT = y/" /usr/src/modules/aufs-2.6.25/local.mk ## >= 2.6.25 #patch -p1 <../kernel-patches/knoppix-kernel.patch ### USING sed INSTEAD sed -i -e "s/console_loglevel \= 4/console_loglevel = 1/" init/main.c ############################################################################### echo "------------------------ make menuconfig -------------------------------" [ -f $odir/kernels/.config-2.6.12 ] || make menuconfig cd .. make kernel #dpkg -i linux-image-2.6.12_2.6.12-10.00.Custom_i386.deb dpkg-deb -x linux-image-2.6.12_2.6.12-10.00.Custom_i386.deb / echo "------------------------- make atl1 ------------------------------------" cd modules unzip $odir/hardware/ASUS/net/lan_Linux_V11400.zip mv -fv lan atl1-2.6.12 cd atl1-2.6.12/src sed -i -e "s/^BUILD_KERNEL\=.*$/BUILD_KERNEL=2.6.12/" Makefile make cd ../../.. echo "------------------------- make cloop -----------------------------------" cd modules tar -xzf cloop-2.06.tar.gz mv -f cloop-2.06 cloop-2.6.12 cd cloop-2.6.12 make KERNEL_DIR=/usr/src/linux cd ../.. echo "------------------------- extracting aufs ----------------------------" cd modules tar -xjf $odir/aufs-cvs_2007-02-10.tar.bz2 mv aufs-2007-02-10 aufs-2.6.12 cd aufs-2.6.12 cp $odir/aufs-patch-2.6.11.patch . patch -p1 <aufs-patch-2.6.11.patch echo "------------------------- make aufs ------------------------------------" #make KDIR=/lib/modules/2.6.12/build -f local.mk kconfig make KDIR=/usr/src/linux -f local.mk mkdir /lib/modules/2.6.12/kernel/drivers/net/atl1 cp -fpv /usr/src/modules/atl1-2.6.12/src/atl1.ko /lib/modules/2.6.12/kernel/drivers/net/atl1/ cp -fpv /usr/src/modules/atl1-2.6.12/src/atl1.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cp -fpv /usr/src/modules/cloop-2.6.12/cloop.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cp -fpv /usr/src/modules/aufs-2.6.12/fs/aufs/aufs.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cd .. depmod -a 2.6.12
This creates a variable named "odir" containing the current directory at the beginning. This directory contains (along with this script) others subdirectories where I keep files used by this script. The directories used in this particular script are:Code:odir=`pwd`
kernels/ ___________this contains the kernels configurations for all new kernels, which configurations I created manually for each kernel.
kernels/kernel.org/ ___this contains the kernels downloaded from kernel.org, as tar.bz2 archives
hardware/ _________this contains drivers for various hardware I have, including ALSA drivers archives downloaded from the ALSA site
dvd/ ______________this contains the exact file structure of the original Knoppix 5.3.1 DVD, EXCEPT FOR the compressed filesystem (that is files KNOPPIX/KNOPPIX and KNOPPIX/KNOPPIX2)
Next:
What this does is it changes the symbolic link "gcc" in /usr/bin to point to the gcc version 3.3.Code:cd /usr/bin rm -f gcc rm -f g++ ln -s gcc-3.3 gcc ln -s g++-3.3 g++
Why? Because the kernel evolved in time, and so did the C compiler. Older kernels are supposed to be compiled with some C compiler of the same age, that is older compilers, or at least that's my approach. For my remaster I used gcc 3.3 to compile kernels 2.6.12 to 2.6.19, and gcc 4.0 to compile kernels 2.6.20 to 2.6.28. Don't ask how I came to this conclusion, I just felt like I needed to do it this way. That does not mean you are not free to use whatever compiler you wish. Only one thing I want to make clear here: When you compile a kernel, you have to use the same compiler to compile extra modules for it. For instance, if you compile kernel 2.6.12 with gcc-3.3, and you also want to compile (some newer) ALSA drivers for this kernel, you have to use the same gcc-3.3 for ALSA
Next:
What this does is, in case I run this script twice or more times, it deletes 2.6.12 kernel files left from previous compilation attempts. This is not really necessary when I have everything working OK, after the script is thoroughly tested and proved to do exactly what it supposed to. But since I used this code in the beginning, I just left it here uncommented.Code:[ -d /lib/modules/2.6.12 ] && echo -en "\n\n---------------------------------------------------------------\nremoving /lib/modules/2.6.12 ..." && rm -rf /lib/modules/2.6.12 && echo "done." rm -rfv /boot/*2.6.12 [ -d /usr/src/linux-2.6.12 ] && echo -n "removing /usr/src/linux-2.6.12 ..." && rm -rf /usr/src/linux-2.6.12 && echo "done." [ -d /usr/share/doc/linux-image-2.6.12 ] && echo -n "removing /usr/share/doc/linux-image-2.6.12 ..." && rm -rf /usr/share/doc/linux-image-2.6.12 && echo "done." [ -d /usr/src/modules/atl1-2.6.12 ] && echo -n "removing /usr/src/modules/atl1-2.6.12 ..." && rm -rf /usr/src/modules/atl1-2.6.12 && echo "done." [ -d /usr/src/modules/aufs-2.6.12 ] && echo -n "removing /usr/src/modules/aufs-2.6.12 ..." && rm -rf /usr/src/modules/aufs-2.6.12 && echo "done." [ -d /usr/src/modules/cloop-2.6.12 ] && echo -n "removing /usr/src/modules/cloop-2.6.12 ..." && rm -rf /usr/src/modules/cloop-2.6.12 && echo "done."
So, the files that have to be deleted are: the directory /lib/modules/2.6.12 containing kernel modules, the directory /usr/src/linux-2.6.12 containing the kernel sources (unpacked from the tar.bz2 downloaded from kernel.org), the directory /usr/share/doc/linux-image-2.6.12 (part of the installed kernel 2.6.12), the directory /usr/src/modules/atl1-2.6.12 (this is where I unpack the driver source for my particular network interface, which is not contained in the kernel since the kernel is much older than the hardware), the directory /usr/src/modules/aufs-2.6.12 which contains the sources for the aufs module used with this particular kernel, and the directory /usr/src/modules/cloop-2.6.12 which contains the sources for the cloop module used with this particular kernel.
Next:
Here, I change dir to /usr/src, I extract the kernel sources for 2.6.12 from $odir/kernels/kernel.org/linux-2.6.12.tar.bz2, thus creating a new subdirectory named "2.6.12" under "/usr/src" and then I change the symbolic link "linux" found in "/usr/src", so that it points to "2.6.12".Code:echo -e "\n\n######################### COMPILING KERNEL 2.6.12 ################################\n\n" cd /usr/src echo "------------------------- extracting kernel ----------------------------" tar -xjf $odir/kernels/kernel.org/linux-2.6.12.tar.bz2 echo "------------------------- changing /usr/src/linux link -----------------" rm -fv linux ln -sv linux-2.6.12 linux cd /usr/src/linux [ -f $odir/kernels/.config-2.6.12 ] || cp -fpv $odir/kernels/.config-k4.0.2 .config [ -f $odir/kernels/.config-2.6.12 ] && cp -fpv $odir/kernels/.config-2.6.12 .config
#----------------------------------------------------------------#
For those who don't know yet, /usr/src/linux is always a link pointing to the current kernel sources, in this case 2.6.12.
Why?, because it's a general rule expected to be true by many other programs, so I keep it true.
Another thing is, you probably notice that instead of simply commenting my actions in the script, I actually print them on the console with "echo". That shoots two birds with one bullet: I see the comment when I read and check my script, and I also see the comment in the compilation log left in the konsole window.
#-----------------------------------------------------------------#
Then I cd into the freshly unpacked kernel sources. Here, I copy the kernel configuration file. If I do not already have a custom configuration file that suits my preferences, I start from the kernel configuration copied from Knoppix 4.0.2, which happens to use the same kernel, 2.6.12. It's a starting point anyway better than kernel 2.6.24.4 which comes with knoppix 5.3.1.
#-----------------------------------------------------------------#
As a comment, I will say here that when you unpack a kernel and start configuring it (with "make menuconfig" for instance) the configuration script will try and find a default kernel configuration file in the system. If it doesn't find a file named ".config" in the root of the kernel source being compiled, it will look for one in the directory "/boot". This directory contains the configuration file for the kernel currently running, which in our case is 2.6.24.4.
Now this kernel being much newer than 2.6.12, when the configuration script (for 2.6.12) tries to import the configuration (for 2.6.24.4) it will complain about attempts to import unknown variables, which is normal, since newer kernels have more and newer config variables (newer drivers, newer features etc.). Also it is possible that some of the config variables for 2.6.12 do not exist anymore in 2.6.24.4, so they will not be imported in 2.6.12, which means more manual work to do for 2.6.12 at configuration time.
Anyway, the idea is I'm using the config from knoppix 4.0.2 as a starting point for my 2.6.12 kernel.
I do "make menuconfig", I go through all menus checking what I want in my 2.6.12 kernel and what not, then I save this configuration, then I start compiling the kernel. I watch the whole process and check for error messages for different drivers/features. If I see some error while compiling a particular driver in the kernel, I start configuring 2.6.12 again, making sure I disable that pesky driver. And so on, until I get a compilation log as clean as possible. When I'm satisfied with my compilation log, I save that kernel configuration as ".config-2.6.12" in the $odir/kernels/ directory I previously mentioned
#-----------------------------------------------------------------#
So, if I already have the final config file for my 2.6.12 kernel (in other words, the file $odir/kernels/.config-2.6.12 exists), then I copy this file to my 2.6.12 source tree.
If I don't have a final configuration according to my preferences (in other words, the file $odir/kernels/.config-2.6.12 does not exist) then I copy the file $odir/kernels/.config-k4.0.2 to my 2.6.12 source tree. Notice that the file is being copied as ".config" in both cases.
Next:
This section of the script takes care of the required kernel patching in order for the aufs module to actually get compiled and work with kernel 2.6.12.Code:############################# KERNEL PATCHING ################################# #patch -p1 </usr/src/modules/aufs-2.6.12/patch/deny_write_access.patch ## >= 2.6.17 #sed -i -e "s/CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH \=/CONFIG_AUFS_DENY_WRITE_ACCESS_PATCH = y/" /usr/src/modules/aufs-2.6.12/local.mk #patch -p0 </usr/src/modules/aufs-2.6.12/patch/put_filp.patch ## >= 2.6.19 #sed -i -e "s/CONFIG_AUFS_PUT_FILP_PATCH \=/CONFIG_AUFS_PUT_FILP_PATCH = y/" /usr/src/modules/aufs-2.6.12/local.mk #patch -p1 </usr/src/modules/aufs-2.6.25/patch/sec_perm-2.6.24.patch ## >= 2.6.24 #sed -i -e "s/CONFIG_AUFS_SEC_PERM_PATCH \=/CONFIG_AUFS_SEC_PERM_PATCH = y/" /usr/src/modules/aufs-2.6.25/local.mk #patch -p0 </usr/src/modules/aufs-2.6.25/patch/splice-2.6.23.patch ## >= 2.6.23 #sed -i -e "s/CONFIG_AUFS_SPLICE_PATCH \=/CONFIG_AUFS_SPLICE_PATCH = y/" /usr/src/modules/aufs-2.6.25/local.mk #patch -p0 </usr/src/modules/aufs-2.6.25/patch/sysfs_get_dentry.patch #sed -i -e "s/CONFIG_AUFS_SYSAUFS \= y/CONFIG_AUFS_SYSAUFS =/" /usr/src/modules/aufs-2.6.25/local.mk ## <= 2.6.24 #sed -i -e "s/CONFIG_AUFS_STAT \=/CONFIG_AUFS_STAT = y/" /usr/src/modules/aufs-2.6.25/local.mk ## >= 2.6.25 #patch -p1 <../kernel-patches/knoppix-kernel.patch ### USING sed INSTEAD sed -i -e "s/console_loglevel \= 4/console_loglevel = 1/" init/main.c ###############################################################################
After each patch I put in a comment the kernel versions that require that patch. For instance the "deny_write_access.patch" is only required for kernels starting with 2.6.17
So since for this particular kernel (2.6.12) no patch is required, I just commented out all patches. The only patch I use is the kernel log level patch aka the knoppix kernel patch, which changes the kernel log level from 4 to 1, and I actually do this patch using the "sed" command instead of patching with a "patch" command.
#-----------------------------------------------------------------#
NOTE: you probably noticed that this section is in the wrong place. It should be AFTER the aufs source code is unpacked. What happened is that I moved the code that unpacks the aufs source towards the end of the script, because no patch is actually required anyway and I wanted to have all the code pertaining to aufs in one single place.
Historically speaking, I started experimenting with kernels from 2.6.20 downwards until I got to 2.6.12.
#-----------------------------------------------------------------#
Next:
OK, so what happens here is that IF I already have the final 2.6.12 kernel configuration file ($odir/kernels/.config-2.6.12), I DO NOT RUN "make menuconfig" anymore, because there is no point in doing that. I just proceed with the kernel compilation since I already know the compilation will be successfull and with minimum warnings.Code:echo "------------------------ make menuconfig -------------------------------" [ -f $odir/kernels/.config-2.6.12 ] || make menuconfig cd .. make kernel #dpkg -i linux-image-2.6.12_2.6.12-10.00.Custom_i386.deb dpkg-deb -x linux-image-2.6.12_2.6.12-10.00.Custom_i386.deb /
IF I don't already have the final 2.6.12 configuration, that means I'm using the configuration taken from knoppix 4.0.2, so further adjustments are necessary, so I run "make menuconfig".
Next, I'm exiting the kernel source directory (/usr/src/linux, or /usr/src/linux-2.6.12) and go to the parent dir, that is /usr/src
Now comes the nice part: thanks to Mr. Klaus Knopper's great work, the kernel compilation is being done by one single command, "make kernel", ran from the "/usr/src" directory. That's because there is a "Makefile" file in this directory, that takes care of everything including the creation of a debian package with the custom kernel being compiled. You will have this debian package in "/usr/src" afterwards. All you have to do next is to install it.
And what I actually do is, instead of installing the package (with "dpkg -i") I just unpack it (with "dpkg-deb -x") like any regular archive into the root of the chrooted environment. Why? Because the debian package has some postinstall script that tries to do some things after unpacking the kernel, like trying to mess with the LILO setup, which is useless since this is a live CD/DVD and we don't need any LILO.
All I have to do after simply unpacking the kernel is to run "depmod -a 2.6.12" at the end of remastering, to make sure that all kernel modules for 2.6.12 have the correct dependency.
Next:
Here I compile the network driver for my particular network interface. There's not much to comment here, except that I unpack the driver sources in the "/usr/src/modules" directory, in a separate subdir called "atl1-2.6.12" and before compiling I make a little change in the Makefile. After compiling the driver, I exit back to the "/usr/src" directoryCode:echo "------------------------- make atl1 ------------------------------------" cd modules unzip $odir/hardware/ASUS/net/lan_Linux_V11400.zip mv -fv lan atl1-2.6.12 cd atl1-2.6.12/src sed -i -e "s/^BUILD_KERNEL\=.*$/BUILD_KERNEL=2.6.12/" Makefile make cd ../../..
Next:
Here I cd into "/usr/src/modules", I unpack the cloop module sources, from the file "cloop-2.06.tar.gz" that came with knoppix, into a separate subdirectory called "cloop-2.6.12", within "/usr/src/modules".Code:echo "------------------------- make cloop -----------------------------------" cd modules tar -xzf cloop-2.06.tar.gz mv -f cloop-2.06 cloop-2.6.12 cd cloop-2.6.12 make KERNEL_DIR=/usr/src/linux cd ../..
Then I compile the module according to the instructions, running "make KERNEL_DIR=/usr/src/linux". Once again I say, "/usr/src/linux" is a symbolic link now pointing to "/usr/src/linux-2.6.12"
After all is done, I exit back to "/usr/src"
Next:
What happens here is that I cd into "/usr/src/modules", I unpack the aufs module sources into a separate directory called "aufs-2.6.12" which I then enter, and there I copy a patch for aufs that makes it work with kernel 2.6.12. Then I apply the patch to the aufs sourceCode:echo "------------------------- extracting aufs ----------------------------" cd modules tar -xjf $odir/aufs-cvs_2007-02-10.tar.bz2 mv aufs-2007-02-10 aufs-2.6.12 cd aufs-2.6.12 cp $odir/aufs-patch-2.6.11.patch . patch -p1 <aufs-patch-2.6.11.patch
Next:
Here, I just compile the aufs module, according to the instructions, as an external module, using the command "make KDIR=/usr/src/linux -f local.mk". The command before it that I commented out is used when you wish to have the module embedded into the kernel, which I'm not interested in, so you just ignore that line.Code:echo "------------------------- make aufs ------------------------------------" #make KDIR=/lib/modules/2.6.12/build -f local.mk kconfig make KDIR=/usr/src/linux -f local.mk
Next:
OK, we're finally at the end of the script. What happens here is this: I create a separate directory for my network module (/lib/modules/2.6.12/kernel/drivers/net/atl1) where I copy the module I previously compiled. The module name is atl1.ko. I also copy this module to my remastering package in case I need it later. Then I also copy the aufs and cloop modules to my remastering package. The aufs and cloop modules are used as external modules, they are loaded when knoppix is booted, from the linuxrc script. On the original Knoppix DVD these two modules are placed in the "KNOPPIX/modules" directory. What I did is, I kept the original modules that came with Knoppix and I created separate subdirectories "2.6.12", "2.6.13", "2.6.14", ..... "2.6.28" for my extra kernels, inside this "KNOPPIX/modules" directory on the DVD. In these directories I then copied the cloop and aufs modules I use for my extra kernels.Code:mkdir /lib/modules/2.6.12/kernel/drivers/net/atl1 cp -fpv /usr/src/modules/atl1-2.6.12/src/atl1.ko /lib/modules/2.6.12/kernel/drivers/net/atl1/ cp -fpv /usr/src/modules/atl1-2.6.12/src/atl1.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cp -fpv /usr/src/modules/cloop-2.6.12/cloop.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cp -fpv /usr/src/modules/aufs-2.6.12/fs/aufs/aufs.ko $odir/dvd/KNOPPIX/modules/2.6.12/ cd .. depmod -a 2.6.12
OK folks, there's more to this episode ("The 2.6.12 episode"), but I have to take a break here, it's almost one hour after midnight and I have to kinda go to bed or something. But I'll be back soon with the rest of this episode. Thank God it's been Friday night, otherwise I wouldn't have so much time to write all this