تتضمن النواة التي توفرها دبيان أكبر كمية ممكنة من الميزات، بالإضافة إلى أكبر كمية من تعريفات الأجهزة، في سبيل تغطية أوسع طيف من تجميعات العتاد الموجودة. لهذا تجد بعض المستخدمين الذين يفضلون إعادة ترجمة النواة حتى تتضمن ما يحتاجونه بشكل خاص فقط. هناك دافعين رئيسيين وراء ذلك. أولاً، قد يُحسن هذا من استهلاك الذاكرة، لأن كود النواة سيحجز الذاكرة دون سبب، حتى لو تكن هناك حاجة له (كما أنه لا ”ينزل“ إلى مساحة التبديل أبداً، لذلك فهو يستهلك الذاكرة RAM الفعلية)، وهذا قد يخفض الأداء الكلي للنظام. كما أن النواة المترجمة محلياً قد تحدّ من خطر المشاكل الأمنية لأن كود النواة المترجم والمستعمل يشكل جزءاً فقط من الكود الكلي.
إعادة ترجمة النواة ضرورية أيضاً إذا كنت تريد استخدام ميزات معينة متاحة بشكل رقع (patches) فقط (وليست مضمنة في نسخ النواة القياسية).
8.10.1. المتطلبات الأولية ومقدمة
ليس غريباً أن تدير دبيان النواة بشكل حزمة، ولم تكن هذه الطريقة هي المتبعة في ترجمة وتثبيت النوى تقليدياً. بما أن النواة تبقى تحت سيطرة نظام الحزم، فيمكن عندها إزالتها بشكل نظيف، أو تنصيبها على عدة أجهزة. بالإضافة لذلك، تؤتمت السكربتات المرتبطة بهذه الحزم التفاعلات مع محمل الإقلاع ومولد initrd.
تحوي أكواد لينكس المنبعية (upstream) كل ما تحتاجه لبناء حزمة دبيان للنواة. لكنك تحتاج مع ذلك تثبيت build-essential لضمان أنك تملك الأدوات اللازمة لبناء حزمة دبيان. بالإضافة لذلك، تحتاج خطوة ضبط النواة للحزمة libncurses5-dev. أخيراً، تسمح الحزمة fakeroot بإنشاء حزمة دبيان دون استخدام الصلاحيات الإدارية.
8.10.2. الحصول على الشفرة المصدرية
تتوفر الشِّفرة المصدرية للنواة لينكس في حزمة، ككل الأشياء التي قد تكون لها فائدة في نظام دبيان. للحصول عليها، فقط ثبّت الحزمة
linux-source-version. يسرد الأمر
apt-cache search ^linux-source
نسخ النواة المختلفة التي توفرها دبيان. يتوفر الإصدار الأخير في التوزيعة
غير المستقرة: يمكنك الحصول عليه دون مخاطرة كبيرة (خصوصاً إذا أعددت APT عندك حسب تعليمات
قسم 6.2.6, “العمل مع عدة توزيعات”). لاحظ أن الشفرة المصدرية التي تحويها هذه الحزم لا تتفق تماماً مع تلك التي ينشرها لينوس تورفالدس ومطورو النواة؛ لأن دبيان –كباقي التوزيعات– تطبّق عدداً من الرقع، التي قد تصل (أو لا تصل) إلى النسخة المنبعية من لينكس. تشمل هذه التعديلات نقلاً خلفياً لتصحيحات أو مزايا أو تعاريف من نسخ النواة الأحدث، ومزايا لم تُدمج (بالكامل) بعد في شجرة لينكس المنبعية، وأحياناً بعض تعديلات الخاصة بدبيان.
The remainder of this section focuses on the 3.16 version of the Linux kernel, but the examples can, of course, be adapted to the particular version of the kernel that you want.
We assume the linux-source-3.16 package has been installed. It contains /usr/src/linux-source-3.16.tar.xz
, a compressed archive of the kernel sources. You must extract these files in a new directory (not directly under /usr/src/
, since there is no need for special permissions to compile a Linux kernel): ~/kernel/
is appropriate.
$
mkdir ~/kernel; cd ~/kernel
$
tar -xaf /usr/src/linux-source-3.16.tar.xz
تتمثل الخطوة التالية في إعداد النواة حسب احتياجاتك. تعتمد الإجراءات الدقيقة على أهدافك.
عند إعادة ترجمة نسخة أحدث من النواة (تحوي رقع إضافية مثلا)، ستبقى الإعدادات أقرب ما يمكن إلى الإعدادات التي تقترحها دبيان على الأغلب. في هذه الحالة، يمكن بدلاً من إعادة ضبط كل شيء بدءاً من الصفر أن تنسخ الملف /boot/config-version
(يقصد بكلمة version نسخة النواة المستخدمة حالياً، التي يمكن معرفتها بالأمر uname -r
) إلى ملف .config
في المجلد الذي يحوي أكواد النواة.
$
cp /boot/config-3.16.0-4-amd64 ~/kernel/linux-source-3.16/.config
Unless you need to change the configuration, you can stop here and skip to
قسم 8.10.4, “ترجمة وبناء الحزمة”. If you need to change it, on the other hand, or if you decide to reconfigure everything from scratch, you must take the time to configure your kernel. There are various dedicated interfaces in the kernel source directory that can be used by calling the
make target
command, where
target is one of the values described below.
make menuconfig
compiles and executes a text-mode interface (this is where the libncurses5-dev package is required) which allows navigating the options available in a hierarchical structure. Pressing the Space key changes the value of the selected option, and Enter validates the button selected at the bottom of the screen; Select returns to the selected sub-menu; Exit closes the current screen and moves back up in the hierarchy; Help will display more detailed information on the role of the selected option. The arrow keys allow moving within the list of options and buttons. To exit the configuration program, choose Exit from the main menu. The program then offers to save the changes you've made; accept if you are satisfied with your choices.
للواجهات الأخرى ميزات مشابهة، لكنها تعمل ضمن واجهات رسومية أكثر تطوراً؛ مثل make xconfig
التي تستخدم الواجهة الرسومية Qt، و make gconfig
التي تستخدم +GTK. تحتاج الأولى حزمة libqt4-dev، بينما تعتمد الثانية على libglade2-dev و libgtk2.0-dev.
When using one of those configuration interfaces, it is always a good idea to start from a reasonable default configuration. The kernel provides such configurations in arch/arch/configs/*_defconfig
and you can put your selected configuration in place with a command like make x86_64_defconfig
(in the case of a 64-bit PC) or make i386_defconfig
(in the case of a 32-bit PC).
8.10.4. ترجمة وبناء الحزمة
Once the kernel configuration is ready, a simple make deb-pkg
will generate up to 5 Debian packages: linux-image-version that contains the kernel image and the associated modules, linux-headers-version which contains the header files required to build external modules, linux-firmware-image-version which contains the firmware files needed by some drivers (this package might be missing when you build from the kernel sources provided by Debian), linux-image-version-dbg which contains the debugging symbols for the kernel image and its modules, and linux-libc-dev which contains headers relevant to some user-space libraries like GNU glibc.
يتحدد version عبر دمج رقم النسخة المنبعية (الذي يتحدد بالمتغيرات VERSION
و PATCHLEVEL
و SUBLEVEL
و EXTRAVERSION
في ملف Makefile
)، ومتغير الضبط LOCALVERSION
، ومتغير البيئة LOCALVERSION
. أما نسخة الحزمة فتستخدم السلسلة النصية نفسها مع إضافة رقم مراجعة يتزايد آلياً (ويُخزَّن في .version
)، إلا إذا تجاوزته باستخدام متغير البيئة KDEB_PKGVERSION
.
$
make deb-pkg LOCALVERSION=-falcot KDEB_PKGVERSION=$(make kernelversion)-1
[...]
$
ls ../*.deb
../linux-headers-3.16.7-ckt4-falcot_3.16.7-1_amd64.deb
../linux-image-3.16.7-ckt4-falcot_3.16.7-1_amd64.deb
../linux-image-3.16.7-ckt4-falcot-dbg_3.16.7-1_amd64.deb
../linux-libc-dev_3.16.7-1_amd64.deb
8.10.5. ترجمة الوحدات الخارجية
Some modules are maintained outside of the official Linux kernel. To use them, they must be compiled alongside the matching kernel. A number of common third party modules are provided by Debian in dedicated packages, such as xtables-addons-source (extra modules for iptables) or oss4-source (Open Sound System, some alternative audio drivers).
هذه الوحدات الخارجية عديدة ومتنوعة ولا يمكننا ذكرها جميعاً هنا؛ قد يضيق الأمر apt-cache search source$
مجال البحث. على أي حال، لن تفيد هذه القائمة كثيراً لعدم وجود سبب يدعو لترجمة الوحدات الخارجية إلا إذا كنت تعلم أنك تحتاجها. في هذه الحالات، سوف تذكر وثائق الجهاز نموذجياً الوحدات الخاصة التي تحتاجها حتى تعمل في لينكس.
For example, let's look at the xtables-addons-source package: after installation, a .tar.bz2
of the module's sources is stored in /usr/src/
. While we could manually extract the tarball and build the module, in practice we prefer to automate all this using DKMS. Most modules offer the required DKMS integration in a package ending with a -dkms
suffix. In our case, installing xtables-addons-dkms is all that is needed to compile the kernel module for the current kernel provided that we have the linux-headers-* package matching the installed kernel. For instance, if you use linux-image-amd64, you would also install linux-headers-amd64.
$
sudo apt install xtables-addons-dkms
[...]
Setting up xtables-addons-dkms (2.6-1) ...
Loading new xtables-addons-2.6 DKMS files...
First Installation: checking all kernels...
Building only for 3.16.0-4-amd64
Building initial module for 3.16.0-4-amd64
Done.
xt_ACCOUNT:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.16.0-4-amd64/updates/dkms/
[...]
DKMS: install completed.
$
sudo dkms status
xtables-addons, 2.6, 3.16.0-4-amd64, x86_64: installed
$
sudo modinfo xt_ACCOUNT
filename: /lib/modules/3.16.0-4-amd64/updates/dkms/xt_ACCOUNT.ko
license: GPL
alias: ipt_ACCOUNT
author: Intra2net AG <opensource@intra2net.com>
description: Xtables: per-IP accounting for large prefixes
[...]
لا تتضمن النواة القياسية بعض المزايا لأنها غير ناضجة أو نتيجة بعض الخلافات مع مشرفي النواة. يمكن توزيع هذه المزايا كرقع يستطيع أي أحد تطبيقها على أكواد النواة إذا أراد.
توزع دبيان بعض هذه الرقع في الحزم linux-patch-* أو kernel-patch-* (مثل linux-patch-grsecurity2، التي تضيّق بعض النواحي في سياسة النواة الأمنية). تُثبِّتُ هذه الحزم ملفات في المجلد /usr/src/kernel-patches/
.
إذا أردت تطبيق بعض من هذه الرقع، استخدم الأمر patch
في مجلد الأكواد المصدرية ثم ابدأ ترجمة النواة كما شرحنا سابقاً.
$
cd ~/kernel/linux-source-3.16
$
make clean
$
zcat /usr/src/kernel-patches/diffs/grsecurity2/grsecurity-3.0-3.17.1-201410250027.patch.gz | patch -p1
لاحظ أنه لا يشترط أن تعمل أي رقعة مع جميع إصدارات النواة؛ قد يخفق الأمر patch
عند تطبيق بعض الرقع على أكواد النواة. ستعرض رسالة خطأ تعطي بعض التفاصيل عن سبب الإخفاق؛ في هذه الحالة، راجع الوثائق المتوفرة في حزمة الرقعة (في المجلد /usr/share/doc/linux-patch-*/
). في معظم الحالات، يذكر مشرف الحزمة إصدارات النواة التي أُعدَّت الرقعة لها.