Kpatch et Wheezy, ça fonctionne !
Dans le précédent billet sur kpatch (cf. Kpatch, une alternative libre pour patcher son noyau à chaud !), je contais mes déboires à installer kpatch sur Debian GNU/Linux Wheezy :
Dans un premier temps, j’ai essayé de faire fonctionner kpatch sur une Debian 7.5 (alias Wheezy) mais ce fut laborieux. Par laborieux je veux dire que Wheezy est trop ancienne pour que kpatch puisse fonctionner out of the box.
Hélas, Jessie n’est que la version testing du projet du Debian. Cela signifie que cette version ne peut pas être installée sur un serveur de production. Comme dit dans le précédent billet, Wheezy embarque une version 4.7.2 de gcc et un noyau Linux 3.2 alors que les pré-requis de kpatch sont minimums gcc 4.8.0 et un noyaux Linux 3.7. Après quelques heures passées à essayer de faire fonctionner kpatch sur Wheezy, j’ai enfin réussi à les faire cohabiter !
Pour se faire, j’ai dû créer des paquets gcc 4.9 en les backportant de Jessie, puis installer les sources du noyau 3.14 des backports officiels.
Double cerises sur le gâteau, j’ai créé un paquet kpatch basé sur le tag 1.8.0 du dépôt GitHub et les paquets linux-image-3.14 et linux-image-3.14-dbg, le noyau est compilé avec les options nécessaires au bon fonctionnement de kpatch :
- CONFIG_KALLSYMS_ALL
- CONFIG_FUNCTION_TRACER
Oui oui, vous pouvez dire merci !
Il faut sauver le soldat Wheezy
L’opération consiste uniquement à ajouter deux dépôts à apt et à installer une petite liste de paquets. Plutôt simple non ?
#!/bin/bash # # kpatch install on Debian GNU/Linux Wheezy (7.x) # # Copyright (C) 2014 Gaëtan Trellu <gaetan.trellu@incloudus.com> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, # 02110-1301, USA. # This script currently works on Debian GNU/Linux Wheezy (7.x) # This script: # - Add Wheezy backports to the sources.list # - Add InCloudUs backports to the sources.list # - Install the kernel 3.14 from InCloudUs backports # - Install the kpatch with his dependencies (gcc, etc...) function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | tail -n 1)" == "$1"; } working_dir="/usr/src" backports_name="wheezy-backports" backports_url="deb http://http.debian.net/debian $backports_name main" incloudus_name="backports-incloudus" incloudus_url="deb http://packages.incloudus.com $incloudus_name main" incloudus_pubkey="http://packages.incloudus.com/incloudus/incloudus.pub" if ! version_gt $(uname -r) 3.7 then echo "$backports_url" > /etc/apt/sources.list.d/${backports_name}.list echo "$incloudus_url" > /etc/apt/sources.list.d/${incloudus_name}.list wget $incloudus_pubkey -O- | apt-key add - aptitude update aptitude install -t $backports_name -y initramfs-tools aptitude install -y gcc gcc-4.9 g++-4.9 kpatch linux-image-3.14 linux-image-3.14-dbg update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50 echo "/x\\ YOU HAVE TO REBOOT THE SERVER ON THE ${linux_version} KERNEL WITH: reboot or coldreboot if kdump is installed /x\\" aptitude clean fi
Pour résumer, ce script exécute les actions suivantes :
- Ajoute le dépôt des backports officiels Wheezy à apt
- Ajoute le dépôt InCloudUs à apt qui contient :
- Le noyau Linux 3.14 avec les bonnes options
- La version 4.9 de gcc pour Wheezy
- Le paquet kpatch
Une fois l’exécution du script terminée, il suffit de redémarrer le serveur (ou la VM) sur le bon noyau (3.14).
Vérification finale
Est-ce la bonne version de gcc installée ?
# gcc -v
Résultat :
Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.0-11~bpo70+2' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.9.0 (Debian 4.9.0-11~bpo70+2)
Est-ce la bonne version du noyau ?
# uname -r
Résultat :
3.14
Est-ce que kpatch est bien installé ?
# kpatch
Résultat :
usage: kpatch <command> [<args>] Valid commands: install [-k|--kernel-version=<kernel version>] <module> install patch module to the initrd to be loaded at boot uninstall [-k|--kernel-version=<kernel version>] <module> uninstall patch module from the initrd load --all load all installed patch modules into the running kernel load <module> load patch module into the running kernel replace <module> load patch module into the running kernel, replacing all other modules unload <module> unload patch module from the running kernel info <module> show information about a patch module list list installed patch modules
Tout semble fonctionnel, kpatch est donc prêt à être utilisé. Pour de plus amples informations sur comment utiliser kpatch, je vous invite à relire l’article suivant : Kpatch, une alternative libre pour patcher son noyau à chaud !
Conclusion
Pas de panique, les paquets gcc, kpatch et linux-image présents sur le dépôt InCloudUs seront maintenus.
Lien
- Version 0.2.0 de kpatch : http://lwn.net/Articles/605438/
Gaëtan Trellu (goldyfruit)
Derniers articles parGaëtan Trellu (goldyfruit) (voir tous)
- Qinling, let’s the journey begin! - 23 mai 2019
- systemd-networkd, l’âge de la maturité ? - 13 mars 2018
- Hyper-V, Nova, VxLAN et Open vSwitch, enfin une belle histoire ! - 31 décembre 2017
Un goût de kpatch pour Debian GNU/Linux Wheezy (7.x) par Gaëtan Trellu (goldyfruit) est sous Licence Creative Commons Internationale Attribution 4.0.