《深入理解Linux内核》实验环境搭建

《深入理解Linux内核》实验环境搭建

背景

前前后后看《深入理解Linux内核》这本书也有两三遍了,每次刚开始都是决心满满的开始,但是都是以失望而结束,对内核的理解也一直只是停留在一些基本概念的掌握,真正深入到各种机制及实现还是完全一窍不通。所以就在网上找了下一些前辈的学习方法,大部分的建议都是基于代码和实验去深入的学习。
基于此,所以搭建实验环境就是开始的第一步,由于《深入理解Linux内核》参考的内核版本是Linux v2.6.11.12,属于比较的老的版本,编译该版本所依赖的一些工具也只能用一些较老的版本(可以通过查看Documentations/Changes)。如果完全去找到这些工具并安装其实也是挺费劲的一件事,所以就在网上找到了两个别人搭好的现成的环境来使用,并且这两套实验环境当前也有人一直在维护,碰到问题他们也会及时响应。
这两个工具是:
1. http://tinylab.org/linux-lab/: 本文主要是基于该环境进行讲解。
2. https://biscuitos.github.io/

依赖软件及cloud-lab获取

  1. Git
  2. Docker
  3. 下载cloud-lab: git clone https://gitee.com/tinylab/cloud-lab.git (注意一定不能用root用户来clone)

使用步骤

  1. 下载完后进入到cloud-lab目录,选择linux-lab:
cd cloud-lab/ && tools/docker/choose linux-lab
  1. 启动Linux-lab, 选择bash登录:
    在这里插入图片描述
  2. 查看支持的开发板
make list
  1. 选择开发板,我们的书籍主要是讲X86架构,所以选择i386/pc:
    在这里插入图片描述
  2. 查看该块板子支持的内核版本:
ubuntu@linux-lab:/labs/linux-lab$ make list-linux
v2.6.10 v2.6.11.12 v2.6.12.6 v2.6.21.5 v2.6.24.7 v2.6.34.9 v2.6.35.14 v2.6.36 v4.6.7 [v5.1] v5.2
  1. 由于《深入理解Linux内核》是以v2.6.11.12为示例讲解的,所以切到这个版本:
ubuntu@linux-lab:/labs/linux-lab$ make local-config LINUX=v2.6.11.12
tools/board/config.sh LINUX=v2.6.11.12 /labs/linux-lab/boards/i386/pc/.labconfig v2.6.11.12;
LINUX := v2.6.11.12 /labs/linux-lab/boards/i386/pc/.labconfig
  1. 编译内核:
make build kernel

编译产生的文件在:

shawn@shawn-ThinkPad-T480:~/cloud-lab/labs/linux-lab/build/i386/linux-v2.6.11.12-pc$ pwd
/home/shawn/cloud-lab/labs/linux-lab/build/i386/linux-v2.6.11.12-pc

如果是第一次编译的话,首先会将代码下载下来,并放在:

shawn@shawn-ThinkPad-T480:~/cloud-lab/labs/linux-lab/src/linux-stable$ pwd
/home/shawn/cloud-lab/labs/linux-lab/src/linux-stable
  1. 启动内核: make boot, 实验用的Linux系统的用户名为root,没有密码:
    在这里插入图片描述
  2. 内核的配置
make menuconfig kernel

默认配置存放在如下目录:

shawn@shawn-ThinkPad-T480:~/cloud-lab/labs/linux-lab/boards/i386/pc/bsp/configs$ pwd
/home/shawn/cloud-lab/labs/linux-lab/boards/i386/pc/bsp/configs
shawn@shawn-ThinkPad-T480:~/cloud-lab/labs/linux-lab/boards/i386/pc/bsp/configs$ ls
buildroot_2019.02.2_defconfig  linux_v2.6.12.6_defconfig  linux_v2.6.35.14_defconfig  linux_v4.6.7_defconfig
buildroot_2019.11_defconfig    linux_v2.6.21.5_defconfig  linux_v2.6.36_defconfig     linux_v5.1_defconfig
linux_v2.6.10_defconfig        linux_v2.6.24.7_defconfig  linux_v2.6.38_defconfig     linux_v5.2_defconfig
linux_v2.6.11.12_defconfig     linux_v2.6.34.9_defconfig  linux_v4.4_defconfig
  1. 通过tftp实现与主机的文件共享:
    在 Qemu 开发板上运行 tftp 命令访问主机的 tftp 服务器。
    主机侧:
$ ifconfig br0
inet addr:172.17.0.3  Bcast:172.17.255.255  Mask:255.255.0.0
$ cd tftpboot/
$ ls tftpboot
kft.patch kft.log

Qemu 开发板:

$ ls
kft_data.log
$ tftp -g -r kft.patch 172.17.0.3
$ tftp -p -r kft.log -l kft_data.log 172.17.0.3

注意: 当把文件从 Qemu 开发板发送到主机侧时,必须先在主机上创建一个空的文件,这是一个 bug?!

  1. GDB调试Linux内核:
    1)使用调试选项编译内核:
    	$ make feature f=debug
    	$ make kernel-olddefconfig
    	$ make kernel
    
    2) 开两个终端并都进入到linux-lab内:
    $ make debug
    打开另外一个新的终端窗口,请通过相应方式再登陆一次 Linux Lab,再次运行如下命令即可:
    $ make debug
    gdb的默认初始化脚本在labs/linux-lab.gdb/kernel.default,可以根据自己的需要修改

cloud-lab官方网站

官方网址: http://tinylab.org/cloud-lab
gitee 上的项目地址:https://gitee.com/tinylab/cloud-lab

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Preface The Audience for This Book Organization of the Material Level of Description Overview of the Book Background Information Conventions in This Book How to Contact Us Safari? Enabled Acknowledgments Chapter 1. Introduction Section 1.1. Linux Versus Other Unix-Like Kernels Section 1.2. Hardware Dependency Section 1.3. Linux Versions Section 1.4. Basic Operating System Concepts Section 1.5. An Overview of the Unix Filesystem Section 1.6. An Overview of Unix Kernels Chapter 2. Memory Addressing Section 2.1. Memory Addresses Section 2.2. Segmentation in Hardware Section 2.3. Segmentation in Linux Section 2.4. Paging in Hardware Section 2.5. Paging in Linux Chapter 3. Processes Section 3.1. Processes, Lightweight Processes, and Threads Section 3.2. Process Descriptor Section 3.3. Process Switch Section 3.4. Creating Processes Section 3.5. Destroying Processes Chapter 4. Interrupts and Exceptions Section 4.1. The Role of Interrupt Signals Section 4.2. Interrupts and Exceptions Section 4.3. Nested Execution of Exception and Interrupt Handlers Section 4.4. Initializing the Interrupt Descriptor Table Section 4.5. Exception Handling Section 4.6. Interrupt Handling Section 4.7. Softirqs and Tasklets Section 4.8. Work Queues Section 4.9. Returning from Interrupts and Exceptions Chapter 5. Kernel Synchronization Section 5.1. How the Kernel Services Requests Section 5.2. Synchronization Primitives Section 5.3. Synchronizing Accesses to Kernel Data Structures Section 5.4. Examples of Race Condition Prevention Chapter 6. Timing Measurements Section 6.1. Clock and Timer Circuits Section 6.2. The Linux Timekeeping Architecture Section 6.3. Updating the Time and Date Section 6.4. Updating System Statistics Section 6.5. Software Timers and Delay Functions Section 6.6. System Calls Related to Timing Measurements Chapter 7. Process Scheduling Section 7.1. Scheduling Policy Section 7.2. The Scheduling Algorithm Section 7.3. Data Structures Used by the Scheduler Section 7.4. Functions Used by the Scheduler Section 7.5. Runqueue Balancing in Multiprocessor Systems Section 7.6. System Calls Related to Scheduling Chapter 8. Memory Management Section 8.1. Page Frame Management Section 8.2. Memory Area Management Section 8.3. Noncontiguous Memory Area Management Chapter 9. Process Address Space Section 9.1. The Processs Address Space Section 9.2. The Memory Descriptor Section 9.3. Memory Regions Section 9.4. Page Fault Exception Handler Section 9.5. Creating and Deleting a Process Address Space Section 9.6. Managing the Heap Chapter 10. System Calls Section 10.1. POSIX APIs and System Calls Section 10.2. System Call Handler and Service Routines Section 10.3. Entering and Exiting a System Call Section 10.4. Parameter Passing Section 10.5. Kernel Wrapper Routines Chapter 11. Signals Section 11.1. The Role of Signals Section 11.2. Generating a Signal Section 11.3. Delivering a Signal Section 11.4. System Calls Related to Signal Handling Chapter 12. The Virtual Filesystem Section 12.1. The Role of the Virtual Filesystem (VFS) Section 12.2. VFS Data Structures Section 12.3. Filesystem Types Section 12.4. Filesystem Handling Section 12.5. Pathname Lookup Section 12.6. Implementations of VFS System Calls Section 12.7. File Locking Chapter 13. I/O Architecture and Device Drivers Section 13.1. I/O Architecture Section 13.2. The Device Driver Model Section 13.3. Device Files Section 13.4. Device Drivers Section 13.5. Character Device Drivers Chapter 14. Block Device Drivers Section 14.1. Block Devices Handling Section 14.2. The Generic Block Layer Section 14.3. The I/O Scheduler Section 14.4. Block Device Drivers Section 14.5. Opening a Block Device File Chapter 15. The Page Cache Section 15.1. The Page Cache Section 15.2. Storing Blocks in the Page Cache Section 15.3. Writing Dirty Pages to Disk Section 15.4. The sync( ), fsync( ), and fdatasync( ) System Calls Chapter 16. Accessing Files Section 16.1. Reading and Writing a File Section 16.2. Memory Mapping Section 16.3. Direct I/O Transfers Section 16.4. Asynchronous I/O Chapter 17. Page Frame Reclaiming Section 17.1. The Page Frame Reclaiming Algorithm Section 17.2. Reverse Mapping Section 17.3. Implementing the PFRA Section 17.4. Swapping Chapter 18. The Ext2 and Ext3 Filesystems Section 18.1. General Characteristics of Ext2 Section 18.2. Ext2 Disk Data Structures Section 18.3. Ext2 Memory Data Structures Section 18.4. Creating the Ext2 Filesystem Section 18.5. Ext2 Methods Section 18.6. Managing Ext2 Disk Space Section 18.7. The Ext3 Filesystem Chapter 19. Process Communication Section 19.1. Pipes Section 19.2. FIFOs Section 19.3. System V IPC Section 19.4. POSIX Message Queues Chapter 20. Program ExZecution Section 20.1. Executable Files Section 20.2. Executable Formats Section 20.3. Execution Domains Section 20.4. The exec Functions Appendix A. System Startup Section A.1. Prehistoric Age: the BIOS Section A.2. Ancient Age: the Boot Loader Section A.3. Middle Ages: the setup( ) Function Section A.4. Renaissance: the startup_32( ) Functions Section A.5. Modern Age: the start_kernel( ) Function Appendix B. Modules Section B.1. To Be (a Module) or Not to Be? Section B.2. Module Implementation Section B.3. Linking and Unlinking Modules Section B.4. Linking Modules on Demand Bibliography Books on Unix Kernels Books on the Linux Kernel Books on PC Architecture and Technical Manuals on Intel Microprocessors Other Online Documentation Sources Research Papers Related to Linux Development About the Authors Colophon Index
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值