![在系统外解压内核源代码 rpm (OpenSuse)?](https://linux22.com/image/18933/%E5%9C%A8%E7%B3%BB%E7%BB%9F%E5%A4%96%E8%A7%A3%E5%8E%8B%E5%86%85%E6%A0%B8%E6%BA%90%E4%BB%A3%E7%A0%81%20rpm%20(OpenSuse)%EF%BC%9F.png)
我使用 LiveUSB USB 闪存/记忆棒中的 OpenSuse 11.2,可以说它没有太多空间。我需要获取此版本 OpenSuse 的 Linux 源代码,因为需要它们来为我正在使用的应用程序构建驱动程序。我在连接的硬盘驱动器上有足够的磁盘空间,所以我想在那里“安装”源(请注意,在 11.2 上,zypper --download-only
默认情况下将下载到 /var/cache/zypp/packages,这会导致我的 LiveUSB 设置崩溃)。
所以,我执行以下操作:
> cd /media/myhdrive/
> wget http://download.opensuse.org/update/11.2/rpm/src/kernel-source-2.6.31.14-0.8.1.src.rpm
> mkdir kernel-source-2.6.31.14
> cd kernel-source-2.6.31.14/
> rpm2cpio ../kernel-source-2.6.31.14-0.8.1.src.rpm | cpio -idmv --no-absolute-filenames
> ls
arch-symbols kernel-source.rpmlintrc patches.kabi.tar.bz2
built-in-where kernel-source.spec patches.kernel.org.tar.bz2
check-for-config-changes kernel-source.spec.in patches.rpmify.tar.bz2
check-supported-list kernel-spec-macros patches.rt.tar.bz2
compute-PATCHVERSION.sh kernel-syms.spec.in patches.staging.tar.bz2
....
...并且有一堆*.tar.gz
文件(补丁)——而不是任何类似于 C 源文件的东西。我猜我现在应该应用一个脚本/命令来解压源代码树,但我不知道它是什么 - 我已经看到了rpmbuild -bb ...
这里,但我想这将构建另一个.rpm
- 虽然我希望解压实际的源代码(并且在我指定的位置 - 不在/usr/src
根文件系统中或根文件系统上的任何位置)。
有什么想法我现在应该做什么吗?
非常感谢您的回答,
干杯!
编辑:通过构建自定义内核 - FedoraProject,尝试rpmbuild -bp
,但失败了:
# man rpmbuild:
# -bp Executes the "%prep" stage from the spec file. Normally this involves
unpacking the sources and applying any patches.
> mkdir src
> rpmbuild --buildroot=$(pwd)/src/ -bp --target=$(uname -m) kernel-source.spec
Building target platforms: i686
Building for target i686
error: Unable to open /usr/src/packages/SOURCES/kernel-spec-macros: No such file or directory
答案1
编辑:使用-bc
以下开关rpmbuild
:
-bc 从规范文件执行“%build”阶段(在执行 %prep 阶段之后)。
这通常涉及相当于“make”。
...因为-bp
只会解压与 .rpm 相关的“源”,但不会“制作”它们 - 这涉及应用特定的 SUSE 补丁...我的尝试rpmbuild -bp
在下面留下以供参考 - 不是它,在它自己的,甚至没有提取 Linux 源代码。下面是 using 的日志rpmbuild -bc
,它既解压了原版源代码,又给它们应用了补丁(从终端日志可以看到,这里省略了;另请注意,修补后的源将位于“ BUILDROOT
”中):
> mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
> echo "%_topdir $(pwd)/rpmbuild" > ~/.rpmmacros
> rpm -i ../kernel-source-2.6.31.14-0.8.1.src.rpm
> ls rpmbuild/*
rpmbuild/BUILD:
rpmbuild/RPMS:
rpmbuild/SOURCES:
arch-symbols kernel-source.rpmlintrc patches.kernel.org.tar.bz2
built-in-where kernel-source.spec.in patches.rpmify.tar.bz2
...
> cd rpmbuild/SPECS
> rm -rf ../BUILD/*
> rpmbuild -bc --target=`uname -m` kernel-source.spec 2>&1
> ls ../BUILDROOT/
kernel-source-2.6.31.14-0.8.1.i386
> ls ../BUILD
kernel-source-2.6.31.14
> ls -la ../BUILDROOT/kernel-source-2.6.31.14-0.8.1.i386/usr/src/
total 16
drwxr-xr-x 4 linux users 4096 2011-11-11 20:55 .
drwxr-xr-x 3 linux users 4096 2011-11-11 20:54 ..
lrwxrwxrwx 1 linux users 5 2011-11-11 20:54 linux -> linux
drwxr-xr-x 24 linux users 4096 2011-11-11 20:56 linux-2.6.31.14-0.8.1
drwxr-xr-x 23 linux users 4096 2011-11-11 20:55 linux-2.6.31.14-0.8.1-vanilla
> ls ../BUILDROOT/kernel-source-2.6.31.14-0.8.1.i386/usr/src/linux-2.6.31.14-0.8.1
arch crypto fs Kbuild MAINTAINERS README security virt
block Documentation include kdb Makefile REPORTING-BUGS sound
....
好吧,事实证明这非常复杂(鉴于我仍然不知道执行此操作的正确方法),但是该帖子如何在 Centos/Xen 上编译自定义内核或优化 CS:S 服务器指明了道路。在那篇文章之后,我做了这个(仍在kernel-source-2.6.31.14/
OP中的目录中):
> mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
> echo "%_topdir $(pwd)/rpmbuild" > ~/.rpmmacros
> rpm -i ../kernel-source-2.6.31.14-0.8.1.src.rpm
> ls rpmbuild/*
rpmbuild/BUILD:
rpmbuild/RPMS:
rpmbuild/SOURCES:
arch-symbols kernel-source.rpmlintrc patches.kernel.org.tar.bz2
built-in-where kernel-source.spec.in patches.rpmify.tar.bz2
...
> cd rpmbuild/SPECS
> rpmbuild -bp --target=`uname -m` kernel-source.spec
Building target platforms: i686
Building for target i686
error: Failed build dependencies:
fdupes is needed by kernel-source-2.6.31.14-0.8.1.src
> sudo zypper install fdupes
> rpmbuild -bp --target=`uname -m` kernel-source.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/bash -e /var/tmp/rpm-tmp.4uWZo1
+ umask 022
+ cd /path/to/kernel-source-2.6.31.14/rpmbuild/BUILD
+ '[' -e /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/linux-2.6.31.tar.bz2 ']'
+ echo 'Symbol(s): '
Symbol(s):
+ cd /path/to/kernel-source-2.6.31.14/rpmbuild/BUILD
+ rm -rf kernel-source-2.6.31.14
+ /bin/mkdir -p kernel-source-2.6.31.14
+ cd kernel-source-2.6.31.14
+ /usr/bin/bzip2 -dc /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/config.tar.bz2
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /usr/bin/bzip2 -dc /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/patches.arch.tar.bz2
+ /bin/tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /usr/bin/bzip2 -dc /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/patches.drivers.tar.bz2
+ /bin/tar -xf -
+ STATUS=0
... [snip] ...
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
> ls ../BUILD/kernel-source-2.6.31.14/
config patches.arch patches.kabi patches.rt patches.trace
patches.addon patches.drivers patches.kernel.org patches.staging patches.xen
patches.apparmor patches.fixes patches.rpmify patches.suse
....
# ?? no linux sources?
...而且,令人惊讶的是,在这一切之后,我仍然看不到任何 Linux 源代码?但是,我确实注意到-e /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/linux-2.6.31.tar.bz2
在上面的脚本中;并猜测 linux*.tar.bz2 可能没有被解压(Symbol(s):
上面代码片段的原始输出中的行后面没有任何内容);我基本上重复了rpmbuild
tmp 脚本所做的事情:
# done previously
> # cd ./rpmbuild/SPECS/
> # rpmbuild -bp --target=`uname -m` kernel-source.spec 2>&1
> cd ../..
> cd ./rpmbuild/BUILD/kernel-source-2.6.31.14/
> /usr/bin/bzip2 -dc ../../../rpmbuild/SOURCES/linux-2.6.31.tar.bz2 | /bin/tar -xf -
> ls # linux-2.6.31 directory gets created
> ls linux-2.6.31/
arch crypto fs Kbuild Makefile REPORTING-BUGS sound
block Documentation include kernel mm samples tools
...
好吧..最后,那些是我能识别的linux源文件:)
然而,这些似乎仍然是“香草”“未打补丁”的来源 - 我想有一个命令可以完成所有这些以及打补丁,但我不知道它是什么......无论如何,希望这可以也帮助别人一点——干杯!