summaryrefslogtreecommitdiffstats
path: root/install_kernel.bonham
blob: b7958e02f6605dd1dd3e131f1d1449668f7bed55 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash

function die()
{
	echo " (EE) $1"
	exit 1
}

function info()
{
	echo " (II) $1"
}

function silent()
{
	OUTPUT=`$*`
	if [ "$?" != "0" ]; then
		echo $OUTPUT
		die "$* failed!"
	fi
}

# Function to grab var from src
function getvar() {
  old=$(head -5 Makefile | grep "^$1")
  echo $(echo ${old/"$1 ="/} | sed -e "s/[ ]*\(.*\)[ ]*/\1/g")
  return 0
}

if [ ! -f "./.config" ]; then
	CURDIR=`pwd`
	die "No kernel .config exists in $CURDIR!"
fi

if [ ! -f "./Makefile" ]; then
	die "No Makefile present!"
fi

VERSION=`getvar VERSION`
PATCHLEVEL=`getvar PATCHLEVEL`
SUBLEVEL=`getvar SUBLEVEL`
EXTRAVERSION=`getvar EXTRAVERSION`

. ./.config

NAME="$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION$CONFIG_LOCALVERSION"

info "Detected kernel version $NAME"

if [ $UID != "0" ]; then
	die "Must be root to install kernel!"
fi

# (1) copy modules
if [ "$1" != "-m" ]; then
	info "Installing modules..."
	silent make -j32 modules_install
else
	info "Skipping installing modules."
fi

# (2) copy kernel
info "Installing kernel..."
silent cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-$NAME
silent cp -v System.map             /boot/System.map-$NAME

# (3) build ramdisk
info "Building module dependencies"
silent depmod -v $NAME

if [ "$1" != "-m" ]; then
	info "Building initial ramdisk..."
	silent update-initramfs -c -k $NAME
else
	info "Skipping updating initial ramdisk..."
fi

# (4) make bootloader entry
ALREADY_PRESENT=`grep "/vmlinuz-$NAME" /etc/grub.d/15_litmus `

if [ ! -z "$ALREADY_PRESENT" ]; then
	info "Bootloader entry appears to be already present."
else
	info "Creating bootloader entry..."

	if [[ "$NAME" =~ "litmus" ]]; then
		cat >> /etc/grub.d/15_litmus <<__EOE__

menuentry 'Ubuntu/Litmus, with $NAME' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set 08b4e70f-d536-45bc-8693-164891c8834b
        linux   /vmlinuz-$NAME root=/dev/sda5 ro quanta=aligned
        initrd  /initrd.img-$NAME
}
__EOE__
	else
		cat >> /etc/grub.d/15_litmus <<__EOE__

menuentry 'Ubuntu/Custom Kernel, with $NAME' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod ext2
        set root='(hd0,3)'
        search --no-floppy --fs-uuid --set 08b4e70f-d536-45bc-8693-164891c8834b
        linux   /vmlinuz-$NAME root=/dev/sda5 ro
        initrd  /initrd.img-$NAME
}
__EOE__
	fi

update-grub

fi

info "Kernel $NAME has been installed."