Lab #8 The Linux Kernel (Part II) by ywr18717

VIEWS: 0 PAGES: 5

									CNET9565                               Operating Systems II                         2005W
                                             Lab #8


                    Lab #8: The Linux Kernel (Part II)

In this lab, we will upgrade the Linux kernel by building it from source code. This is
a way to customize your Linux kernel to exactly match your machine's hardware, and
also to enable or disable various drivers. The best part is, that if you make a mistake,
you just reboot with the old, working kernel!

1.     Download the latest 2.6 kernel source code (as of February 8, 2005, it is
       2.6.10).

       The main source is ftp.kernel.org, but you can download a copy from the
       course web site, or from Mike Boldin's servers (gojira and mothra).

       Download the file to your home directory.

       ~$ ftp ftp.kernel.org

       log in as "anonymous" password is your email address

       ftp> cd /pub/linux/kernel/v2.6

       ftp> bin

       ftp> get linux-2.6.10.tar.bz2

       ftp> quit


2.     For compactness, the kernel uses bzip compression, which on Fedora Core 3 is
       built into the tar command (on older Linux systems, this may not the case.)
       To extract the source code, run the following command:

       ~$ tar jxf linux-2.6.10.tar.bz2                                     OR
       ~$ bzip2 -d -c linux-2.6.10.tar.bz2                |   tar xf   -

       ~$ cd    linux-2.6.10


3.     There are several methods of building a kernel; view the README file for more
       details.




D:\2005W\cnet9565\labs\lab8\lab8.wpd                                            Page 1 of 5
CNET9565                                  Operating Systems II                    2005W
                                                Lab #8
3.     (continued...)

       For example, to build a custom kernel using a text-based menu system, the
       following commands can be used...

       Note -- we will not be doing this!

               make   menuconfig
               make   dep
               make   bzImage
               make   modules
               make   modules_install
               make   install

4.     Instead, we will be using the same configuration as the existing stock Fedora
       2.6.9-1.667 kernel. Its configuration file is saved as /boot/config-2.6.9-1.667.
       We need to copy it and rename it as .config (a hidden file that the kernel build
       scripts look for).

       ~/linux-2.6.10$ cp        /boot/config-2.6.9-1.667          .config


5.     For the next command, press Enter to accept the defaults for each of kernel
       features added since the 2.6.9 release. You can also customize various items,
       like, for example, building the kernel for a Pentium 4 processor.

       ~/linux-2.6.10$ make            oldconfig


6.     To build the kernel, first we build the kernel (make bzImage), then build any
       loadable kernel modules that are required (make modules). This process should
       take 45-50 minutes... you can do other activities in Linux (like web browsing)
       while the builds are building.

       ~/linux-2.6.10$ make            bzImage   ;   make    modules


7.     To install the kernel, you need to become root.

       ~/linux-2.6.10$ su        -
       Password:




D:\2005W\cnet9565\labs\lab8\lab8.wpd                                          Page 2 of 5
CNET9565                                    Operating Systems II                    2005W
                                                  Lab #8
7.     (continued...)

       First, make a backup of the /boot directory!

       ALWAYS REMEMBER, BACKUPS ARE YOUR FRIENDS!!!!!!

       ~#     mkdir      backups

       /#     cd    /

       /#     tar    cf    ~/backups/boot-200402071620.tar              boot

       /#     tar    cf    ~/backups/etc-200402071620.tar            etc

       ~/backups#        cd   ~/backups

       ~/backups#        gzip   -9     -v   *.tar

       ~/backups#        cd   /etc

       ~/etc#       cp    grub.conf      grub.conf.old


       Second, change to the directory where you built the new kernel.

       ~/etc#      cd    ~yourusername/linux-2.6.10

       /home/yourusername/linux-2.6.10# make                  modules_install

       /home/yourusername/linux-2.6.10# make                  install


8.     View the contents of grub.conf to verify that GRUB will be aware of the new
       kernel.

       #    cat    /etc/grub.conf




D:\2005W\cnet9565\labs\lab8\lab8.wpd                                            Page 3 of 5
CNET9565                                Operating Systems II                                 2005W
                                              Lab #8
8.     (continued...)

       The default grub.conf file for Fedora Core 3:

           # grub.conf generated by anaconda
           #
           # Note that you do not have to rerun grub after making changes to this file
           # NOTICE: You have a /boot partition. This means that
           #          all kernel and initrd paths are relative to /boot/, eg.
           #          root (hd0,0)
           #          kernel /vmlinuz-version ro root=/dev/hda3
           #          initrd /initrd-version.img
           #boot=/dev/hda
           default=0
           timeout=5
           splashimage=(hd0,0)/grub/splash.xpm.gz
           hiddenmenu
           title Fedora Core (2.6.9-1.667)
                  root (hd0,0)
                  kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/ rhgb quiet
                  initrd /initrd-2.6.9-1.667.img




       By adding the new kernel, we get:

           # grub.conf generated by anaconda
           #
           # Note that you do not have to rerun grub after making changes to this file
           # NOTICE: You have a /boot partition. This means that
           #          all kernel and initrd paths are relative to /boot/, eg.
           #          root (hd0,0)
           #          kernel /vmlinuz-version ro root=/dev/hda3
           #          initrd /initrd-version.img
           #boot=/dev/hda
           default=1
           timeout=5
           splashimage=(hd0,0)/grub/splash.xpm.gz
           hiddenmenu
           title Fedora Core (2.6.10)
                  root (hd0,0)
                  kernel /vmlinuz-2.6.10 ro root=LABEL=/ rhgb quiet
                  initrd /initrd-2.6.10.img
           title Fedora Core (2.6.9-1.667)
                  root (hd0,0)
                  kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/ rhgb quiet
                  initrd /initrd-2.6.9-1.667.img




D:\2005W\cnet9565\labs\lab8\lab8.wpd                                                     Page 4 of 5
CNET9565                                Operating Systems II                                2005W
                                              Lab #8
8.     (continued...)

       However, we want GRUB to allow us to choose which kernel it boots. So, four
       small changes are required to the grub.conf – use a text editor to do this.

           # grub.conf generated by anaconda
           #
           # Note that you do not have to rerun grub after making changes to this file
           # NOTICE: You have a /boot partition. This means that
           #           all kernel and initrd paths are relative to /boot/, eg.
           #           root (hd0,0)
           #           kernel /vmlinuz-version ro root=/dev/hda3
           #           initrd /initrd-version.img
           #boot=/dev/hda
           default=0
           timeout=30
           #splashimage=(hd0,0)/grub/splash.xpm.gz
           #hiddenmenu
           title Fedora Core (2.6.10)
                  root (hd0,0)
                  kernel /vmlinuz-2.6.10 ro root=LABEL=/ rhgb quiet
                  initrd /initrd-2.6.10.img
           title Fedora Core (2.6.9-1.667)
                  root (hd0,0)
                  kernel /vmlinuz-2.6.9-1.667 ro root=LABEL=/ rhgb quiet
                  initrd /initrd-2.6.9-1.667.img




9.     Reboot your computer:

       /etc# sync       ;   sync   ;   sync   ;   shutdown     -r   now


10.    Your computer should boot using the new kernel. Verify using uname                 -r or
        cat /proc/version .

       If your computer does not boot with the new kernel, troubleshoot by booting
       with the old kernel. If that does not work, you can boot Linux in "Rescue"
       mode using a Fedora CD-R – this is where those backups become very useful!


11.    When you are done, email your grub.conf and an                ls   -l   /boot   listing to
       Mike Boldin.




D:\2005W\cnet9565\labs\lab8\lab8.wpd                                                    Page 5 of 5

								
To top