Difference between revisions of "Compile Kernel"

From OnnoWiki
Jump to navigation Jump to search
 
(65 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Source code]] [[kernel]] (inti) [[sistem operasi]] [[Linux]] dapat di ambil secara bebas dari situs http://www.kernel.org. Proses / langkah membuat [[sistem operasi]] [[Linux]] dengan cara meng-[[compile kernel]] dapat di lakukan di [[sistem operasi]] [[linux]] yang kita operasikan dan menjalankan perintah-perintah berikut.
 
[[Source code]] [[kernel]] (inti) [[sistem operasi]] [[Linux]] dapat di ambil secara bebas dari situs http://www.kernel.org. Proses / langkah membuat [[sistem operasi]] [[Linux]] dengan cara meng-[[compile kernel]] dapat di lakukan di [[sistem operasi]] [[linux]] yang kita operasikan dan menjalankan perintah-perintah berikut.
  
Jika baru install, ubah password root
+
Siapkan [[kernel]] package
 
 
$ sudo passwd root
 
Password:
 
Password:
 
 
 
Masuk sebagai root
 
 
 
$ su -
 
#
 
 
 
update source
 
 
 
# apt-get update
 
$ sudo apt-get update
 
 
 
  
Set supaya /bin/sh menjadi /bin/bash jika di perlukan
+
apt update
 +
apt -y install libncurses5-dev fakeroot wget bzip2 \
 +
kernel-wedge build-essential makedumpfile libncurses5 libssl-dev \
 +
flex bison libelf-dev
  
  # rm -f /bin/sh
+
  # mungkin tidak bisa di semua versi
  # ln -s /bin/bash /bin/sh
+
  apt -y install kernel-package
  
Siapkan [[kernel]] package
 
  
apt-get update
+
Download source code linux, mungkin sekitar 100+ Mb butuh sekitar 20 menit-an untuk sambungan rakyat biasa :) ...
apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 \
 
fakeroot kernel-wedge build-essential makedumpfile libncurses5
 
apt-get build-dep linux
 
 
 
==Untuk source code .gz==
 
 
Copy [[source code]] [[kernel]]
 
Copy [[source code]] [[kernel]]
  
 +
sudo su
 
  cd /usr/src
 
  cd /usr/src
 
  rm -Rf /usr/src/linux
 
  rm -Rf /usr/src/linux
  wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.8.5.tar.gz
+
  wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.3.tar.xz
  tar xjf linux-3.8.5.tar.gz -C /usr/src
+
  tar xJf linux-6.3.tar.xz -C /usr/src
  ln -s /usr/src/linux-3.8.5 /usr/src/linu
+
  ln -s /usr/src/linux-6.3 /usr/src/linux
  
==Untuk Source Code .xz==
+
==Konfigurasi Kernel sebelum compile==
Copy [[source code]] [[kernel]]
 
  
cd /usr/src
+
Konfigurasi kernel di Linux
rm -Rf /usr/src/linux
 
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.8.5.tar.xz
 
tar xJf linux-3.8.5.tar.xz -C /usr/src
 
ln -s /usr/src/linux-3.8.5 /usr/src/linux
 
 
 
Compile kernel 3.8 di Linux
 
  
 
  cd /usr/src/linux
 
  cd /usr/src/linux
Line 58: Line 34:
 
  make menuconfig
 
  make menuconfig
 
  make-kpkg clean
 
  make-kpkg clean
 +
 +
Beberapa alternatif lain untuk mengkonfigurasi kernel linux adalah
 +
 +
cd /usr/src/linux
 +
make menuconfig
 +
 +
atau
 +
 +
vi /usr/src/linux/.config
 +
 +
===HACK===
 +
 +
Tampaknya .config perlu di hack sedikit
 +
 +
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
 +
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
 +
CONFIG_DEBUG_INFO_BTF=y
 +
 +
 +
ubah menjadi
 +
 +
CONFIG_SYSTEM_TRUSTED_KEYS=""
 +
CONFIG_SYSTEM_REVOCATION_KEYS=""
 +
# CONFIG_DEBUG_INFO_BTF=n
 +
 +
===Catatan Untuk Driver===
 +
 +
Supaya aman, semua driver di compile. Caranya
 +
 +
* Saat "make menuconfig"
 +
* Klik
 +
 +
General Setup > compile also drivers which will not load
 +
 +
==Catatan Untuk Membuat Localversion==
 +
 +
Saat menuconfig
 +
 +
* Masuk > General Setting > Local Version
 +
 +
Dalam Local Version
 +
 +
* Sebaiknya tidak ada huruf besar
 +
* Tidak ada spasi, _ dan character2 yang aneh
 +
* hanya huruf dan angka saja.
 +
 +
  
 
==Proses Compile==
 
==Proses Compile==
 +
 +
Cara yang lebih cepat
 +
 +
cd /usr/src/linux
 +
make all
 +
 +
Kemudian install Linux:
 +
 +
# make firmware_install
 +
make modules_install
 +
make install
 +
 +
Setelah di instalasi kita perlu update grub
 +
 +
update-grub
 +
 +
Booting komputer dan pilih sistem operasi yang baru kita instalasi tersebut.
 +
 +
==Cara Lama==
 +
 
Mungkin akan lebih mudah untuk memaksa compile semua [[source code]] melalui perintah
 
Mungkin akan lebih mudah untuk memaksa compile semua [[source code]] melalui perintah
  
Line 69: Line 112:
 
Proses compile kernel akan memakan waktu lumayan lama, bisa mencapai 2-3 jam atau lebih. Sabar.
 
Proses compile kernel akan memakan waktu lumayan lama, bisa mencapai 2-3 jam atau lebih. Sabar.
  
Setelah selesai, baru di lanjutkan dengan perintah
+
Selanjutnya, (atau tanpa "make all") jalankan fakeroot
  
 
  cd /usr/src/linux
 
  cd /usr/src/linux
 
  fakeroot make-kpkg --initrd --append-to-version=-custom kernel-image kernel-headers
 
  fakeroot make-kpkg --initrd --append-to-version=-custom kernel-image kernel-headers
 +
 +
Alternatif lain, kalau tidak mau ada kata-kata "-custom" dalam versi yang dibuat bisa menggunakan
 +
 +
cd /usr/src/linux
 +
fakeroot make-kpkg --initrd kernel-image kernel-headers
 +
 +
 +
Setelah selesai fakeroot, install image & header kernel menggunakan perintah
  
 
  cd /usr/src
 
  cd /usr/src
  dpkg -i linux-image-3.8.4-custom_3.8.4-custom-10.00.Custom_amd64.deb
+
  dpkg -i linux-image-4.1-custom_4.1-custom-10.00.Custom_amd64.deb
  dpkg -i linux-headers-3.8.4-custom_3.8.4-custom-10.00.Custom_amd64.deb
+
  dpkg -i linux-headers-4.1-custom_4.1-custom-10.00.Custom_amd64.deb
 +
 
 +
File linux-image dan linux-headers mungkin akan berbeda. Sebaiknya lakukan dulu
 +
 
 +
cd /usr/src
 +
ls
 +
 
 +
pastikan nama file linux-image dan linux-headers-nya apa ..
  
 
==GRUB di Ubuntu 9.04 ke bawah==
 
==GRUB di Ubuntu 9.04 ke bawah==
Line 145: Line 203:
 
akan keluar versi kernel yang anda gunakan, misalnya
 
akan keluar versi kernel yang anda gunakan, misalnya
  
  3.8.4-custom
+
  4.5-custom
  
 
==Referensi==
 
==Referensi==
Line 153: Line 211:
 
* http://embedid.net/2010/06/01/linux-kernel-dari-mula-bagian-1/
 
* http://embedid.net/2010/06/01/linux-kernel-dari-mula-bagian-1/
 
* http://embedid.net/2010/06/01/linux-kernel-dari-mula-bagian-2/
 
* http://embedid.net/2010/06/01/linux-kernel-dari-mula-bagian-2/
 +
* http://www.xnote.com/howto/install_linux_kernel.html
 +
* http://kernelnewbies.org/KernelBuild
 +
* http://kernelnewbies.org/KernelHacking
  
 
==Pranala Menarik==
 
==Pranala Menarik==
Line 161: Line 222:
 
* [[Linux]]
 
* [[Linux]]
 
* [[Ubuntu]]
 
* [[Ubuntu]]
 +
* [[Linux: CLI untuk Survival]]
 
* [[Sistem Operasi]]
 
* [[Sistem Operasi]]
 +
* [[Linux: Instalasi Sistem Operasi]]
 +
* [[Linux: Skema Partisi di Linux]]
 
* [[Kernel]]
 
* [[Kernel]]
 
* [[Compile Kernel]]
 
* [[Compile Kernel]]
 +
* [[Compile Kernel: Konfigurasi Kernel]]
 +
* [[Compile Kernel: Ubuntu 16.04 - Source dari apt install]]
 +
* [[Compile Kernel: Buat Kernel Headers untuk VirtualBox]]
 +
* [[Kernel: Anatomi Kernel Source]]
 
* [[OS: Linux Kernel]]
 
* [[OS: Linux Kernel]]
 
* [[OS: Parameter Kernel Default]]
 
* [[OS: Parameter Kernel Default]]
Line 169: Line 237:
 
* [[OS: Complete Teori Tuning Kernel Scheduler]]
 
* [[OS: Complete Teori Tuning Kernel Scheduler]]
 
* [[OS: Complete Teori Tuning I/O Performance]]
 
* [[OS: Complete Teori Tuning I/O Performance]]
 +
* [[OS: Tuning Manajemen Memory]]
 
* [[OS: Tuning Kernel Scheduler]]
 
* [[OS: Tuning Kernel Scheduler]]
 
* [[OS: Tuning Completely Fair Queueing CFQ I/O scheduler]]
 
* [[OS: Tuning Completely Fair Queueing CFQ I/O scheduler]]
Line 176: Line 245:
 
* [[OS: Benchmarking menggunakan UnixBench]]
 
* [[OS: Benchmarking menggunakan UnixBench]]
 
* [[OS: Benchmarking menggunakan LLCBench]]
 
* [[OS: Benchmarking menggunakan LLCBench]]
 +
* [[OS: Mengerti System Call]]
 
* [[OS: Membuat Kernel Modul]]
 
* [[OS: Membuat Kernel Modul]]
 +
* [[OS: Android - Download]]

Latest revision as of 10:35, 4 May 2023

Source code kernel (inti) sistem operasi Linux dapat di ambil secara bebas dari situs http://www.kernel.org. Proses / langkah membuat sistem operasi Linux dengan cara meng-compile kernel dapat di lakukan di sistem operasi linux yang kita operasikan dan menjalankan perintah-perintah berikut.

Siapkan kernel package

apt update
apt -y install libncurses5-dev fakeroot wget bzip2 \
kernel-wedge build-essential makedumpfile libncurses5 libssl-dev \
flex bison libelf-dev
# mungkin tidak bisa di semua versi
apt -y install kernel-package 


Download source code linux, mungkin sekitar 100+ Mb butuh sekitar 20 menit-an untuk sambungan rakyat biasa :) ... Copy source code kernel

sudo su
cd /usr/src
rm -Rf /usr/src/linux
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.3.tar.xz
tar xJf linux-6.3.tar.xz -C /usr/src
ln -s /usr/src/linux-6.3 /usr/src/linux

Konfigurasi Kernel sebelum compile

Konfigurasi kernel di Linux

cd /usr/src/linux
cp -vi /boot/config-`uname -r` ./.config

Langkah cp /boot/config* dibutuhkan jika kita ingin konfigurasi kernel yang digunakan sama dengan konfigurasi kernel dari system operasi yang sedang kita gunakan. Kita dapat meloncati hal ini dan langsung ke make menuconfig.

cd /usr/src/linux
make menuconfig
make-kpkg clean

Beberapa alternatif lain untuk mengkonfigurasi kernel linux adalah

cd /usr/src/linux
make menuconfig

atau

vi /usr/src/linux/.config

HACK

Tampaknya .config perlu di hack sedikit

CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
CONFIG_DEBUG_INFO_BTF=y


ubah menjadi

CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""
# CONFIG_DEBUG_INFO_BTF=n

Catatan Untuk Driver

Supaya aman, semua driver di compile. Caranya

  • Saat "make menuconfig"
  • Klik
General Setup > compile also drivers which will not load

Catatan Untuk Membuat Localversion

Saat menuconfig

  • Masuk > General Setting > Local Version

Dalam Local Version

  • Sebaiknya tidak ada huruf besar
  • Tidak ada spasi, _ dan character2 yang aneh
  • hanya huruf dan angka saja.


Proses Compile

Cara yang lebih cepat

cd /usr/src/linux
make all

Kemudian install Linux:

# make firmware_install
make modules_install
make install

Setelah di instalasi kita perlu update grub

update-grub

Booting komputer dan pilih sistem operasi yang baru kita instalasi tersebut.

Cara Lama

Mungkin akan lebih mudah untuk memaksa compile semua source code melalui perintah

cd /usr/src/linux
make all

Pada awal compile kernel kadang kala kita harus menjawab pertanyaan konfigurasi kalau ternyata konfigurasi kernel yang kita gunakan agak berbeda dengan konfigurasi kernel yang lama.

Proses compile kernel akan memakan waktu lumayan lama, bisa mencapai 2-3 jam atau lebih. Sabar.

Selanjutnya, (atau tanpa "make all") jalankan fakeroot

cd /usr/src/linux
fakeroot make-kpkg --initrd --append-to-version=-custom kernel-image kernel-headers

Alternatif lain, kalau tidak mau ada kata-kata "-custom" dalam versi yang dibuat bisa menggunakan

cd /usr/src/linux
fakeroot make-kpkg --initrd kernel-image kernel-headers


Setelah selesai fakeroot, install image & header kernel menggunakan perintah

cd /usr/src
dpkg -i linux-image-4.1-custom_4.1-custom-10.00.Custom_amd64.deb
dpkg -i linux-headers-4.1-custom_4.1-custom-10.00.Custom_amd64.deb

File linux-image dan linux-headers mungkin akan berbeda. Sebaiknya lakukan dulu

cd /usr/src
ls

pastikan nama file linux-image dan linux-headers-nya apa ..

GRUB di Ubuntu 9.04 ke bawah

Ubah GRUB untuk menambahkan menu untuk booting

vi /boot/grub/menu.lst

Pastikan ada menu untuk booting dari kernel yang baru seperti

title           Ubuntu 9.04, kernel 2.6.29.2-custom
uuid            d0a32d6c-3176-4b92-8cac-6e75acc4348a
kernel          /boot/vmlinuz-2.6.29.2-custom root=UUID=d0a32d6c-3176-4b92-8cac-6e75acc4348a ro quiet splash
initrd          /boot/initrd.img-2.6.29.2-custom
quiet
title           Ubuntu 9.04, kernel 2.6.29.2-custom (recovery mode)
uuid            d0a32d6c-3176-4b92-8cac-6e75acc4348a
kernel          /boot/vmlinuz-2.6.29.2-custom root=UUID=d0a32d6c-3176-4b92-8cac-6e75acc4348a ro  single
initrd          /boot/initrd.img-2.6.29.2-custom

GRUB di Ubuntu 9.10 ke atas

Gunakan cara nekad

update-grub

Jika perintah di atas sudah dilakukan, kita tidak perlu lagi melakukan perintah di bawah ini. Kalau mau iseng mencoba mengedit juga bisa mengubah file,

vi /boot/grub/grub.cfg

Isi informasi kernel yang baru

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry "Ubuntu, Linux 2.6.32.3-custom" {
        recordfail=1
        if [ -n ${have_grubenv} ]; then save_env recordfail; fi
        set quiet=1
        insmod ext2
        set root=(hd0,6)
        search --no-floppy --fs-uuid --set e2482ccc-1480-4c25-adf8-bc77a255b3b3
        linux   /boot/vmlinuz-2.6.32.3-custom root=UUID=e2482ccc-1480-4c25-adf8-bc77a255b3b3 ro    crashkernel=384M-2G:64M,2G-:128M quiet splash
        initrd  /boot/initrd.img-2.6.32.3-custom
}
menuentry "Ubuntu, Linux 2.6.32.3-custom (recovery mode)" {
        recordfail=1
        if [ -n ${have_grubenv} ]; then save_env recordfail; fi
        insmod ext2
        set root=(hd0,6)
        search --no-floppy --fs-uuid --set e2482ccc-1480-4c25-adf8-bc77a255b3b3
        linux   /boot/vmlinuz-2.6.32.3-custom root=UUID=e2482ccc-1480-4c25-adf8-bc77a255b3b3 ro single
        initrd  /boot/initrd.img-2.6.32.3-custom
}
### END /etc/grub.d/40_custom ###

Shutdown dan Reboot komputer

shutdown -r now

Setelah reboot & masuk lagi ke shell lakukan ..

uname -r

akan keluar versi kernel yang anda gunakan, misalnya

4.5-custom

Referensi

Pranala Menarik