EXPLORING LINUX KERNEL:
THE EASY WAY!
PROBLEM
Explore linux kernel TCP/IP stack
• Solution
– Try to understand relative kernel code – Available text
– Run kernel in virtualized environment
• Selected solution
– Develop a virtual machine using QEMU – Build Linux kernel as Eclipse project
– Interconnect Eclipse with QEMU
IN THIS PRESENTATION
• Virtualization
• What is QEMU
• Linux
• Root File System • Linux kernel
• Linux under QEMU
VIRTUALIZATION
• Separation of resources from underlying physical
resources
• Examples
─ Memory virtualization
─ Partitioning the hard disk ─ Server virtualization
─ Hardware virtualization
WHY VIRTUALIZATION
• Resource utility optimization
• Testing and Development
• Exploration
WHY VIRTUALIZATION
• Resource utility optimization
• Testing and Development
• Exploration
HOW TO GET VIRTUALIZATION
• Xen
– Baremetal hypervisor
– Open source virtualization
• VMWare
– A number of virtualization products
• VMWare player • Ware workstation
QEMU
• QEMU
– CPU Emulator – Open source
– Emulation of various architectures
• x86, x86_64 • ARM
• MIPS
– Supports large variety of devices
QEMU
• Networking features
– Connection to multiple virtualized instances – Local host connection using NAT
– Use same network as the host
• Communication between host and guest system
• SMP system simulation
– Multiple CPUs can be virtualized to get an SMP
machine
INTRODUCTION TO LINUX
• Robust, open source OS
• Applications range form servers to embedded
systems
• Best option for research purpose
• Two major parts
ROOT FILE SYSTEM
• File system
– File system is hierarchy of directories
• Types of file system
– How data is organized on the disc – Rules to handle the data
ROOT FILE SYSTEM
• Linux file system
– Supports large number of file system types – Everything starts from “root” directory
– Hierarchy may vary with Linux distribution or system
requirement
ROOT FILE SYSTEM
• File system hierarchy
• /bin
– Contains binary executables
ROOT FILE SYSTEM
• File system hierarchy
• /boot
ROOT FILE SYSTEM
• File system hierarchy
• /dev
– Contains device files
ROOT FILE SYSTEM
• File system hierarchy
• /home
– Contains directories of all the users registered to the
system
ROOT FILE SYSTEM
• File system hierarchy
• /lib
ROOT FILE SYSTEM
• File system hierarchy
• /media
– Contains directories for temporarily mounted
removable devices
LINUX FILE SYSTEM
• File system hierarchy
• /etc
– Contains configuration files for all the programs
LINUX FILE SYSTEM
• File system hierarchy
• /sbin
– Named after system binaries
– Contains executable binaries especially for system
ROOT FILE SYSTEM
• File system hierarchy
• /sys
– It is utilized by sysfs
ROOT FILE SYSTEM
• File system hierarchy
• /tmp
ROOT FILE SYSTEM
• File system hierarchy
• /usr
– Contains files that can be shared across multiple
machines.
ROOT FILE SYSTEM
• File system hierarchy
• /var
– Contains variable files – File size varies with time
LINUX KERNEL
• Core of Linux
• Manages hardware
• Distributes the resources
• Basic components of kernel
– Scheduler
– Interrupt handler
– Memory management – System services
Network services & inter-process communication
LINUX KERNEL
• User space
– All user level programs – Limited privilege
• Kernel space
– Protected memory space
– Communicates with user space using system calls and
virtual file systems
– Has complete access to the resources
LINUX KERNEL
• Linux kernel source
– http://www.kernel.org/
LINUX KERNEL
• Distribution of Linux
– Debian – SUSE Linux – Gentoo – Slackware– Red Hat Enterprise Linux – Fedore Project
BOOTING THE LINUX KERNEL
• System startup
• BIOS
– Power on self test
• Checks the hardware
– Search for bootable device
• CD-ROM
• Disk partition • USB
• Bootable kernel file
BOOTING THE LINUX KERNEL
• Booting procedure in vmlinuz
– Basic hardware startup – Basic environment setup – Kernel decompression
• decompress_kernel()
– Memory management
BOOTING THE LINUX KERNEL
• Start_kernel() performs
– initialization of procedure – Setup interrupts
– Load of initial-RAM disk (initrd) in memory
BOOTING THE LINUX KERNEL
Initial-RAM disc (initrd.img)
– Initial root file system
– 1st step to load real file system
LINUX UNDER QEMU
• Requirement to run Linux on QEMU
– Virtualized hardware
– Root file system (initrd.img)
– Linux kernel (bzimage of Linux kernel)
LINUX UNDER QEMU
• BIOS in QEMU
– QEMU uses SeaBIOS
– SeaBIOS is a free BIOS implementation
– SeaBIOS can be used to boot emulator/hardware
LINUX UNDER QEMU
• -append option specifies the device on which the
file system is mounted
– ‘root=/dev/ram rw’
• ‘rw’ gives read/write permission
• Flags are added to support debuging
– Example: -s and –S
• -s: start servergdb
LINUX KERNEL DEBUGGING
Procedure of linux debugging
– Setup kernel source code as Eclipse project – Build the project
– Setup emulator to run virtualized machine – Connect Eclipse with emulator
– Setup break points in kernel source – Run debug configuration.