1:Back Up Your Working Kernel
- # cp -Rp /boot/kernel /boot/kernel.good
2:保存 Kernel 配置文件
- # cd /usr/src/sys/amd64/conf
- # mkdir /root/kernels
- # cp GENERIC /root/kernels/MYKERNEL
- # ln -s /root/kernels/MYKERNEL
3:Trimming a Kernel
- # dmesg |grep 'not found' (看看GENERIC 内核是不是捕捉到了所有 硬件)
- # dmesg |grep -i cpu (蓝色字体 便是阁下的 CPU架构)
- CPU: Intel(R) Core(TM) i7 CPU Q740 @ 1.73GHz (1728.97-MHz K8-class CPU)
- <你会不会问我了? 内核配置文件 要写 K8 哦?自然不是!>
- 判断内核配置 CPU 选项如何填写:
- # less /usr/src/sys/amd64/conf/NOTES (找到你相应架构的目录)
- CPU OPTIONS
- cpu HAMMER # aka K8, aka Opteron & Athlon64
- 方法一:根据 GENERIC 调整配置
- # vim MYKERNEL
- # Basic Options
- cpu HAMMER (CPU 架构类型)
- ident MYKERNEL (命名)
- makeoptions DEBUG=-g # Build kernel with gdb debug symbols
- options SCHED_ULE # ULE scheduler
- options PREEMPTION # Enable kernel thread preemption
- options INET # InterNETworking
- options INET6 # IPv6 communications protocols
- options SCTP # Stream Control Transmission Protocol
- options FFS # Berkeley Fast Filesystem
- options SOFTUPDATES # Enable FFS soft updates support
- options UFS_ACL # Support for access control lists
- options UFS_DIRHASH # Improve performance on big directories
- options UFS_GJOURNAL # Enable gjournal-based UFS journaling
- options MD_ROOT # MD is a potential root device
- options NFSCLIENT # Network Filesystem Client
- options NFSSERVER # Network Filesystem Server
- options NFSLOCKD # Network Lock Manager
- options NFS_ROOT # NFS usable as /, requires NFSCLIENT
- options MSDOSFS # MSDOS filesystem
- options CD9660 # ISO 9660 filesystem
- options PROCFS # Process filesystem (requires PSEUDOFS)
- options PSEUDOFS # Pseudo-filesystem framework
- options GEOM_PART_GPT # GUID Partition Tables
- options GEOM_LABEL # Provides labelization
- options COMPAT_43TTY # BSD 4.3 TTY compat [KEEP THIS!]
- options COMPAT_FREEBSD32 # Compatible with i386 binaries
- options COMPAT_FREEBSD4 # Compatible with FreeBSD4
- options COMPAT_FREEBSD5 # Compatible with FreeBSD5
- options COMPAT_FREEBSD6 # Compatible with FreeBSD6
- options COMPAT_FREEBSD7 # Compatible with FreeBSD7
- options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI
- options KTRACE # ktrace(1) support
- options SYSVSHM # SYSV-style shared memory
- options SYSVMSG # SYSV-style message queues
- options SYSVSEM # SYSV-style semaphores
- options P1003_1B_SEMAPHORES # POSIX-style semaphores
- options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions
- options KBD_INSTALL_CDEV # install a CDEV entry in /dev
- options AUDIT # Security event auditing
- # Make an SMP-capable kernel by default
- options SMP # Symmetric MultiProcessor Kernel
- ... ... ...
- ... ... ...
- # Device Drivers
- # Floppy drives
- # device fdc (注释掉 没有的设备)
- :wq
- 方法二:Include GENERIC
- # vim MYKERNEL
- ident MYKERNEL (命名)
- include GENERIC (包含 GENERIC)
- options CPU_SOEKRIS (添加 选项)
- nooption MSDOSFS (撤销 选项)
- nodevice fdc (撤销 设备)
- :wq
4:Building a Kernel
- # cd /usr/src
- # make buildkernel KERNCONF=MYKERNEL ()
- # make installkernel KERNCONF=MYKERNEL
- 关于用不用 -j选项:
- (-j:理论上核心数 +1更多不起作用,因为 线程与核心 本身无法等同
- 但是:
- 由于less /usr/src/UPDATING 文档内提到
- General Notes
- -------------
- Avoid using make -j when upgrading. From time to time in the
- past there have been problems using -j with buildworld and/or
- installworld. This is especially true when upgrading between
- "distant" versions (eg one that cross a major release boundary
- or several minor releases, or when several months have passed
- on the -current branch).
- 因此:我建议大家还是不要用了,除了kernel 和 buildworld 其他软件想用无妨!)
5:Testing Kernel
- 方法一:安装后直接运行 new kernel
- 方法二:nextboot
- # make KERNCONF=MYKERNEL INSTKERNAME=test kernel (编译安装时起个名字)
- 此时你已经安装完 new kernel !
- # mv /boot/kernel /boot/kernel.test
- # mkdir /boot/kernel
- # cp /boot/kernel.good/* /boot/kernel/ (将老版本Kernel 拉回来)
- # nextboot -t kernel.test (下次启动运行kernel.test,仅一次)
- # mv /boot/kernel /boot/kernel.previous (测试后保存 老版本 kernel)
- # mv /boot/kernel.test /boot/kernel (将kernel.test 改为默认 kernel)
- ------------------------------------------------------------------------------------------------------
- 声明:这是从书上看到的 我感觉很变态
- 下面这是 less /usr/src/UPDATING 文档里的方法 (这个很正常)
- To test a kernel once
- ---------------------
- If you just want to boot a kernel once (because you are not sure
- if it works, or if you want to boot a known bad kernel to provide
- debugging information) run
- make installkernel KERNCONF=YOUR_KERNEL_HERE KODIR=/boot/testkernel
- nextboot -k testkernel
- 方法三:Loader Prompt
- ok unload (erase the loaded kernel and all modules from memory)
ok load /boot/kernel.test/kernel
ok load /boot/kernel.test/acpi.ko
ok boot (使用 kernel.test 重新启动)
6: