1
0
mirror of https://github.com/dynup/kpatch synced 2025-01-01 18:22:01 +00:00

kpatch: install to initrd and load patch modules on boot

When doing "kpatch install", copy the patch modules to the initrd and
install a dracut hook which calls "kpatch apply --all".
This commit is contained in:
Josh Poimboeuf 2014-04-01 15:14:40 -05:00
parent 68c925d9b2
commit eb1bd13278
5 changed files with 76 additions and 1 deletions

View File

@ -1,6 +1,6 @@
include Makefile.inc
SUBDIRS = kpatch-build kpatch kmod man
SUBDIRS = kpatch-build kpatch kmod man contrib
BUILD_DIRS = $(SUBDIRS:%=build-%)
INSTALL_DIRS = $(SUBDIRS:%=install-%)
UNINSTALL_DIRS = $(SUBDIRS:%=uninstall-%)

14
contrib/Makefile Normal file
View File

@ -0,0 +1,14 @@
include ../Makefile.inc
DRACUTDIR=/usr/lib/dracut/modules.d/99kpatch
all:
install: all
$(INSTALL) -d $(DRACUTDIR)
$(INSTALL) module-setup.sh kpatch-apply-all.sh $(DRACUTDIR)
uninstall:
$(RM) $(DRACUTDIR)
clean:

11
contrib/kpatch-apply-all.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Licensed under the GPLv2
#
# Copyright 2014 Red Hat, Inc.
# Josh Poimboeuf <jpoimboe@redhat.com>
insmod /usr/lib/modules/$(uname -r)/kpatch/kpatch.ko
kpatch apply --all

48
contrib/module-setup.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Licensed under the GPLv2
#
# Copyright 2014 Red Hat, Inc.
# Josh Poimboeuf <jpoimboe@redhat.com>
# called by dracut
check() {
if [[ -e /var/lib/kpatch/$kernel ]] || [[ -e /usr/lib/kpatch/$kernel ]]; then
return 0
else
return 1
fi
}
# called by dracut
install() {
# install kpatch script
inst_any -d /usr/sbin/kpatch /usr/local/sbin/kpatch /usr/sbin/kpatch
# install insmod (needed by kpatch script)
inst_symlink /usr/sbin/insmod
# install core module
inst_any -d /usr/lib/modules/$kernel/kpatch/kpatch.ko /usr/local/lib/modules/$kernel/kpatch/kpatch.ko /usr/lib/modules/$kernel/kpatch/kpatch.ko
# install patch modules
if [[ -e /var/lib/kpatch/$kernel ]]; then
inst_dir /var/lib/kpatch/$kernel
for i in /var/lib/kpatch/$kernel/*; do
[[ -e $i ]] || continue
inst "$i"
done
fi
if [[ -e /usr/lib/kpatch/$kernel ]]; then
inst_dir /usr/lib/kpatch/$kernel
for i in /usr/lib/kpatch/$kernel/*; do
[[ -e $i ]] || continue
inst "$i"
done
fi
# install hook script
inst_hook pre-udev 00 "$moddir/kpatch-apply-all.sh"
}

View File

@ -120,6 +120,7 @@ case "$1" in
[[ ${PATCH: -3} == ".ko" ]] || die "$PATCH isn't a .ko file"
mkdir -p "$USERDIR" || die "failed to create install directory"
cp -f "$PATCH" "$USERDIR" || die "failed to install patch $PATCH"
dracut -f || die "dracut failed"
;;
"uninstall")
@ -127,6 +128,7 @@ case "$1" in
PATCH="$2"
find_module "$PATCH" || die "$PATCH is not installed"
rm -f "$USERDIR/$(basename $MODULE)" || die "failed to uninstall patch $PATCH"
dracut -f || die "dracut failed"
;;
"list")