Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using OpenSuse 11.2 from a LiveUSB USB flash/stick, which arguably has not much place on it. I need to get the Linux sources for this version of OpenSuse, as they are needed to build a driver for an application I'm using. I have plenty of disk space on an attached hard-drive, so I'd like to "install" the sources there (note that on 11.2, zypper --download-only will by default download to /var/cache/zypp/packages, which crashes my LiveUSB setup).

So, I do the following:

> 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
....

... and there is a bunch of *.tar.gz files (patches) - and not anything resembling C source files. I'm guessing there is a script/command I should apply now to unpack the source tree, but I have no idea what it - I've seen rpmbuild -bb ... here, but I guess that will build yet another .rpm - while I want the actual sources unpacked (and that at a location I specify - not in /usr/src or anywhere on root filesystem).

Any ideas what I should do now?

Many thanks in advance for any answers,
Cheers!

EDIT: via Building a custom kernel - FedoraProject, trying rpmbuild -bp, but it fails:

# 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
share|improve this question

migrated from stackoverflow.com Nov 12 '11 at 0:35

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 0 down vote accepted

EDIT: Use the -bc switch of rpmbuild:

-bc   Do the "%build" stage from the spec file (after doing the %prep stage).
    This generally involves the equivalent of a "make".

... since -bp will just unpack the "sources" related to the .rpm, but will not "make" them - which involves applying the specific SUSE patches... My attempt to use rpmbuild -bp is left below for reference - not that it, on its own, doesn't even extract the linux sources. Below is the log of using rpmbuild -bc, which both unpacks vanilla sources and applies patches to them (which can be seen from the terminal log, which has been left out here; note also that the patched sources will be in "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
....

Ok, this turned out to be quite convoluted (given I still don't know the proper way to do this), but the post How to compile custom kernel on Centos/Xen or optimize CS:S server showed the way. Following that post, I did this ( still in the kernel-source-2.6.31.14/ directory as in the 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?

... and, surprisingly, after all this, I still couldn't see any linux sources? However, I did notice that -e /path/to/kernel-source-2.6.31.14/rpmbuild/SOURCES/linux-2.6.31.tar.bz2 in the script above; and guessing that the linux*.tar.bz2 probably didn't get unpacked (there was nothing after the Symbol(s): line in the original output for the snippet above); I basically repeated what the rpmbuild tmp script did:

# 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
...

Well.. finally, those are linux source files I can recognize :)

However, those are still, seemingly, the "vanilla" 'unpatched' sources - I guess there is a command that does all this along with patching, but I'm at loss as to what it is... Anyways, hope this may also help others a bit - cheers!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.