Ustawienie domyślnego startu ze starszej wersji kernela Linux w GRUB

Domyślnie GRUB startuje z 0, czyli wpisu, który jest na samej górze listy. To może być problematyczne, jeśli nasz system się od czasu do czasu aktualizuje, a my z powodu jakiejś aplikacji nie możemy się przenieść na nowszą wersję, na przykład aktualnie Docker nie obsługuje kerneli 5.x, a 4.x owszem. By pozbyć się problemu należy:

  • zawsze odpalać system z tego samego wpisu w GRUB,
  • zapobiec usunięciu starego kernela z systemu.

To pierwsze można osiągnąć poprzez edycję pliku /etc/default/grub. Często nie mamy dostępu do KVMa lub dostęp do niego na serwerach zabiera nam cenny czas, więc możemy sobie wygenerować szybko listę wpisów takim one-linerem:

sed -nre "/submenu|menuentry/s/(.? )'([^']+)'.*/\1 \2/p" < /boot/grub/grub.cfg
menuentry  Ubuntu
submenu  Advanced options for Ubuntu
        menuentry  Ubuntu, with Linux 5.4.0-37-generic
        menuentry  Ubuntu, with Linux 5.4.0-37-generic (recovery mode)
        menuentry  Ubuntu, with Linux 5.4.0-33-generic
        menuentry  Ubuntu, with Linux 5.4.0-33-generic (recovery mode)
        menuentry  Ubuntu, with Linux 4.10.0-42-generic //z tego chcę odpalać system
        menuentry  Ubuntu, with Linux 4.10.0-42-generic (recovery mode)

W takiej sytuacji w /etc/default/grub w zmiennej GRUB_DEFAULT wpisuję wartość:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.10.0-42-generic"
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""
GRUB_RECORDFAIL_TIMEOUT=0
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE=1600x900

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"

Potem wystarczy wykonać sudo update-grub i gotowe. Jeśli nie chce się Wam grzebać w konsoli to jest aplikacja okienkowa, która też robi robotę. Teraz upewnijmy się, że nasz kernel nie zostanie usunięty z systemu. Na początku musimy się zorientować jaka jest nasza wersja kernela (jeśli tego nie widzieliśmy wyżej):

dpkg -l | grep linux-image
ii  linux-image-4.10.0-42-generic         4.10.0-42.46~16.04.1                        amd64        Linux kernel image for version 4.10.0 on 64 bit x86 SMP
rc  linux-image-4.15.0-36-generic         4.15.0-36.39                                amd64        Signed kernel image generic
rc  linux-image-4.15.0-38-generic         4.15.0-38.41                                amd64        Signed kernel image generic
rc  linux-image-4.15.0-39-generic         4.15.0-39.42                                amd64        Signed kernel image generic
rc  linux-image-4.18.0-13-generic         4.18.0-13.14                                amd64        Signed kernel image generic
rc  linux-image-4.18.0-14-generic         4.18.0-14.15                                amd64        Signed kernel image generic
rc  linux-image-4.18.0-15-generic         4.18.0-15.16                                amd64        Signed kernel image generic
ii  linux-image-4.4.0-112-generic         4.4.0-112.135                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-116-generic         4.4.0-116.140                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-119-generic         4.4.0-119.143                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-121-generic         4.4.0-121.145                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-122-generic         4.4.0-122.146                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-124-generic         4.4.0-124.148                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-127-generic         4.4.0-127.153                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-128-generic         4.4.0-128.154                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-130-generic         4.4.0-130.156                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-131-generic         4.4.0-131.157                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-133-generic         4.4.0-133.159                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-134-generic         4.4.0-134.160                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-135-generic         4.4.0-135.161                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-4.4.0-137-generic         4.4.0-137.163                               amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
rc  linux-image-5.0.0-13-generic          5.0.0-13.14                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-15-generic          5.0.0-15.16                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-16-generic          5.0.0-16.17                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-17-generic          5.0.0-17.18                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-19-generic          5.0.0-19.20                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-20-generic          5.0.0-20.21                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-21-generic          5.0.0-21.22                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-23-generic          5.0.0-23.24                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-25-generic          5.0.0-25.26                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-27-generic          5.0.0-27.28                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-29-generic          5.0.0-29.31                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-31-generic          5.0.0-31.33                                 amd64        Signed kernel image generic
rc  linux-image-5.0.0-32-generic          5.0.0-32.34                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-19-generic          5.3.0-19.20                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-22-generic          5.3.0-22.24                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-23-generic          5.3.0-23.25                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-24-generic          5.3.0-24.26                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-26-generic          5.3.0-26.28                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-29-generic          5.3.0-29.31                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-40-generic          5.3.0-40.32                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-42-generic          5.3.0-42.34                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-45-generic          5.3.0-45.37                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-46-generic          5.3.0-46.38                                 amd64        Signed kernel image generic
rc  linux-image-5.3.0-51-generic          5.3.0-51.44                                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-29-generic          5.4.0-29.33                                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-31-generic          5.4.0-31.35                                 amd64        Signed kernel image generic
ii  linux-image-5.4.0-33-generic          5.4.0-33.37                                 amd64        Signed kernel image generic
ii  linux-image-5.4.0-37-generic          5.4.0-37.41                                 amd64        Signed kernel image generic
ii  linux-image-extra-4.10.0-42-generic   4.10.0-42.46~16.04.1                        amd64        Linux kernel extra modules for version 4.10.0 on 64 bit x86 SMP
ii  linux-image-generic                   5.4.0.37.40                                 amd64        Generic Linux kernel image
ii  linux-image-virtual                   5.4.0.37.40                                 amd64        Virtual Linux kernel image

Zaznaczone paczki należy zablokować przed usunięciem i robimy to z poziomu roota:

echo linux-image-4.10.0-42-generic hold | dpkg --set-selections;
echo linux-image-generic hold | dpkg --set-selections;
echo linux-image-extra-4.10.0-42-generic hold | dpkg --set-selections;

I to tyle. Teraz apt ich nie usunie przy aktualizacji.

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *