SlideShare a Scribd company logo
1 of 6
Download to read offline
Embedded Linux
                                            kernel usage
                                          Training lab book


Kernel - Kernel sources
Objective: Learn how to get the kernel sources and patch
          them.



After this lab, you will be able to
   Get the kernel sources from the official location
   Apply kernel patches

Setup
Go to the /home/<user>/felabs/sysdev/kernel directory.

Get the sources
Go to the Linux kernel web site (http://www.kernel.org/) and
identify the latest stable version.
Just to make sure you know how to do it, check the version of the    For your convenience, you may copy
Linux kernel running on your machine.                                the source URL from your web
                                                                     browser and then use wget to
We will use linux­2.6.35, which this lab was tested with.            download the sources from the
                                                                     command line:
To practice the patch command later, download the full 2.6.34 
sources. Unpack the archive, which creates a linux­2.6.34            wget <url>
directory.                                                           wget can continue interrupted
                                                                     downloads
Apply patches
Install the patch command, either through the graphical package
manager, or using the following command line:
sudo apt­get install patch
Download the 2 patch files corresponding to the latest 2.6.35 
stable release: a first patch to move from 2.6.34 to 2.6.35 and a
second patch to move from 2.6.35 to 2.6.35.x.
Without uncompressing them (!), apply the 2 patches to the linux­
2.6.34 directory.
                                                                     Did you know it? gvim can open
View one of the 2 patch files with vi or gvim (if you prefer a       compressed files on the fly!
graphic editor), to understand the information carried by such a     Vim supports supports syntax
file. How are described added or removed files?                      highlighting for patch files

Rename the linux­2.6.34 directory to linux­2.6.35.<n>.




             © 2004-2010 Free Electrons, http://free-electrons.com   Creative Commons License
Embedded Linux
                               kernel usage
                             Training lab book




© 2004-2010 Free Electrons, http://free-electrons.com   Creative Commons License
Embedded Linux
                                             kernel usage
                                           Training lab book


Kernel – Configuration and compiling
Objective: get familiar with configuring and compiling the
          kernel



After this lab, you will be able to
   Configure, compile and boot your kernel on a virtual PC.
   Mount and modify a root filesystem image by adding entries
   to the /dev/ directory.

Setup
Stay in the /home/<user>/felabs/sysdev/kernel directory from
the previous lab.

Objectives
The goal of this lab is to configure, build and boot a kernel for a
minimalistic, virtual PC, emulated by the qemu emulator
(http://qemu.org)

Kernel configuration
Run make xconfig to start the kernel configuration interface. The
kernel configuration interface is provided as source code in the
kernel, make xconfig compiles it automatically, but requires
libraries and headers. You will need to install the libqt3­mt­dev 
package, which contains the Qt development files, and the g++ 
package, the C++ compiler.
In the interface, toggle the Option ­> Show Name option. This is        Also try with make menuconfig.
useful sometimes, when the parameter name is more explicit than         Though it is not graphical, some
its description, or when you're are following guidelines which give     people prefer this interface. As the
                                                                        menuconfig interface is based on the
the parameter name itself.                                              Ncurses library, you will have to
Also try the Option ­> Show All Options and Option ­> Show              install the libncurses­dev package
                                                                        to use it.
Debug Info options. They let you see all the parameters which
wouldn't appear otherwise, because they depend on the values of
other parameters. By clicking on the description of such a
parameter, you will see its preconditions and understand why it is
not selectable.
Specify a version suffix, so that you can identify your kernel in the
running system by running uname ­r
or cat /proc/version.
Configure your kernel for a minimalistic PC:
                                                                        We advise you to unselect all options
   Pentium-Pro processor (CONFIG_M686)                                  at once, and add only the ones that
                                                                        you need.
   IDE hard disk (CONFIG_IDE, CONFIG_IDE_GD_ATA,
   CONFIG_IDE_GENERIC)
   ext2 filesystem (CONFIG_EXT2_FS)
   Support for elf binaries (CONFIG_BINFMT_ELF)
Take your time to have a look at other available features!
Don't hesitate to ask your trainer for more details about a given
option.



             © 2004-2010 Free Electrons, http://free-electrons.com      Creative Commons License
Embedded Linux
                                               kernel usage
                                             Training lab book


Compile your kernel
Just run:                                                                 Here, we won't need to run the make 
make                                                                      install command. If we ran it, the
                                                                          kernel would be installed for the
                                                                          workstation PC, while our plans are
The qemu PC emulator                                                      to use an emulated PC.

qemu is a fast tool which can emulate several processors (x86, ppc,
arm, sparc, mips...) or even entire systems.
By using an emulator, you won't have to reboot your workstation
over and over again to test your new kernel.
To install qemu on your system, simply install the qemu package.

Booting your kernel
                                                                          qemu is going to emulate a virtual PC
You are now ready to (try to) boot your new kernel. We will use the       with the following features:
data/linux_i386.img file as root filesystem.                              ­m: specifies its amount of RAM.
                                                                          ­hda: specifies the contents (and
Back to the main lab directory, run the run_qemu script (just adjust      size!) of the virtual hard disk.
the path to the Linux kernel image):                                      ­kernel: kernel image to boot. qemu
                                                                          is here a bootloader too. Before
qemu ­m 32 ­kernel linux­<ver>/arch/x86/boot/bzImage                     starting the emulation, it copies the
­append "root=/dev/hda rw"                                               kernel file to the RAM of the virtual
­hda data/linux_i386.img                                                  PC.
                                                                          ­append: options for the kernel. In
If the kernel doesn't manage to boot, and if the error message is         particular, root=/dev/hda instructs
explicit enough, try to guess what is missing in your kernel              the kernel to boot on the first IDE
                                                                          hard disk of the virtual PC.
configuration, and rebuild your kernel.
Don't hesitate to show your issue to your trainer.
If you are really stuck, you can try with the rescue config file in the
data/ directory, which your instructor is supposed to have
checked.
If everything goes right, you should reach this message:
Warning: unable to open an initial console.
This happens because no console device file is available in the root
filesystem. Without such a file, the shell has no way to interact with
the hardware: reading what you type on the keyboard, and
displaying the output of commands on the screen.
In our case, the device file the shell is trying to use is
/dev/console. All you need is to create it!
Type [Ctrl] C in the terminal running qemu to stop the emulation
or close the qemu window.

Adding a console device to the root filesystem
Use the following commands in                                             root permissions are required to
                                                                          create an entry in /mnt/, as well as
/home/<user>/felabs/sysdev/kernel to access the contents of
                                                                          to run the mount command
the filesystem image:
mkdir fs
sudo mount ­o loop data/linux_i386.img fs/
Now, create the dev/console device that is missing. You can check         Whatever the architecture Linux runs
the /dev/console device file on your training workstation to find         on, major and minor device numbers
                                                                          are always the same.
out the file type as well as the major and minor device numbers.



            © 2004-2010 Free Electrons, http://free-electrons.com         Creative Commons License
Embedded Linux
                                            kernel usage
                                          Training lab book


Once this is done, unmount the root filesystem:                      If you don't umount a filesystem or
sudo umount fs                                                       do not use special mount options, you
                                                                     can't be sure that your changes have
Rerun your qemu command. Now, you should reach a command line        already been committed on the
                                                                     physical media (the .img file in this
shell.                                                               case).
Run a few commands in the virtual PC shell.                          To unmount a filesystem, remember
                                                                     that you must be outside of the
                                                                     directory where the filesystem is
Kernel version                                                       mounted. Otherwise umount will fail
                                                                     with Device or resource busy.
Query the version of the running kernel and make sure you find the
version suffix that you specified at configuration time.

Conclusion
Well done! Now you know how to configure, compile and boot a
kernel on a minimalistic PC.

Going further
If you completed your lab before the others...
  Add framebuffer console support to your kernel, and choose the
  VGA 16 color framebuffer driver. Then, add boot logo support.
  You should now see a penguin logo when your virtual PC boots.
  Add SMP (Symmetric Multi Processing) support to your kernel.       Don't be surprised if the whole
  Using the ­smp option of qemu, simulate a PC with 4 processors.    kernel sources are recompiled after
                                                                     enabling SMP support. This changes
  Because of a temporary qemu bug you will also have to add the      many data structures throughout the
  noapic parameter to the kernel command line (passed by the         kernel sources.
  ­append parameter of qemu), You should now see 4 penguins on
  the framebuffer console, indicating the number of CPUs found
  on your system!
  Add framebuffer console rotation support to your kernel, and       You will find details about how to use
  modify the kernel command line (­append parameter again) to        console rotation in the
  boot your kernel with a 90 degree anticlockwise rotation.          Documentation/fb/fbcon.txt file.




            © 2004-2010 Free Electrons, http://free-electrons.com    Creative Commons License
Embedded Linux
                               kernel usage
                             Training lab book




© 2004-2010 Free Electrons, http://free-electrons.com   Creative Commons License

More Related Content

More from gowell

Lua 语言介绍
Lua 语言介绍Lua 语言介绍
Lua 语言介绍gowell
 
Kernel init
Kernel initKernel init
Kernel initgowell
 
Logging develop
Logging developLogging develop
Logging developgowell
 
Logging introduce
Logging introduceLogging introduce
Logging introducegowell
 
Script meta
Script metaScript meta
Script metagowell
 
Script binding
Script bindingScript binding
Script bindinggowell
 
使用Lua提高开发效率
使用Lua提高开发效率使用Lua提高开发效率
使用Lua提高开发效率gowell
 
Casing3d opengl
Casing3d openglCasing3d opengl
Casing3d openglgowell
 
Pytables
PytablesPytables
Pytablesgowell
 
从动态说开去
从动态说开去从动态说开去
从动态说开去gowell
 

More from gowell (10)

Lua 语言介绍
Lua 语言介绍Lua 语言介绍
Lua 语言介绍
 
Kernel init
Kernel initKernel init
Kernel init
 
Logging develop
Logging developLogging develop
Logging develop
 
Logging introduce
Logging introduceLogging introduce
Logging introduce
 
Script meta
Script metaScript meta
Script meta
 
Script binding
Script bindingScript binding
Script binding
 
使用Lua提高开发效率
使用Lua提高开发效率使用Lua提高开发效率
使用Lua提高开发效率
 
Casing3d opengl
Casing3d openglCasing3d opengl
Casing3d opengl
 
Pytables
PytablesPytables
Pytables
 
从动态说开去
从动态说开去从动态说开去
从动态说开去
 

Recently uploaded

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 

Recently uploaded (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Embedded linux-kernel-usage-labs

  • 1. Embedded Linux kernel usage Training lab book Kernel - Kernel sources Objective: Learn how to get the kernel sources and patch them. After this lab, you will be able to Get the kernel sources from the official location Apply kernel patches Setup Go to the /home/<user>/felabs/sysdev/kernel directory. Get the sources Go to the Linux kernel web site (http://www.kernel.org/) and identify the latest stable version. Just to make sure you know how to do it, check the version of the For your convenience, you may copy Linux kernel running on your machine. the source URL from your web browser and then use wget to We will use linux­2.6.35, which this lab was tested with. download the sources from the command line: To practice the patch command later, download the full 2.6.34  sources. Unpack the archive, which creates a linux­2.6.34  wget <url> directory. wget can continue interrupted downloads Apply patches Install the patch command, either through the graphical package manager, or using the following command line: sudo apt­get install patch Download the 2 patch files corresponding to the latest 2.6.35  stable release: a first patch to move from 2.6.34 to 2.6.35 and a second patch to move from 2.6.35 to 2.6.35.x. Without uncompressing them (!), apply the 2 patches to the linux­ 2.6.34 directory. Did you know it? gvim can open View one of the 2 patch files with vi or gvim (if you prefer a compressed files on the fly! graphic editor), to understand the information carried by such a Vim supports supports syntax file. How are described added or removed files? highlighting for patch files Rename the linux­2.6.34 directory to linux­2.6.35.<n>. © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
  • 2. Embedded Linux kernel usage Training lab book © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
  • 3. Embedded Linux kernel usage Training lab book Kernel – Configuration and compiling Objective: get familiar with configuring and compiling the kernel After this lab, you will be able to Configure, compile and boot your kernel on a virtual PC. Mount and modify a root filesystem image by adding entries to the /dev/ directory. Setup Stay in the /home/<user>/felabs/sysdev/kernel directory from the previous lab. Objectives The goal of this lab is to configure, build and boot a kernel for a minimalistic, virtual PC, emulated by the qemu emulator (http://qemu.org) Kernel configuration Run make xconfig to start the kernel configuration interface. The kernel configuration interface is provided as source code in the kernel, make xconfig compiles it automatically, but requires libraries and headers. You will need to install the libqt3­mt­dev  package, which contains the Qt development files, and the g++  package, the C++ compiler. In the interface, toggle the Option ­> Show Name option. This is Also try with make menuconfig. useful sometimes, when the parameter name is more explicit than Though it is not graphical, some its description, or when you're are following guidelines which give people prefer this interface. As the menuconfig interface is based on the the parameter name itself. Ncurses library, you will have to Also try the Option ­> Show All Options and Option ­> Show  install the libncurses­dev package to use it. Debug Info options. They let you see all the parameters which wouldn't appear otherwise, because they depend on the values of other parameters. By clicking on the description of such a parameter, you will see its preconditions and understand why it is not selectable. Specify a version suffix, so that you can identify your kernel in the running system by running uname ­r or cat /proc/version. Configure your kernel for a minimalistic PC: We advise you to unselect all options Pentium-Pro processor (CONFIG_M686) at once, and add only the ones that you need. IDE hard disk (CONFIG_IDE, CONFIG_IDE_GD_ATA, CONFIG_IDE_GENERIC) ext2 filesystem (CONFIG_EXT2_FS) Support for elf binaries (CONFIG_BINFMT_ELF) Take your time to have a look at other available features! Don't hesitate to ask your trainer for more details about a given option. © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
  • 4. Embedded Linux kernel usage Training lab book Compile your kernel Just run: Here, we won't need to run the make  make install command. If we ran it, the kernel would be installed for the workstation PC, while our plans are The qemu PC emulator to use an emulated PC. qemu is a fast tool which can emulate several processors (x86, ppc, arm, sparc, mips...) or even entire systems. By using an emulator, you won't have to reboot your workstation over and over again to test your new kernel. To install qemu on your system, simply install the qemu package. Booting your kernel qemu is going to emulate a virtual PC You are now ready to (try to) boot your new kernel. We will use the with the following features: data/linux_i386.img file as root filesystem. ­m: specifies its amount of RAM. ­hda: specifies the contents (and Back to the main lab directory, run the run_qemu script (just adjust size!) of the virtual hard disk. the path to the Linux kernel image): ­kernel: kernel image to boot. qemu is here a bootloader too. Before qemu ­m 32 ­kernel linux­<ver>/arch/x86/boot/bzImage  starting the emulation, it copies the ­append "root=/dev/hda rw"  kernel file to the RAM of the virtual ­hda data/linux_i386.img PC. ­append: options for the kernel. In If the kernel doesn't manage to boot, and if the error message is particular, root=/dev/hda instructs explicit enough, try to guess what is missing in your kernel the kernel to boot on the first IDE hard disk of the virtual PC. configuration, and rebuild your kernel. Don't hesitate to show your issue to your trainer. If you are really stuck, you can try with the rescue config file in the data/ directory, which your instructor is supposed to have checked. If everything goes right, you should reach this message: Warning: unable to open an initial console. This happens because no console device file is available in the root filesystem. Without such a file, the shell has no way to interact with the hardware: reading what you type on the keyboard, and displaying the output of commands on the screen. In our case, the device file the shell is trying to use is /dev/console. All you need is to create it! Type [Ctrl] C in the terminal running qemu to stop the emulation or close the qemu window. Adding a console device to the root filesystem Use the following commands in root permissions are required to create an entry in /mnt/, as well as /home/<user>/felabs/sysdev/kernel to access the contents of to run the mount command the filesystem image: mkdir fs sudo mount ­o loop data/linux_i386.img fs/ Now, create the dev/console device that is missing. You can check Whatever the architecture Linux runs the /dev/console device file on your training workstation to find on, major and minor device numbers are always the same. out the file type as well as the major and minor device numbers. © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
  • 5. Embedded Linux kernel usage Training lab book Once this is done, unmount the root filesystem: If you don't umount a filesystem or sudo umount fs do not use special mount options, you can't be sure that your changes have Rerun your qemu command. Now, you should reach a command line already been committed on the physical media (the .img file in this shell. case). Run a few commands in the virtual PC shell. To unmount a filesystem, remember that you must be outside of the directory where the filesystem is Kernel version mounted. Otherwise umount will fail with Device or resource busy. Query the version of the running kernel and make sure you find the version suffix that you specified at configuration time. Conclusion Well done! Now you know how to configure, compile and boot a kernel on a minimalistic PC. Going further If you completed your lab before the others... Add framebuffer console support to your kernel, and choose the VGA 16 color framebuffer driver. Then, add boot logo support. You should now see a penguin logo when your virtual PC boots. Add SMP (Symmetric Multi Processing) support to your kernel. Don't be surprised if the whole Using the ­smp option of qemu, simulate a PC with 4 processors. kernel sources are recompiled after enabling SMP support. This changes Because of a temporary qemu bug you will also have to add the many data structures throughout the noapic parameter to the kernel command line (passed by the kernel sources. ­append parameter of qemu), You should now see 4 penguins on the framebuffer console, indicating the number of CPUs found on your system! Add framebuffer console rotation support to your kernel, and You will find details about how to use modify the kernel command line (­append parameter again) to console rotation in the boot your kernel with a 90 degree anticlockwise rotation. Documentation/fb/fbcon.txt file. © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License
  • 6. Embedded Linux kernel usage Training lab book © 2004-2010 Free Electrons, http://free-electrons.com Creative Commons License