summaryrefslogtreecommitdiff
path: root/push_kernel.sh
blob: f8caf10fd394747d915f05a538c749a87eeffa0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

if [ "$#" -ne 1 ] ; then
  echo "usage: $0 <target host>"
  exit 0
fi

if [ ! -f arch/x86/boot/bzImage ] ; then
	echo "run from a linux tree with the kernel built"
	exit 0
fi

# Copy modules
rm -rf /tmp/pk
make INSTALL_MOD_PATH=/tmp/pk INSTALL_MOD_STRIP=1 modules_install
(cd /tmp/pk/lib/modules; rsync -av * root@$1:/lib/modules/)

if [ $? -ne 0 ] ; then
	echo "module copy failed"
	exit 0
fi

# Build kernel image
vbutil_kernel --pack /tmp/new_kern.bin --keyblock /usr/share/vboot/devkeys/kernel.keyblock --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk --version 1 --config ~/hatch-cmdline.txt --bootloader ~/bootstub.efi --vmlinuz arch/x86/boot/bzImage --arch x86_64

if [ $? -ne 0 ] ; then
	echo "failed to build kernel image"
	exit 0
fi

# Setup new kernel to boot from partition B
scp /tmp/new_kern.bin root@$1:/tmp
if [ $? -ne 0 ] ; then
	echo "failed to copy kernel image"
	exit 0
fi

ssh root@$1 dd if=/tmp/new_kern.bin of=/dev/nvme0n1p4 bs=4K
if [ $? -ne 0 ] ; then
	echo "failed to write kernel image on target"
	exit 0
fi

ssh root@$1 cgpt add -i 4 -S 0 -T 1 -P15 /dev/nvme0n1
if [ $? -ne 0 ] ; then
	echo "failed to set new kernel image active on target"
	exit 0
fi