Linux directory source code

Where do you download Linux source code? [closed]

Say I’m interested in the source for one particular Linux utility, like factor . Where can I find the source code for that utility?

8 Answers 8

You can also find out which package the binary comes from an download that packages source code.

On Debian (and Ubuntu and anything else that’s based on Debian) you do that like this:

$ dpkg -S /usr/bin/factor coreutils: /usr/bin/factor $ apt-get source coreutils

The first command will check which package contains the file you are searching for (use » which factor » to find out which binary is executed when you just type » factor «).

The second command will download and unpack the sources (including the patches applied to build the package) to the current directory, so it should be executed in a dedicated or temporary directory.

I’m pretty sure rpm -based distributions have a similar mechanism, but I don’t know their commands.

Thanks, that’s a good, non-Google option. I know Google will always be there, but for some reason I still like knowing how to live without it.

and went to the bottom and found ‘GNU coreutils 6.10’. So I googled ‘coreutils’ and. found the site joschi just linked to.

Thanks, this (a general explanation of how to find the source for a given program) is what I was after.

That may not be a good idea for all things. Some distributions may have modified the original for their distribution. It may be a better idea to use the package management software that comes with you system (Package management can get source as well as binaries) See ‘Saua’ below.

To find the package a binary comes from, in rpm based system, you might type:

which will print the package name. Instead, with:

you will get also information on a package, including it’s home page in many cases.

Source rpms also exist, but how to get them depends on the high-level package manager used on top of RPM (yum, urpmi, apt-get4 for rpm, . ).

On most systems, also, /usr/share/doc/ contains some documentation on the program, and the website link is pretty often found somewhere there, maybe in the README.

Usually you’ll find the source code on the website of the program if it is open source. In this case here since factor is part of coreutils.

On Gentoo, simply look in the ebuild you compiled the package with :D.

# which factor /usr/bin/factor # grep '/usr/bin/factor' /var/db/pkg/*/*/CONTENTS /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/bin/factor 5aaf903daa4345efb11618b3cb47e9a5 1224224574 /var/db/pkg/sys-apps/coreutils-6.12-r2/CONTENTS:obj /usr/lib64/debug/usr/bin/factor.debug 517d965636850633e9b15926dde8c222 1224224575 # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/SRC_URI ftp://alpha.gnu.org/gnu/coreutils/coreutils-6.12.tar.lzma mirror://gnu/coreutils/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12.tar.lzma mirror://gentoo/coreutils-6.12-patches-1.0.tar.lzma http://dev.gentoo.org/~vapier/dist/coreutils-6.12-patches-1.0.tar.lzma # cat /var/db/pkg/sys-apps/coreutils-6.12-r2/HOMEPAGE http://www.gnu.org/software/coreutils/

But of course, the source code is probably still available in /usr/portage/distfiles .

Читайте также:  Linux how to execute script

Источник

kernel source code location in linux

I am working in Windows and running fedora through VMware. By default, the kernel source tree should be in usr/src/ directory. Instead I could find only an empty directory called kernels. The actual source code is missing there. When browsing I thought it might be in other directories like /boot . But I couldn’t find source tree there as well. I need to modify system call tables for which I should be able to access those source codes.

3 Answers 3

Kernel source is not installed by default. You can follow e.g. the instructions here to install the source and build your kernel.

You probably need to install the kernel-devel package.

On Fedora, all of the software is managed through a system called the Red Hat Package Manager (RPM). Every file (other than user data and other transient files like logs and such) is «owned» by a package. The ls command is from coreutils , the kernel is probably from kernel and BZFlag (the greatest Linux game ever) is provided by the bzflag package.

In the good old days, you would try to install software by using the rpm command (type » man rpm » for more information) and giving it the path to an RPM file that you had downloaded. The rpm command would then dutifully respond by informing you that you first need to satisfy 33 prerequisites. Then you would go download those 33 prerequisites and try to install them, only to find that each of those had their own prerequisites. And so on.

These days, Fedora has a nice set of online repositories of packages (and you can add others for third party software), and a program called yum that can download databases of all the packages, and you tell yum «install package foo for me» (by typing something like » yum install kernel-devel «) and it goes and figures out that in order to install that package, you need a bunch of other prerequisite packages, and so on. It then automatically downloads and installs everything you need, and away you go. For more information on the various incantations that make yum go, see » man yum «).

Источник

Standard location for holding software source files

Is there a standard location in Linux for holding source files for example OpenSSL. I am building Nginx from source with non default version of OpenSSL. I need to download and untar OpenSSL and I did it in home directory. Now, I wonder is there a standard location in Linux maybe /opt ?

Читайте также:  Timeout tcp connections linux

As terdon wrote /usr/src is the standard location, and you may here find directories for the kernel source (/usr/src/linux linked to /usr/src/linux-version) and for example X11. Source-code for packages installed locally (/usr/local) fits better in /usr/local/src. If you want to build packages «manually» yourself, creating a src-directory in your homedir is probably a good idea. Remember you should not download, unpack or build as root — only install as! If you build deb/rpm-packages, temporary build directories (eg. under /var/tmp) are typically used instead. TBC

If you build and install a package — or create a package (rpm/dem) — yourself, you usually don’t need the source-code anymore after it’s installed. The reason why you may have the source-code for some packages — like the kernel or X11 — under /usr/src (or /usr/local/src if it was created locally), is mostly because you may need them if you’re building (or writing) some software package yourself (eg. some obscure header-files from the kernel, matching your actual system set-up). (Of course, you’ll need it if you want to build your own kernel too. ) But this applies to few packages.

4 Answers 4

Whenever you ask yourself something like this, check out the Filesystem Hierarchy Standard (FHS).There, you will find the following entry:

usr/src : Source code (optional)

Purpose

Source code may be placed in this subdirectory, only for reference purposes

So you can put your source files in subdirectories of /usr/src . That said, this is an optional directory so you can really keep them wherever you like. Source code is not relevant after you’ve compiled it into an executable so the system will never require the source of something to be accessible at a specific location.

In conclusion: /usr/src is a pretty standard location but feel free to choose your own if you prefer.

Just be aware that you really do not want to be messing with /usr/src on a non-Linux system. The BSDs keeps their base system sources there by default and you don’t want to intermingle them with third-party software. Just build in your $HOME somewhere.

The same applies to some sub-directories of /usr/src on Debian derivatives, if you have certain packages installed ( gcc-6-source , binutils-source , DKMS packages, the kernel headers etc.). On Debian, there’s a nice feature where you can add yourself to the src group which owns /usr/src , and then just write there as yourself (without needing to sudo or whatever).

I’ll go further and say you shouldn’t really be touching /usr on any system. You should be putting things in /usr/local . Do BSDs mind you using /usr/local/src ?

It says «only for reference purposes». The same standard says you should not build source code in there, so /usr/src is definitely not the place to put your source code if you plan to do any development.

Читайте также:  Установщик для линукс минт

/usr/local/src is a safe place to keep source code, and build it too. The FHS says: (last line on the table):

/usr/local : Local hierarchy [. ] Requirements: The following directories, or symbolic links to directories, must be in /usr/local Directory Description [. ] src Local source code 

The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated.

It’s not clear what «Local source code» means, but it’s clear the system isn’t going to try to place anything in /usr/local/src , unlike /usr/src , so there seems to be little downside to putting code there.

In fact, I have mine on a separate filesystem:

Filesystem Size Used Avail Use% Mounted on /dev/mapper/data-local_src 79G 46G 30G 61% /usr/local/src 

Note: at least on Debian, your user needs to be added to the staff group in order to write to /usr/local .

As for what «local source code» means, in general it means controlled by the local sysadmin rather than by a distribution. The same as everything else under /usr/local (in theory). So essentially it means exactly what you described.

I don’t see the description you shared at the FHS link (pathname.com/fhs/pub/fhs-2.3.html#USRLOCALLOCALHIERARCHY). Would you be specific? (or did you grab information seperately)

@CloudCho: Look more carefully. It’s the last line on the table. I’ve now added more context, though I don’t think it’s necessary.

If by «standard» you mean conventional, then the place to unpack and build source code is your home directory. Such files are expected to be transient, deleted when you are done, or kept if you like, organised however you please. Your home directory is your area to play with all this kind of stuff.

If you do wish to keep them afterwards, for reference, the «Filesystem Hierarchy Standard» recommends /usr/src . However, this is a guide not a law; and, if you were to get into this habit then venture onto a non-Linux system, you are liable to cause trouble by following it. For example, on a BSD system, base system sources are kept there and you really don’t want to be messing with those. Even on Linux you may run the risk of mingling with any source stored by package managers, which is not desirable.

I would recommend avoiding /usr/src overall. There’s no obvious benefit to keeping anything there at all, and potential risk if you confuse its intended meaning.

Источник

Оцените статью
Adblock
detector