简体   繁体   English

如何从 linux 内核克隆模块?

[英]How can I clone a module from linux kernel?

If I only want to focus on a module of linux , such as perf , how can I just fork or download perf module related files from github ?如果我只想专注于linux一个模块,例如perf ,我如何只从github fork 或下载perf模块相关文件? I have tried the following command:我尝试了以下命令:

c:\work> git clone https://github.com/torvalds/linux/tree/master/tools/perf
Cloning into 'perf'...
fatal: repository 'https://github.com/torvalds/linux/tree/master/tools/perf/' not found

But it can't work.但它不能工作。

You need to use a combination of two relatively new features of Git.您需要结合使用 Git 的两个相对较新的功能。

The first is sparse-checkout (available since Git 1.7.0).第一个是稀疏结帐(自 Git 1.7.0 起可用)。 Sparse-checkout allows you to keep your workspace clean by explicitely specifying which directories you want to have in your repo. Sparse-checkout 允许你通过明确指定你想要在你的仓库中拥有哪些目录来保持你的工作区干净。 However it does not affect the size of the whole repository and downloading 1GB of all Linux kernel sources is pain in the neck.然而,它不会影响整个存储库的大小,下载 1GB 的所有 Linux 内核源代码是一件令人头疼的事。 That's why you need the second feature:这就是您需要第二个功能的原因:

The second feature is shallow clone (available since Git 1.9.0).第二个特性是浅克隆(从 Git 1.9.0 开始可用)。 It allows you to pull from a repo keeping only n changesets in the history using --depth parameter.它允许您使用--depth参数从仅保留历史记录中的n 个变更集的存储库中--depth

So if you want to get only the tools/perf module this is the way to go:因此,如果您只想获得tools/perf模块,这是要走的路:

git init
git remote add origin https://github.com/torvalds/linux.git
git config core.sparsecheckout true
echo "tools/perf" >> .git/info/sparse-checkout
git pull --depth=1 origin master

Voila!瞧! The only directory in your repo is tools/perf and you had to download only 136MB.你的 repo 中唯一的目录是tools/perf ,你只需要下载 136MB。

Adding to Luboš' answer, since I also needed only perf, but a specific tagged version.添加到 Luboš 的回答中,因为我也只需要 perf,但需要特定的标记版本。 The tags don't appear in the shallow clone.标签不会出现在浅克隆中。 So you need to check out the repo exactly at the tagged version.因此,您需要准确地查看标记版本的 repo。

Replace代替

git pull --depth=1 origin master

with

git fetch --depth=1 origin v4.19
git checkout FETCH_HEAD

if the version you want is 4.19.如果您想要的版本是 4.19。

If you want to actually build that specific perf version you'll need more folders:如果要实际构建特定的 perf 版本,则需要更多文件夹:

git init
git remote add origin https://github.com/torvalds/linux.git
git config core.sparsecheckout true
echo "tools/perf" >> .git/info/sparse-checkout
echo "tools/scripts" >> .git/info/sparse-checkout
echo "tools/build" >> .git/info/sparse-checkout
echo "tools/include" >> .git/info/sparse-checkout
echo "tools/include" >> .git/info/sparse-checkout
echo "tools/arch" >> .git/info/sparse-checkout
echo "tools/lib" >> .git/info/sparse-checkout
git fetch --depth=1 origin v4.19
git checkout FETCH_HEAD
make -C tools/perf

Now (if you have all the dependencies installed):现在(如果您安装了所有依赖项):

$ ./tools/perf/perf --version
perf version 4.19.g84df

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM