Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am planning to write some device drivers and I need to get the Linux kernel source. My Linux kernel version is 3.2.0-23-generic-pae and I downloaded the image from this. In many of the articles I have read, it tells me that I need to have the entire kernel tree to start inserting new modules.

Is it enough if I download this image and paste it into the usr/src/ folder or do I have to do something else?

share|improve this question
1  
I usually just install the 'linux-source' package from synaptic when I'm custom compiling for one of my machines, but given you're doing development you might need the most recent version. This link might be useful to you: help.ubuntu.com/community/Kernel/Compile –  Mark Paskal Jul 5 '12 at 5:50

2 Answers 2

up vote 15 down vote accepted

In precise, this will get the source of the kernel:

apt-get source linux-source-3.2.0

Or if you want the git source of the ubuntu kernel:

git clone git://kernel.ubuntu.com/ubuntu/ubuntu-precise.git
share|improve this answer
    
+1 for the git link –  hbdgaf Jul 5 '12 at 6:35
    
If I use git to clone how do i specify the version. Also If i Clone it is it enough if a I copy pate it into the usr/src folder –  Sab Jul 5 '12 at 7:07
    
That git repository is kept to 3.2.0 specifically; it follows what's in Ubuntu Precise (12.04). If you want a different version change ubuntu-precise.git to ubuntu-quantal.git or whatever. It should be fine to just copy into usr/src. –  Bryce Jul 5 '12 at 7:11
    
Okay.Thanks- But how did you find that git link? –  Sab Jul 5 '12 at 7:15
    
Found it at wiki.ubuntu.com/KernelTeam/GitKernelBuild –  Bryce Jul 5 '12 at 7:30
apt-get source linux

is the easiest way. It will download the source from your repository - and it'll be the same as the version you're running (assuming you haven't already customised it).

But if you want to find where the source is maintained you can run:

apt-cache showsrc linux

Look for the 'Vcs-' attribute (Version control system). It'll usually be a git (Vcs-Git) or mercurial repository.

Note - these commands work with any package. Just substitute 'linux' with the package you're interested in. And also note that 'apt-get source' doesn't need sudo access and will dump the source in your current directory.

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.