summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/makekernel
blob: 33ffb3021d352c9630c9e51622dc6a7a3802e62e (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh


KEYDIR="/etc/efikeys/"
KERNEL_NAME="vmlinuz-latest-gentoo"

if [[ $(hostname) = "pc" ]]; then
	ROOT_DEVICE="/dev/nvme0n1p3"
	MICROCODE="amd"
	KERNEL_DIR="/boot/efi/gentoo"
	THREADS=12
else
	ROOT_DEVICE="/dev/sda3"
	MICROCODE="intel"
	KERNEL_DIR="/boot/efi/EFI/gentoo"
	THREADS=4
fi

ROOT="/dev/mapper/root"
CRYPT_ROOT="$(blkid -s UUID | grep $ROOT_DEVICE | cut -d' ' -f2 | sed 's/"//g')"
BOOT_PARAMS="ro crypt_root=$CRYPT_ROOT root=$ROOT rootfsype=btrfs rootflags=subvol=@ root_trim=yes lsm=selinux"

echo -e "Boot parameters:\n$BOOT_PARAMS\n"
echo -e "\"lsblk -f\" output:\n$(lsblk -f)\n"
echo -e "Kernel image will compiled with $THREADS threads and be installed to $KERNEL_DIR\n"

if [[ $(/usr/bin/id -u) -ne 0 ]]; then
	echo "Cannot proceed, need root permissions"
	exit 1
fi

echo "Proceed with kernel compiling?[Y/N]"
read answer
if [ "$answer" != "${answer#[Nn]}" ] ;then
	echo "Aborted"
	exit 1
fi

echo "Starting compilation. Asking for root permissions."
#exit 1

cd /usr/src/linux

# inject $BOOT_PARAMS into kernel
sed -i "s|^\(CONFIG_CMDLINE=\).*|\1\"$BOOT_PARAMS\"|" .config

genkernel --no-clean --no-mrproper --no-save-config \
	--microcode="$MICROCODE" \
	--integrated-initramfs --compress-initramfs --compress-initramfs-type=lz4 \
	--luks --no-zfs \
	--btrfs \
	--kernel-config=/usr/src/linux/.config \
	--kernel-filename="$KERNEL_NAME" \
	--makeopts="-j$THREADS" \
	--loglevel=3 \
	all
	#--virtio \

echo "Signing image"
sbsign --key "$KEYDIR/db.key" --cert "$KEYDIR/db.crt" -o "$KERNEL_DIR/$KERNEL_NAME.efi" "/boot/$KERNEL_NAME"

cd -