mirror of
https://github.com/dynup/kpatch
synced 2025-01-02 18:52:02 +00:00
build and install core module with make
Build and install the kpatch core module with make and make install, rather than building it every time with kpatch build. The only downside to this approach is that the user has to make and make install kpatch every time they get a new kernel. But this is only temporary, until the kpatch module is delivered in an RPM.
This commit is contained in:
parent
09a963cfd9
commit
8085d0402b
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,6 +4,8 @@
|
|||||||
*.ko.cmd
|
*.ko.cmd
|
||||||
*.mod.c
|
*.mod.c
|
||||||
*.swp
|
*.swp
|
||||||
|
.tmp_versions
|
||||||
|
Module.symvers
|
||||||
kpatch-build/add-patches-section
|
kpatch-build/add-patches-section
|
||||||
kpatch-build/create-diff-object
|
kpatch-build/create-diff-object
|
||||||
kpatch-build/link-vmlinux-syms
|
kpatch-build/link-vmlinux-syms
|
||||||
|
@ -5,6 +5,7 @@ INSTALL = /usr/bin/install
|
|||||||
|
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
SBINDIR = $(DESTDIR)$(PREFIX)/sbin
|
SBINDIR = $(DESTDIR)$(PREFIX)/sbin
|
||||||
|
MODULESDIR = $(DESTDIR)$(PREFIX)/lib/modules
|
||||||
LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec/kpatch
|
LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec/kpatch
|
||||||
DATADIR = $(DESTDIR)$(PREFIX)/share/kpatch
|
DATADIR = $(DESTDIR)$(PREFIX)/share/kpatch
|
||||||
|
|
||||||
|
22
README.md
22
README.md
@ -26,13 +26,25 @@ Quick Start
|
|||||||
kernel on any distribution, the "kpatch build" command currently
|
kernel on any distribution, the "kpatch build" command currently
|
||||||
only works on Fedora.*
|
only works on Fedora.*
|
||||||
|
|
||||||
First, use diff to make a source patch against the kernel tree, e.g. foo.patch.
|
Load the kpatch core module:
|
||||||
Then:
|
|
||||||
|
|
||||||
kpatch build foo.patch
|
sudo insmod /usr/local/lib/modules/$(uname -r)/kpatch/kpatch.ko
|
||||||
sudo insmod kpatch.ko kpatch-foo.ko
|
|
||||||
|
|
||||||
Voila, your kernel is patched.
|
Make a source patch against the kernel tree:
|
||||||
|
|
||||||
|
# from a kernel git tree:
|
||||||
|
git diff > /path/to/foo.patch
|
||||||
|
|
||||||
|
Build the hot patch kernel module:
|
||||||
|
|
||||||
|
kpatch build /path/to/foo.patch
|
||||||
|
|
||||||
|
This outputs a hot patch module named `kpatch-foo.ko` in the current
|
||||||
|
directory. Now apply it to the running kernel:
|
||||||
|
|
||||||
|
sudo insmod kpatch-foo.ko
|
||||||
|
|
||||||
|
Done! The kernel is now patched.
|
||||||
|
|
||||||
|
|
||||||
License
|
License
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
include ../Makefile.inc
|
include ../Makefile.inc
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
$(MAKE) -C core
|
||||||
|
|
||||||
install:
|
install:
|
||||||
$(INSTALL) -d $(DATADIR)/core
|
$(INSTALL) -d $(MODULESDIR)/(uname -r)/kpatch
|
||||||
$(INSTALL) -m 644 core/* $(DATADIR)/core
|
$(INSTALL) -m 644 core/kpatch.ko $(MODULESDIR)/(uname -r)/kpatch
|
||||||
$(INSTALL) -d $(DATADIR)/patch
|
$(INSTALL) -d $(DATADIR)/patch
|
||||||
$(INSTALL) -m 644 patch/* $(DATADIR)/patch
|
$(INSTALL) -m 644 patch/* $(DATADIR)/patch
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
$(MAKE) -C core clean
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
# make rules
|
# make rules
|
||||||
KPATCH_BUILD ?= /usr/lib/modules/$(shell uname -r)/build
|
KPATCH_BUILD ?= /usr/src/kernels/$(shell uname -r)
|
||||||
KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD)
|
THISDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
|
ifeq ($(wildcard $(KPATCH_BUILD)),)
|
||||||
|
$(error $(KPATCH_BUILD) doesn\'t exist. Try installing the kernel-devel-$(shell uname -r) RPM.)
|
||||||
|
endif
|
||||||
|
|
||||||
|
KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(THISDIR)
|
||||||
|
|
||||||
kpatch.ko: core.c trampoline.S
|
kpatch.ko: core.c trampoline.S
|
||||||
$(KPATCH_MAKE) kpatch.ko
|
$(KPATCH_MAKE) kpatch.ko
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
KPATCH_NAME ?= patch
|
KPATCH_NAME ?= patch
|
||||||
KPATCH_BUILD ?= /lib/modules/$(shell uname -r)/build
|
KPATCH_BUILD ?= /lib/modules/$(shell uname -r)/build
|
||||||
KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD)
|
KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD)
|
||||||
ccflags-y += -I$(KPATCH_BASEDIR)
|
|
||||||
|
|
||||||
obj-m += kpatch-$(KPATCH_NAME).o
|
obj-m += kpatch-$(KPATCH_NAME).o
|
||||||
|
|
||||||
|
1
kmod/patch/kpatch.h
Symbolic link
1
kmod/patch/kpatch.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../core/kpatch.h
|
@ -153,21 +153,16 @@ for i in $FILES; do
|
|||||||
"$TOOLSDIR"/create-diff-object "orig/$i" "patched/$i" "output/$i" >> "$LOGFILE" 2>&1 || die
|
"$TOOLSDIR"/create-diff-object "orig/$i" "patched/$i" "output/$i" >> "$LOGFILE" 2>&1 || die
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Building core module: kpatch.ko"
|
|
||||||
cd core
|
|
||||||
KPATCH_BUILD="$KSRCDIR" make >> "$LOGFILE" 2>&1 || die
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
echo "Building patch module: kpatch-$PATCHNAME.ko"
|
echo "Building patch module: kpatch-$PATCHNAME.ko"
|
||||||
cd "$TEMPDIR/output"
|
cd "$TEMPDIR/output"
|
||||||
ld -r -o ../patch/output.o $FILES >> "$LOGFILE" 2>&1 || die
|
ld -r -o ../patch/output.o $FILES >> "$LOGFILE" 2>&1 || die
|
||||||
cd "$TEMPDIR/patch"
|
cd "$TEMPDIR/patch"
|
||||||
"$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die
|
"$TOOLSDIR"/add-patches-section output.o ../vmlinux >> "$LOGFILE" 2>&1 || die
|
||||||
KPATCH_BASEDIR="$TEMPDIR/core" KPATCH_BUILD="$KSRCDIR" KPATCH_NAME="$PATCHNAME" make >> "$LOGFILE" 2>&1 || die
|
KPATCH_BUILD="$KSRCDIR" KPATCH_NAME="$PATCHNAME" make >> "$LOGFILE" 2>&1 || die
|
||||||
"$STRIPCMD" "kpatch-$PATCHNAME.ko" >> "$LOGFILE" 2>&1 || die
|
"$STRIPCMD" "kpatch-$PATCHNAME.ko" >> "$LOGFILE" 2>&1 || die
|
||||||
"$TOOLSDIR"/link-vmlinux-syms "kpatch-$PATCHNAME.ko" ../vmlinux >> "$LOGFILE" 2>&1 || die
|
"$TOOLSDIR"/link-vmlinux-syms "kpatch-$PATCHNAME.ko" ../vmlinux >> "$LOGFILE" 2>&1 || die
|
||||||
|
|
||||||
cp -f "$TEMPDIR/patch/kpatch-$PATCHNAME.ko" "$TEMPDIR/core/kpatch.ko" "$BASE" || die
|
cp -f "$TEMPDIR/patch/kpatch-$PATCHNAME.ko" "$BASE" || die
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
echo "SUCCESS"
|
echo "SUCCESS"
|
||||||
|
Loading…
Reference in New Issue
Block a user