【发布时间】:2018-05-02 05:11:33
【问题描述】:
我已经尝试了几个小时从我的 MacBook Pro 重新编译 https://github.com/torvalds/linux 的 Linux 内核,最后仍然卡住了。很难找到一个教程来理解如何重新编译它,缺少标题,bla bla bla。
- http://www.howardism.org/Technical/Linux/Rebuilding_Kernel.html
- https://medium.com/@ssreehari/implementing-a-system-call-in-linux-kernel-4-7-1-6f98250a8c38
- https://tssurya.wordpress.com/2014/08/19/adding-a-hello-world-system-call-to-linux-kernel-3-16-0/ (但没用,因为我有 v4.17)
PS:我首先尝试了adding a syscall 网站,因为这就是我最初想要做的。
一开始,我收到了.config not found。
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
make[3]: *** [silentoldconfig] Error 1
make[2]: *** [silentoldconfig] Error 2
make[1]: *** No rule to make target `include/config/auto.conf', needed by`include/config/kernel.release'. Stop.
与某些网络链接不同,使用的 conf 不存在或其他错误,所以我从"make menuconfig" 创建一个新的.config(作为网络上的一些答案)。
然后,我尝试再次编译。我尝试了一些命令:
-制作
emixam23@Maximes-MBP:~/Workspace/linux-kernel$ make
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
/bin/sh: scripts/basic/modules.order: Permission denied
make[1]: *** [scripts/basic/modules.order] Error 1
make: *** [scripts_basic] Error 2
- 须藤制作
emixam23@Maximes-MBP:~/Workspace/linux-kernel$ sudo make
Password:
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
HOSTCC arch/x86/tools/relocs_32.o
In file included from arch/x86/tools/relocs_32.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
^~~~~~~
1 error generated.
make[1]: *** [arch/x86/tools/relocs_32.o] Error 1
make: *** [archscripts] Error 2
之后,我开始搜索错误是否来自我的make 命令,我发现了这个:
- sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4
emixam23@Maximes-MBP:~/Workspace/linux-kernel$ sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4
getconf: no such configuration parameter `LFS_CFLAGS'
getconf: no such configuration parameter `LFS_LDFLAGS'
getconf: no such configuration parameter `LFS_LIBS'
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
HOSTCC arch/x86/tools/relocs_32.o
HOSTCC arch/x86/tools/relocs_64.o
HOSTCC arch/x86/tools/relocs_common.o
In file included from arch/x86/tools/relocs_common.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
^~~~~~~
In file included from arch/x86/tools/relocs_32.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
^~~~~~~
In file included from arch/x86/tools/relocs_64.c:2:
arch/x86/tools/relocs.h:13:10: fatal error: 'elf.h' file not found
#include <elf.h>
^~~~~~~
1 error generated.
make[1]: *** [arch/x86/tools/relocs_common.o] Error 1
make[1]: *** Waiting for unfinished jobs....
1 error generated.
1 error generated.
make[1]: *** [arch/x86/tools/relocs_32.o] Error 1
make[1]: *** [arch/x86/tools/relocs_64.o] Error 1
make: *** [archscripts] Error 2
make: INTERNAL: Exiting with 5 jobserver tokens available; should be 4!
所以,根据我得到的错误,我搜索了<elf.h>,它似乎是关于 Android 的。对我来说,它没有任何链接,我的意思是,我有这种感觉。
问题是,我刚刚下载了一个 Linux 内核 (Torvalds),我添加了我的系统调用,现在我正在尝试重新编译它并将它与 vagrant 一起使用。而已。为什么看起来这么复杂?老实说,我感到完全迷失了......你知道我是对的,但我只是误解了一些东西,还是我完全不适合?
我在 MacBook Pro 上工作:
MacBook Pro(视网膜显示屏,15 英寸,2015 年中)
- macOS High Sierra
- 版本 10.13.1
感谢任何提示/帮助
最大
PS:编辑 1:添加我的编辑: https://github.com/Emixam23/linux-kernel/commit/d7d7b66cc6513e7b69fd2122b880c259628c438a
流浪者
我找到了一种解决方法,它是 vagrant :) 使用 vragrant,您可以从 Mac OS 重新编译内核。你只需要vagrant init 然后你将自己连接到vagrant VM vagrant ssh。进入 vagrant VM 后,运行 cd /,您将到达机器的根目录,这也是您创建 VM 的位置,因此您可以从 Mac OS 做任何您想做的事情并从终端 make -j 4 编译: )
【问题讨论】:
-
你为什么要从 macOS 编译 Linux?这听起来会很复杂(例如,参见here)。为什么不使用 Vagrant 启动 Linux VM,然后从那里开始工作?
-
这可能是一个想法,但我不确定该怎么做?我也已经阅读了这个答案
-
我不知道 Buildroot 是否可以使用 MacOS 原生 SDK 构建(您也可以尝试使用自制软件,以防它不同),但值得一试。 Buildroot 是一个 Linux 发行版,它有自己的 SDK,所以,它会先构建 SDK,然后用它来构建其他所有东西,包括 Linux 内核。无需虚拟环境。
-
好的,所以我尝试了
vagrant trusty64并且它部分工作,但是<sys/sysinfos.h>没有找到
标签: macos compilation linux-kernel