21 lab: Configuring a Linux Kernel




Дата канвертавання19.04.2016
Памер43.31 Kb.

HP World/Interex 2002



Linux Kernel Configuration and Patching
Red Hat Linux 7.2


21–1. LAB: Configuring a Linux Kernel


Directions

In this lab, you are going to create a new Linux kernel.





1) Change directory into the Linux kernel source tree (/usr/src/linux 2.4) and edit the Makefile by modifying the EXTRAVERSION variable (replacing the word “custom” with “rev1”) to maintain consistent version control for Linux kernels on your system.
# cd /usr/src/linux-2.4

# vi Makefile

VERSION = 2

PATCHLEVEL = 4

SUBLEVEL = 7

EXTRAVERSION = -10rev1





2) Clean up all of the previous intermediate kernel source build files from a previous compilation. Copy one (consult your instructor) of the kernel configuration file from the kernel source tree (/usr/src/linux 2.4/configs) configs directory to a file named /usr/src/linux 2.4/.config. Examine the contents of the file.
# make mrproper

# uname -a

# cp configs/kernel-2.4.7-i686.config .config

# vi .config (please don’t edit anything!!!)





3) Use the make utility to initialize (use the oldconfig argument) and then modify the .config file (following the direction of your instructor). Add LVM support to the kernel as a static module. Also, add the read-only NTFS (MS Windows) file system driver to the kernel as a dynamic module. The make utility can be used with one of the following arguments. Reexamine the contents of the file.
# make oldconfig

# make config (for a pure text-based tool)

OR

# make menuconfig (for a text-based (n-cursor) menu tool)



OR

# make xconfig (for an X-Window GUI tool)

# vi .config (please don’t edit anything!!!)




4) Compile any kernel hardware dependencies needed for your architecture.
# make dep 2> dep-errors

# cat dep-errors

# make clean




5) Compile the static (core) portion of your kernel. Confirm that the System.map and arch/i386/boot/bzImage files were produced.
# make bzImage 2> bzI-errors

# cat bzI-errors

# ll System.map

# ll arch/i386/boot/bzImage





6) Compile the dynamic (module) portion of your kernel. Confirm that the drivers directory is full of files were produced.
# make modules 2> mod-errors

# cat mod-errors

# ll –R drivers




7) Install the kernel and kernel modules into the correct directories. Create an initial ramdisk image for the new kernel to assist in booting your Linux system. Read the manual page for the lvmcreate_initrd command to learn how to create an initial ramdisk image for a Linux system with an LVM-based root (/) file system.
# ll /lib/modules

# make modules_install

# ll /lib/modules

# ll /boot

# make install

# ll /boot

# mkinitrd –f -v /boot/initrd 2.4.7-10rev1.img 2.4.7-10rev1




8) Edit the LInux LOader (LILO) configuration file (/etc/lilo.conf) to add the new kernel to the boot loader and make it the default kernel.
# vi /etc/lilo.conf

prompt


timeout=50

default=linuxrev1

boot=/dev/hda

map=/boot/map

install=/boot/boot.b

message=/boot/message

linear
image=/boot/vmlinuz-2.4.7-10

label=linux

initrd=/boot/initrd-2.4.7-10.img

read-only

root=/dev/hda1


image=/boot/vmlinuz-2.4.7-10rev1

label=linuxrev1

initrd=/boot/initrd-2.4.7-10rev1.img

read-only

root=/dev/hda1



9) Apply the LInux LOader (LILO) boot loader changes by running the lilo command twice (first to test, then to apply you boot loader configuration).
# lilo –t -v

# lilo -v





10) Reboot your system and select the new kernel from the RedHat Logo LILO boot list screen. Login to the system and test to see if your new kernel works. (Notice the version information in the login prompt on the virtual consoles.)
# reboot
# uname -a

# cat /proc/version





11) Test to see if the new kernel has the NTFS dynamic kernel driver available.
# lsmod

# insmod ntfs

# lsmod

21–2. LAB: Loading and Unloading Dynamic Kernel Modules


Directions

In this lab, you are going to learn how to work with dynamic kernel modules in Linux.





1) List all of the dynamic kernel modules that are currently loaded in kernel memory. Is the vfat or msdos module loaded? (No) Create a 50MB partition on any free disk space and set the type to FAT16 (Hint: Hex Code 6). Reboot your system (if fdisk requires). Using the mkdosfs command to create a DOS file system on this previously created partition.
# lsmod

# fdisk /dev/hd@ (or /dev/sd@)

# mkdosfs /dev/hd@#




2) Create a directory called /mnt/dos and mount the newly-created file system to this directory. Is the vfat or msdos module loaded? (Yes) Were any other related modules loaded in response to accomplishing the mount? (Yes, the fat module was loaded because both vfat and msdos depend on fat.) Confirm what type of file system was mounted to /mnt/dos. Unmount the /mnt/dos file system. Are the related modules still loaded? (Yes)
# mkdir /mnt/dos

# mount -t msdos /dev/hd@# /mnt/dos

OR

# mount -t vfat /dev/hd@# /mnt/dos



# lsmod

# mount -v

# umount /mnt/dos

# lsmod




3) Unload all of the FAT related modules (msdos or vfat and fat) from the kernel using the rmmod command. Manually load the msdos module using the insmod command. Were you successful? (No, errors complain about unresolved symbols meaning dependencies are unresolved.) Manually load the fat module using the insmod command. Were you successful? (Yes) Try manually loading the msdos module again using the insmod command. Were you successful? (Yes) Unload both modules from the kernel.
# rmmod msdos vfat fat

# insmod msdos (fails)

# insmod fat

# insmod msdos (succeeds)

# lsmod

# rmmod msdos fat



# lsmod



4) Examine the modules.dep file in the /lib/modules/ directory and search for the defined dependencies of the msdos module. Also, search for the defined dependencies of the umsdos module. Manually load the umsdos module using the insmod command. Were you successful? (No, errors complain about unresolved symbols meaning dependencies are unresolved.) Manually load the umsdos module using the modprobe command. Were you successful? (Yes, the modprobe command resolves dependencies by loading the appropriate modules listed in the /lib/modules//modules.dep file.) List all of the dynamic kernel modules that are currently loaded in kernel memory and notice how the lsmod command displays dependency information in the far right column. Unload all three modules from the kernel.
# vi /lib/modules//modules.dep

/lib/modules//kernel/fs/msdos/msdos.o: \

/lib/modules//kernel/fs/fat/fat.o

. . . . . . .

/lib/modules//kernel/fs/msdos/umsdos.o: \

/lib/modules//kernel/fs/fat/fat.o \

/lib/modules//kernel/fs/msdos/msdos.o

# insmod umsdos (fails)

# modprobe msdos (succeeds)

# lsmod


Module Size Used by

umsdos 26112 0 (unused)

msdos 5360 0 [umsdos]

fat 32384 0 [umsdos msdos]

# rmmod umsdos msdos fat

22–1. LAB: Patching a Linux Kernel


Directions

In this lab, you are going to learn how to apply patch to the Linux kernel source tree.


DISCLAIMER: The sole purpose of this lab is to give you a feel for how to apply a patch (diff) file bundle to a Linux kernel source tree. You will not rebuild a kernel using the patch files due to the time constraints of the course. It is also important to note that RedHat will usually bundle patches into a (precompiled or source) kernel RPM package so that the patches can be installed as an entire kernel tree bundle using the rpm software installation command. Of course, you would then need to build a kernel from the new (patched) kernel source tree provided to realize the patched kernel. We will now apply a patch bundle (downloaded from http://www.kernel.org) to a different kernel source tree (a pure (not distribution-specific) Linux kernel source tree downloaded from http://www.kernel.org) as an educational exercise to get some experience using the patch command. After completing the patch download, investigate the changes to the patched kernel source tree.



1) Change into the /usr/src directory and copy the /labs/linux 2.4.9.tar.gz file to the directory and then uncompress and untar the linux 2.4.9.tar.gz archive. Move the directory created by the tar command execution named linux to a directory named linux-2.4.9 to maintain better version control. Create a directory called /usr/src/patches and then change into that directory. Copy the Linux kernel patch (diff) file named /labs/patch 2.4.10.gz to the /usr/src/patches directory and uncompress (gunzip command) the file and then read the man page for the patch command especially noting the -b, -d and -p options.
# cd /usr/src

# cp /labs/linux-2.4.9.tar.gz /usr/src

# tar -zxvf linux-2.4.9.tar.gz

# mv linux linux-2.4.9

# mkdir /usr/src/patches

# cd patches

# cp /labs/patch-2.4.10.gz /usr/src/patches

# gunzip patch-2.4.10.gz

# man patch




2) Change into the /usr/src/linux 2.4.9 directory and then execute the ls  lR|grep .c.orig command to see that there are no patched source backup files yet. Change back into the /usr/src/patches directory and then execute the following command to apply the patch bundle:

patch  b  d /usr/src/linux 2.4.9  p1 < patch 2.4.10


# cd /usr/src/linux-2.4.9

# ls -lR|grep .c.orig

# cd /usr/src/patches

# patch -b -d /usr/src/linux-2.4.9 -p1 < patch-2.4.10





3) Change into the /usr/src/linux 2.4.9 directory again and then execute the ls  lR|grep .c.orig command to see that there are many patched source backup files now. (Notice how a backup of every original C source file was made before that C source file was patched during the application of the patch bundle.) Run the ls  lR|grep .c.orig|wc -l command to count how many files were actually patched by the patch command execution. Change into the /usr/src directory and move the patched linux 2.4.9 directory to a directory named linux 2.4.10.patched.
# cd /usr/src/linux-2.4.9

# ls -lR|grep .c.orig

# ls -lR|grep .c.orig|wc -l

# cd /usr/src

# mv linux-2.4.9 linux-2.4.10.patched

22–2. LAB: Installing (Patching) a RedHat Kernel Source Tree


Directions

In this lab, you are going to learn how to install (patch) a RedHat Linux kernel source tree.


DISCLAIMER: The sole purpose of this lab is to give you a feel for how to install a new version of the RedHat Linux kernel source tree. Do not rebuild a kernel using this RedHat Linux kernel source tree as none of the (numerous) dependencies will have been downloaded that are required for this version of the RedHat Linux kernel to boot. In fact, it is important to note that patching an existing RedHat installation will (should) usually be accomplished by upgrading to the next RedHat Linux release (RedHat 7.2 to RedHat 7.3, for example) using a RedHat Install CD or some other network media. To manually upgrade is usually a painful process due to the possibility of literally hundreds of RPM package dependencies needing to be installed (in the correct order) to support a build of the new RedHat kernel release.
1) Change into the /usr/src directory and do a long listing of the contents of the directory. Change into the /usr/src/redhat/SOURCES directory and copy the two RedHat RPMs in the /labs directory (kernel source 2.4.18 3.i386.rpm and the kernel doc 2.4.18 3.i386.rpm) files to the current working directory.
# cd /usr/src

# ls -l


# cd /usr/src/redhat/SOURCES

# cp /labs/kernel-* .


2) Examine the contents of the two RedHat kernel RPMs using the rpm command (refer to the man page for more details) with out installing them on your system. Install both RPM packages on your system and do a long listing of the contents of the /usr/src directory.
# rpm -qpl kernel source 2.4.18 3.i386.rpm

# rpm -qpl kernel doc 2.4.18 3.i386.rpm

# rpm -ivh kernel source 2.4.18 3.i386.rpm

# rpm -ivh kernel doc 2.4.18 3.i386.rpm

# ls -l /usr/src
3) Change into the /usr/src/linux 2.4.18 3 directory and execute the make xconfig utility to examine all of the kernel build parameters offered with this new release of RedHat Linux. (Do NOT attempt to rebuild a kernel using this RedHat Linux kernel source tree.) Save the .config file and examine its contents using the vi text editor.
# cd /usr/src/linux 2.4.18 3

# make xconfig



# vi .config



1-
U2794S A.00 http://education.hp.com

© 2002 Hewlett-Packard Company


База данных защищена авторским правом ©shkola.of.by 2016
звярнуцца да адміністрацыі

    Галоўная старонка