[Ubuntu] 切換 kernel 版本

首先在 http://kernel.ubuntu.com/~kernel-ppa/mainline/  選擇要切換的版本,接下來根據 CPU 架構選擇下載  .deb 檔案,例如 4.15 AMD64 版本可以看到有5個 .deb 可下載:

Build for amd64 succeeded (see BUILD.LOG.amd64):
  linux-headers-4.15.0-041500_4.15.0-041500.201802011154_all.deb
  linux-headers-4.15.0-041500-generic_4.15.0-041500.201802011154_amd64.deb
  linux-headers-4.15.0-041500-lowlatency_4.15.0-041500.201802011154_amd64.deb
  linux-image-4.15.0-041500-generic_4.15.0-041500.201802011154_amd64.deb
  linux-image-4.15.0-041500-lowlatency_4.15.0-041500.201802011154_amd64.deb

其中 -lowlatency 是低延遲版本的 kernel,除了 lowlatency 之外還有 -generic、 -rt 、 -preempt 等,沒特殊要求選擇 -generic 就行。

Choosing a Kernel for Your Use Case

These are some simple guidelines provided to help you understand which kernel, and in which order, you should test to fit your use case.

1. If you do not require low latency for your system then please use the -generic kernel.

2. If you need a low latency system (e.g. for recording audio) then please use the -preempt kernel as a first choice. This reduces latency but doesn't sacrifice power saving features. It is available only for 64 bit systems (also called amd64).

3. If the -preempt kernel does not provide enough low latency for your needs (or you have an 32 bit system) then you should try the -lowlatency kernel.

4. If the -lowlatency kernel isn't enough then you should try the -rt kernel

5. If the -rt kernel isn't enough stable for you then you should try the -realtime kernel

先建立一個資料夾, 再使用 wget 下載檔案:

$ mkdir 4.15
$ cd 4.15

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15/linux-headers-4.15.0-041500_4.15.0-041500.201802011154_all.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15/linux-headers-4.15.0-041500-generic_4.15.0-041500.201802011154_amd64.deb

$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.15/linux-image-4.15.0-041500-generic_4.15.0-041500.201802011154_amd64.deb

使用 dpkg 安裝 kernel:

$ dpkg -i *.deb

安裝完成後重開機,使用 uname -r 確認 kernel 版本:

$ uname -r
4.15.0-041500-generic

 

如果要切回原本的 kernel 版本手動在 grub 中選擇要開機的 kernel 就可以了,修改 grub 預設方法如下:

查看 grub menu 目前的選項 (紅字部份):
$ grep "menuentry 'Ubuntu" /boot/grub/grub.cfg
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-cb95ab61-6bbe-462e-ae16-0f2da404f4f4' {
    menuentry 'Ubuntu, with Linux 4.15.0-041500-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-041500-generic-advanced-cb95ab61-6bbe-462e-ae16-0f2da404f4f4' {
    menuentry 'Ubuntu, with Linux 4.15.0-041500-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-041500-generic-recovery-cb95ab61-6bbe-462e-ae16-0f2da404f4f4' {
    menuentry 'Ubuntu, with Linux 4.13.0-21-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.13.0-21-generic-advanced-cb95ab61-6bbe-462e-ae16-0f2da404f4f4' {
    menuentry 'Ubuntu, with Linux 4.13.0-21-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.13.0-21-generic-recovery-cb95ab61-6bbe-462e-ae16-0f2da404f4f4' {

接下來修改 grub config 檔案:
$ sudo nano /etc/default/grup 
找到 GRUB_DEFAULT=0 ,將數字 0 改成想用來開機的 kernel,以這個例子來說:
0 = 'Ubuntu, with Linux 4.15.0-041500-generic'
1 = 'Ubuntu, with Linux 4.15.0-041500-generic (recovery mode)'
2 = 'Ubuntu, with Linux 4.13.0-21-generic'
3 = 'Ubuntu, with Linux 4.13.0-21-generic (recovery mode)'
更新 grup 設定:
$ sudo update-grub
 
 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *