Skip to content

Instantly share code, notes, and snippets.

@cell13
Forked from laozhu/kernel-configure.md
Created January 4, 2016 19:05
Show Gist options
  • Save cell13/2d7658042f99272a5908 to your computer and use it in GitHub Desktop.
Save cell13/2d7658042f99272a5908 to your computer and use it in GitHub Desktop.
Linux 内核编译指南

编译原则

  1. 确定 的功能一定编译进内核
  2. 可能 的功能编译为模块
  3. 不确定 的功能保留默认值,或编译为模组
  4. 选择 双号 版本内核,忽略 单号 内核

准备工作

# 下载Linux内核源代码(Gentoo)
emerge -av vanilla-sources

# 切换到所需内核源代码
eselect kernel list
eselect kernel set 2
cd /usr/src/linux

# 删除之前的核心功能配置文件
make mrproper

# 清理编译过程中的中间文件,不删除配置文件
make clean

配置内核

make menuconfig

配置菜单包括以下几个大项:

[*] 64-bit kernel
    # 64bit 支持
    General setup --->
    # 基本设置
[*] Enable loadable module support --->
    # 模块加载支持
-*- Enable the block layer --->
    # 块设备层支持
    Processor type and features --->
    # 处理器类型和特性选择
    Power management and ACPI options --->
    # 电源管理功能
    Bus options (PCI etc.) --->
    # 总线选项
    Executable file formats / Emulations --->
    # 可执行文件格式
-*- Networking support --->
    # 网络支持
    Device Drivers --->
    # 设备驱动
    Firmware Drivers --->
    # 固件驱动
    File systems --->
    # 文件系统
    Kernel hacking --->
    # 内核技巧
    Security options --->
    # 安全选项
-*- Cryptographic API --->
    # 密码相关API
[*] Virtualization --->
    # 虚拟化
    Library routines --->
    # 函式库

基本设置

[ ] Prompt for development and/or incomplete code/drivers
    # 尚未完成开发的代码或驱动,求稳不选
    
( ) Cross-compliler tool prefix
    # 交叉编译前缀,用不到不选
    
( ) Local version - append to kernel release
[ ] Automatically append version infomation to the version string
    # 以上两项用于自定义内核的版本描述,无意义不设
    
    Kernel compression mode (XZ) --->
    # 内核压缩算法,有 Gzip,Bzip2,LZMA,XZ,LZO 几个选项
    # 选择了较新的 XZ ,有较高的压缩比和解压缩速度

( ) Default hostname
    # 用户未设置 hostname 时的默认值,无意义不设  

[*] Support for paging of anonymous memory (swap)
    # swap 虚拟内存支持,必选

[*] System V IPC
    # 进程间通信,必选

[ ] Open by fhandle syscalls
    # 支持通过文件句柄的系统调用,开发文件系统时可能用到,一般用户可不选       

[ ] Auditing support
    [ ] Enable system-call auditing support
    [ ] Make audit loginuid immutable
    # 审计支持,安装 SELinux 必选,但会拖慢系统,一般用户可不选  

IRQ Subsystem --->
# 中断请求子系统,64位系统下面木有选项,免选了

Timers Subsystem --->
    [*] Tickless System (Dynamic Ticks)
    # 计时子系统,Tickless系统可降能耗,选上
    [ ] High Resolution Timer Support
    # 高精度计时器需要硬件支持,一般硬件不支持,不选

CPU/Task time and stats accounting --->
    Cputime accounting (Simple tick based cputime accounting) --->
        (X) Simple tick based cputime accounting
        ( ) Fine granularity task level IRQ time accounting
    # 统计进程占用CPU时间的方式,这里选择 Simple tick 方式
    [*] BSD Process Accounting
    # 将进程的统计信息写入文件,支持用户级系统调用,必选
        [*] BSD Process Accounting version 3 file format
        # 使用第三版文件格式,不兼容老版本,淘汰老文件格式,选了
        [ ] Export task/process statistics through netlink (EXPERIMENTAL)
        # 通过netlink接口向用户空间导出统计信息,可不选   
        [ ] Enable per-task delay accounting (EXPERIMENTAL)
        # 在统计信息中包含进程等待资源所花费的时间,可不选
        [ ] Enable extended accounting over taskstats (EXPERIMENTAL)
            [ ] Enable pre-task storage I/O accounting (EXPERIMENTAL)
            # 在统计信息中包含额外的信息,可不选
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment