Howto recompiling the kernel for SysRescCd

From SystemRescueCd

Jump to: navigation, search

This HowTo was generously written by Thierry Nuttens in March 2006. It's based on Sysresccd-0.2.17, it works only with the 0.2.x SysRescCd versions based on a 2.6 kernel. If you use SysRescCd version 0.2.19, you can skip steps 6.2 and 7.4, since there is no cloop module anymore. This HowTo does not work for SystemRescueCd 0.3.x and 0.4.x.

Contents

1 Introduction

Originally the Distribution is not capable to recognise the Perc 4i/DE install on some hardware. So I had to modify the kernel to include the require driver (CONFIG_MEGARAID_NEWGEN) for this specific RAID controller. I went successful after a few little problems then François ask me to write a procedure which is this document. It has been inspired from the Howto-advanced-customization. This HowTo aims to help you to use your own kernel with SystemRescueCd, in order to add support for a driver, or any other kernel change that you would need. It explains how to rebuild your kernel, and make Sysresccd work with this new kernel.

The distribution SystemRescue CD is a good demonstration of the efficiency's of the boot process of an operating system like Linux. The way this distribution is loaded on your computer is just amazing, "just 4 files are involved".

  • File 1: isolinux.bin which is the bootloader calling the file 2,
  • File 2: vmlinuz1 which is the file name of the kernel, once this file is load, we are already in a linux environment, it is this file we are suppose to recompile
  • File 3: inird1 is the initial Ram disk file which contain the minimum environment for our linux to be setup. The initrd1 file contains an important file call cloop.ko. This driver is going to be part of the job since it has to follow the extraversion of the kernel otherwise it will fail to load.
  • File 4: sysrcd.dat is the compressed file containing the complete Linux structure file. This file will be regenerate as well.

In this document, we will talk about the cloop. The aim of this document is to explain how to create a personnal rescue CD. We are going to explain how we implement an modify kernel, a modify initrd file and a modify sysrcd.dat file. If you do not require a custom kernel, then the customization procedure as described in the System Rescue CDRom Manual will more than likely be adequate for your needs.

2 Setting up the working environment

My computer is running SuSE 10.0 (but any other distribution would make it as long it as an development environment) it has a CD Writer. My harddisk have a free partition of 2 Gigabytes. It will be used for the holding space for the customization process. You could go for a smaller size but they will be a big chance that's you will run out of space. All the prompt command supposed that we are login as root.

3 Quick overview of steps involved

  • Download the Rescue CD iso file to CD Burner machine and burn a copy of the CD.
  • Using the original Bootable rescue CD to generate a snapshot image file.
  • Reboot on SuSE.
  • Add any kernel patches and/or kernel customizations.
  • Recompile the kernel and the modules.
  • Recompile the cloop.ko module for this new kernel.
  • Add kernel modules to snapshot.
  • Remove the old kernel module tree from snapshot.
  • Add new kernel to snapshot.
  • Add modules to initrd (at least cloop.ko)
  • Regenerate a new ISO file. Burn new CD and test.

4 Get the files from SysRescueCD

If you have in your hand the latest version of SysRescCD then you can go directly to Step 5

4.1 Downloaded the latest sysresccd

If you not have the latest version yet, the latest sysresccd can be found at Download. The ISO should be checked against the published md5 checksum. Burn a copy of the new CD - I used cdrecord here.

4.2 Burn the new CD

cdrecord -v dev=x,y,z blank=fast
cdrecord -v dev=x,y,z systemrescuecd-x.y.z.iso

5 Extract the file structure on Harddisk

During this phase, we are going to extract the data from our current bootable rescue CD to our free partition, in my case /dev/sda3. You can have a list of all available partition by typing "cat /proc/partitions".

We booted from Sysresccd, the boot manager should offer a list of options that you can provide to the kernel. I use fb1280, since my resolution is higher anyway. When the CD has booted and you are given a commandline prompt and root shell you can:

# Third disk partition, used to hold our customised image.
mount -t ext3 /dev/sda3 /mnt/custom

Change to your filesystem type in accordance. The script for creating the custom CD /usr/sbin/sysresccd-custom will always refer to /mnt/custom. This is not changeable without editing the script. And since the script is on read-only media, we need to copy this script to a non read-only area like /tmp. Editing the script also turns out to be a necessity as there might comes error resulting of any specific situation which will cause the script to die.

mkdir -vp /mnt/custom/tmp
cp -v /usr/sbin/sysresccd-custom /mnt/custom/tmp/

Once this is done we can extract a copy of our bootdisk to /mnt/custom/customcd/files.

/mnt/custom/tmp/sysresccd-custom extract

From now on we go back to our favorite distribution, so reboot.

6 Compilation

6.1 Build the kernel

As mentionned in the setting up, the distro should have all the necessary tools for compiling. Naturally enough, to recompile the kernel we need a number of things:

  • The kernel source
  • The kernel config file (Unless you want to configure you own kernel)
  • Any kernel patches that we want to install.

The kernel sources from were found at http://www.sysresccd.org/Kernel At the time of writing, the current kernel version is linux-2.6.15.6. Assuming that you have already downloaded the kernel source, and your ExtraVersion is -ab15, the following steps are simply paraphrased and must be modified for your setup:

cd /usr/src/
tar xjf /path/to/downloaded/linux_source/linux-2.6.15.6.tar.bz2
mv linux-2.6.15.6 linux-2.6.15.6-ab15
ln -s /usr/src/linux-2.6.15.6-ab15 /usr/src/linux
cd linux
wget -c ftp://ftp2.sysresccd.org/partimage/sysresccd/kernel/sysresccd-X.Y.Z/config-x.y.z 
cp config-x.y.z .config

Now, you may need to apply several patches. Here is an example:

cd /usr/src/linux
patch -p1 < /path/to/a/patch.diff

It's important to keep in mind you must keep several patches that are applied against the official sysresccd kernel. If you don't patch your kernel with cloop for 2.6.16 or cloop for 2.6.17, it will not work. Of course, you have to answer Yes to the option that enable the cloop. Then, the best thing to do is to keep the patch given on the sysresccd website, and eventually add your own patches.

6.1.1 Modify the .config file

We shall use the .config file downloaded from the official site, and make any change we want to the .config file. If these options weren't added by you, you will be prompted as to whether you want to add them or not:

make oldconfig
make xconfig

6.1.2 Compile the kernel

The build procedure for the kernel is described in the kernel source README file. At this stage you must edit the top level Makefile, and change the parameter EXTRAVERSION on line 4 to read EXTRAVERSION = YourExtraVersion (for example EXTRAVERSION = -ab15)

cd /usr/src/linux
make
make modules_install

Ok now we have already done a big part of the job, the new kernel is compiled and all the related modules as well.

6.2 Build cloop module

This step is not required anymore with SysRescCd version 0.2.19 and newer. You don't need to recompile the cloop module, and change initrd1 anymore. Just skip this step.

Because we have compiled a new kernel we also need to replace the module cloop.ko which is not a part of the kernel distribution. It is stored in initrd1, which is a gzipped loopback ext2 filesystem. The function of this module is to allow us to mount a compressed loopback filesystem (sysrcd.dat). To this effect we need to compile a new version cloop module related to our kernel version. The different versions is available on the WWW are: The Knoppix cloop, the gcloop from the Gentoo project. I used the official source from the knopper website. There is a copy of the sources for cloop_2.04 At the time of writing, this is version 2.04.

At the prompt, type the following command:

make KERNEL_DIR=/path/to/kernel-sources

For example, if your kernel version is 2.6.15.6-ab15, it should be:

make KERNEL_DIR=/usr/src/linux-2.6.15.6-ab15

At this stage the generated module will be named "cloop.ko". It should be found in the current directory.

7 Customization of the filesystem

7.1 Mounting the partition

mount /dev/sda3 /mnt/custom
ln -s /mnt/custom/customcd/files/usr/sbin/create_compressed_fs /usr/sbin

This last command will just allow us to perform the necessary tasks from the current session.

7.2 Replace the modules file

Add the new kernel modules to /mnt/custom/files/lib/modules/2.6.15.4YourExtraVersion

cp -a /lib/modules/2.6.15.4YourExtraVersion /mnt/custom/customcd/files/lib/modules

Remove the old kernel modules.

rm -rf /mnt/custom/customcd/files/lib/modules/old-version-kernel-module

7.3 Replace the Kernel file

install the compiled kernel into isoroot directory

cd /mnt/custom/customcd/isoroot/isolinux
cp /usr/src/linux/arch/i386/boot/bzImage /mnt/custom/customcd/isoroot/isolinux/vmlinuz1

7.4 Update initrd

This step is not required anymore with SysRescCd version 0.2.19 and newer. You don't need to recompile the cloop module, and change initrd1 anymore. Just skip this step.

update initrd to replace the cloop module. The ram disk inititialisation sequence must be updated to accomodate the new module. This is found in the compressed (using gzip) loopback ext2 filesystem initrd1

cd /mnt/custom/customcd/isoroot/isolinux
cp -v initrd1 initrd1.bak
cp -v initrd1 /mnt/custom/tmp/initrd1.gz
cd /mnt/custom/tmp
gunzip initrd1.gz
mkdir -vp /mnt/loop1
mount -t ext2 -o loop /mnt/custom/tmp/initrd1 /mnt/loop1
cp -v /usr/src/linux/cloop-2.02/cloop.ko /mnt/loop1/cloop.ko
cd /mnt/custom/tmp
umount /mnt/loop1
gzip -9 initrd1
cp -v initrd1.gz /mnt/custom/customcd/isoroot/isolinux/initrd1

7.5 Generate the new cloop file – SYSRCD.DAT

From the previous steps we should be able to generate a new LiveCD. This procedure generates the new livecd.cloop file in /mnt/custom/customcd/isoroot/. /mnt/custom/tmp/sysresccd-custom cloop 750 60000

7.6 Generate a new ISO file

/mnt/custom/tmp/sysresccd-custom isogen Volume-Label

The new ISO is saved as /mnt/custom/customcd/isofile/sysresccd-new.iso

7.7 Burning the new CD and test it

From the previous steps we should be able to generate a new LiveCD.

cdrecord -v dev=x,y,z blank=fast
cdrecord -v dev=x,y,z /mnt/custom/customcd/isofile/sysresccd-new.iso

If everything went ok, you should see the new feature implement like new storage driver, network driver or anything else. If it is not what you expect. You can always go back to step 6 and make the necessary changes

8 Conclusion

I have been trying this distribution with a lot of success. Ok they are still some little problems with some tools, but it is still usuable. When I mentioned in the introduction 4 files involved. I want it to bring your attention to the mecanisme of starting up of SystemRescueCD. With this method and a little bit of skill, you could really customised you SytemRescueCD as you like: setting up the network in the boot process, mounting the specific partition, etc...

I have try to be as simple as possible in my explaination, but if you still have problems with the procedure, I will be please to help you: tnu AT else-automation DOT com

Views
Personal tools