Chinaunix首页 | 论坛 | 博客
  • 博客访问: 246914
  • 博文数量: 33
  • 博客积分: 3030
  • 博客等级: 中校
  • 技术积分: 500
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-09 17:49
文章分类

全部博文(33)

文章存档

2011年(1)

2010年(1)

2009年(10)

2008年(21)

我的朋友

分类: LINUX

2009-04-16 12:25:06

Sysresccd-manual-en Build a SystemRescueCd with your own kernel

From SystemRescueCd

Jump to: navigation, search

Contents

[]

[edit] Overview

SystemRescueCd comes with . You may want to compile your own linux kernel because you need another driver, or you want more recent sources, or just different compilation options.

This tutorial explains how you can compile your own kernel from SystemRescueCd itself, you don't need to have another linux system installed on your hard disk. You can do all the compilation stuff from any other linux system installed on the hard disk, as long as you know what you are doing. This tutorial is based on SystemRecueCd-1.1.0 because this is the first version which comes with the development tools (gcc, make, ...) which are required to compile the kernel. So you should not attempt to follow these instructions with an older version.

After the new kernel sources are compiled, it will be necessary to make a customized SystemRescueCd using the compiled kernel image and modules.

[edit] Prepare your system

This tutorial explains how to compile the kernel from SystemRescueCd.

First boot SystemRescueCd-1.1.0 or a more recent version.

[edit] Check the requirements

Verify the version of SystemRescueCd and that the gcc compiler is installed:

root@sysresccd /root % cat /root/version
1.1.0

root@sysresccd /root % gcc --version
gcc (GCC) 4.2.4 (Gentoo 4.2.4 p1.0)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[edit] Prepare a partition with some free space

You need at least 2GB of free space on your hard disk to compile the sources and to make a customized sysresccd. You can use any partition formatted with a linux filesystem (ext3, reiserfs, reiser4, jfs, xfs, ...). It does not need to be empty.

This example uses partition /dev/sda6, mount it on /mnt/custom:

mount /dev/sda6 /mnt/custom

We will work in /usr/src. Make a directory in that partition, and mount it on /usr/src:

mkdir /mnt/custom/sources
mount -o bind /mnt/custom/sources /usr/src

This gives us two directories at the root of the partition will be created by SystemRecueCd:

  • /mnt/custom/sources: work area to compile the kernel
  • /mnt/custom/customcd: for the customized sysresccd

[edit] Download and prepare the sources and patches

First you must download the vanilla sources of the kernel (linux-w.x.y.z.tar.bz2 where z=0)

cd /usr/src
wget

Now you need the sysresccd patches. There are two sets of patches:

  • std-sources are the patches used to compile the standard kernels (rescuecd and rescue64)
  • alt-sources are the patches used to compile the alternative kernels (altker32 and altker64)

You have to decide which kind of kernel sources you want to use: either the standard ones or the alternative ones.

Here is how to download the patches. Don't forget to replace the version number in the URL with the latest one:

cd /usr/src
wget -r -l1 -A bz2 --no-directories

Then, you must extract the main sources:

tar xfjp linux-2.6.25.tar.bz2

And you apply the SystemRescueCd patches in the order:

cd /usr/src/linux-2.6.25
bzcat ../std-sources-2.6.25.16_01-r16.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_02-nosquashfs.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_03-sqlzma-3.3.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_04-reiser4.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_05-aufs.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_06-loopaes.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_07-speakup.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_08-rtl8168.patch.bz2 | patch -p1
bzcat ../std-sources-2.6.25.xx_09-netdev-atl2.patch.bz2 | patch -p1

The sysresccd kernel sources are made of several patches. Some patches are necessary for the system to work, other patches are not important. Here are the patches that you must keep if you want the system to work:

  • sqlzma: support for the squashfs filesystem with the lzma compression
  • aufs: support for the aufs filesystem (another unionfs)

You are free to apply other patches as long as they don't conflict with other ones or break the sources.

[edit] Configure your kernel

[edit] Customize the EXTRAVERSION

When you type uname -r, the extra version informations are displayed:

root@sysresccd /root % uname -r
2.6.25.16-std110

You may want to change the default EXTRAVERSION value, you can do that by editing the main Makefile:

root@sysresccd /root % cd /usr/src/linux-2.6.25
root@sysresccd /usr/src/linux-2.6.25 % vi Makefile

Here is an example of /usr/src/linux-2.6.25/Makefile

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 25
EXTRAVERSION = .16-custom

[edit] Use the right architecture

You may want to compile a 32bit kernel if you are running a 64bit one, or you may want to compile a 64bit kernel even if you are running a 32bit kernel. In that case, it's important that you specify the right value for ARCH before you run any make command related to the kernel. For instance, here is what you must do if you are running a 64bit kernel (uname -m returns x86_64) and you want to compile a 32bit kernel:

cd /usr/src/linux-2.6.25
export ARCH=i386
sed -i -e '1i\ARCH=i386' Makefile

To compile a 64bit kernel from SystemRescueCd or from any other 32bit linux it's a bit difficult. You have to install crossdev first (run emerge crossdev on SystemRescueCd with portage ready), and then compile that way:

CROSS_COMPILE=x86_64-pc-linux-gnu- ARCH=x86_64 make

After than, the right architecture will be used when you select the options and when you compile the kernel.

[edit] Choose the kernel compilation options

If you don't want to check all the kernel configuration options, you can use the official sysresccd options as a starting point. The options of the running kernel are available in /proc/config.gz, so you can just get the configuration file that way:

cd /usr/src/linux-2.6.25
cat /proc/config.gz | gzip -d > myconfig

If you are working in graphical mode, you can select the options using the graphical program based on GTK. The make xconfig command cannot be used since the system does not have the Qt libraries. So just type this:

cd /usr/src/linux-2.6.25
make gconfig

If you are working in console mode, you can use make menuconfig instead:

cd /usr/src/linux-2.6.25
make menuconfig

When you selection the kernel options, it's very important that you enable the following modules, they must be built-in the kernel image not as a module:

CONFIG_AUFS=y
CONFIG_AUFS_FAKE_DM=y
CONFIG_AUFS_BRANCH_MAX_127=y
CONFIG_AUFS_RR_SQUASHFS=y
CONFIG_AUFS_BR_XFS=y
CONFIG_AUFS_WORKAROUND_FUSE=y
CONFIG_AUFS_DEBUG=y
CONFIG_AUFS_COMPAT=y
CONFIG_SQUASHFS=y

If you want to compile a 64bits kernel (ARCH=x86_64), don't forget to enable the IA32 support (CONFIG_IA32_EMULATION=y), else your kernel won't execute the 32bit binaries. And the sysresccd system is made of 32bit binaries.

[edit] Compile and install the kernel

After the options have been selected and saved in /usr/src/linux-2.6.25/.config, you can compile the sources:

make && make modules && make modules_install

If the kernel compile without error, a compressed kernel image should be available:

root@sysresccd /root % find /usr/src -type f -name bzImage
/usr/src/linux-2.6.25/arch/x86/boot/bzImage

You should also find new modules in either /lib/modules or /lib64/modules/.

Just make a backup of these two things (bzImage file, and the new modules) that you will need in the next stages.

[edit] Recreate the initramfs

[edit] What is an initramfs

An initramfs (also known as init-ramdisk) is a compressed cpio archive which contains files used to initialize the system at boot time. The files are used by the kernel to initialize the system. Basically it does things such as mounting the main root filesystem. It's not required for all the linux systems, but it's necessary for complex ones, for instance when the root filesystem is on an LVM logical volume. In previous kernel versions, the ramdisks were compressed loopback filesystems.

SystemRescueCd needs an initramfs to boot, it's located in isolinux on the cdrom. All the kernels use the same initramfs to save space. This file contains the modules of the kernel you boot, so it's necessary to copy the new modules in this initramfs.

[edit] Extracting the current initramfs

Here is how we extract the contents of the old initramfs using cpio. If you are booting from the network, you may need to download initram.igz by hand.

mkdir /usr/src/initramfs
cd /usr/src/initramfs
zcat /mnt/cdrom/isolinux/initram.igz | cpio -id

[edit] Copy the new modules in the initramfs

Now, you have to copy the directory where your new modules are stored to the initramfs contents. The location of the modules can be either /lib/modules or /lib64/modules:

cp -a /lib/modules/your-kernel-modules /usr/src/initramfs/lib/modules/

[edit] Recreating the initramfs

Here is how we can recreate the new initramfs:

rm -f /usr/src/initram.igz
cd /usr/src/initramfs
find . | cpio -H newc -o | gzip -9 > /usr/src/initram.igz

[edit] Create a customized disc with the new kernel

Now what you have to do is to make a customized SystemRescueCd in which you will copy the new initram.igz and the new kernel modules. You have to follow the detailed instructions about customizing SystemRescueCd without forgetting to copy the new files. Here is a summarized procedure (you have to update the files path and names so that they match your configuration):

  • You don't have to mount a partition again on /mnt/custom since it's already done
  • Extract the file from the squashfs filesystem:
/usr/sbin/sysresccd-custom extract
  • Copy the new kernel modules in /mnt/custom/customcd/files/lib/modules or /mnt/custom/customcd/files/lib64/modules:
cp -a /lib/modules/your-kernel-modules /mnt/custom/customcd/files/lib/modules

or

cp -a /lib64/modules/your-kernel-modules /mnt/custom/customcd/files/lib64/modules
  • Create the new compressed squashfs filesystem:
/usr/sbin/sysresccd-custom squashfs
  • Copy the new initram.igz:
cp /usr/src/initram.igz /mnt/custom/customcd/isoroot/isolinux/initram.igz
  • Copy the new kernel in /mnt/custom/customcd/isoroot/isolinux/. You have to choose a name for your kernel image. For instance it may be vmlinuz which is a common name for kernel images, or you can replace the official kernel and give it the same name: rescuecd.
cp /usr/src/linux-2.6.25/arch/x86/boot/bzImage /mnt/custom/customcd/isoroot/isolinux/vmlinuz

or

cp /usr/src/linux-2.6.25/arch/x86/boot/bzImage /mnt/custom/customcd/isoroot/isolinux/rescuecd

If you decided to give the kernel image another name, you will have to update isolinux.cfg and syslinux.cfg so that it has boot entries which use the new kernel. Here is how to edit it:

vim /mnt/custom/customcd/isoroot/isolinux/isolinux.cfg

Here is an example of two new entries that you can add to isolinux.cfg. The first one has no boot option, and the second one has an option to set the keyboard mapping:

label mykernel
kernel vmlinuz
append initrd=initram.igz
label mykernelfr
kernel vmlinuz
append initrd=initram.igz setkmap=fr

In other words, you will have to type either mykernel or mykernelfr at the very first boot prompt in order to boot the new customized SystemRescueCd.

  • Now you have to build the ISO filesystem:
/usr/sbin/sysresccd-custom isogen my_srcd
  • The final ISO image must have been written in /mnt/custom/customcd/isofile/sysresccd-new.iso. Copy this file wherever you want, or burn it directly from SystemRescueCd if your driver is not busy.
  • And then, unmount the partition cleanly:
cd / ; umount /mnt/custom ; sync
阅读(1416) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~