add on/off commands
[ktest-util.git] / vzt-kernel-install
blobcb98265f4d3f732ae0ad6aaabbfa8f89ce7fbf57
1 #!/bin/bash
2 # Install kernel to test host
3 CONFIG=.vzt/kernel-install.cfg
4 function show_usage
6 echo "$0: <host> [OPTS]"
7 echo "Usage:"
8 echo "Install kernele to test host via ssh or pxe"
9 echo "Examples:"
10 echo "Install kernel, modules and initrd to host via \
11 ssh and setup local boot loader"
12 echo " $0 my_host.org --all"
13 echo "Install kernel only via ssh and setup local boot loader"
14 echo " $0 my_host.org "
15 echo "Install kernel and setup pxe boot loader"
16 echo " $0 my_host --pxe"
17 echo "Disable pxe boot for host"
18 echo " $0 my_host --pxe --disable"
22 if [ ! -f "$CONFIG" ]; then
23 echo "Cant find .vzt/kernel-install.cfg"
24 echo "you may use example config:"
25 echo " mkdir .vzt; cp /etc/vzt/kernel-install.cfg.example \
26 .vzt/kernel-install.cfg "
27 exit
29 . $CONFIG
30 krel=`make kernelrelease`
32 if [ ! $? -eq 0 ]; then
33 echo "Can't get kernel release version"
34 echo "This is probably happend CWD is wrong."
35 echo "do: cd /your/path/to/kernel/linux-tree/"
36 show_usage
37 exit 1
39 function SSH
41 ssh -n -oStrictHostKeyChecking=no -oBatchMode=yes $@
42 return $?
45 host="${1}"
46 shift
47 if [ -z "$host" ] ;then
48 echo "Err: Bad arguments"
49 show_usage
50 exit 1
52 boot_proto=local
53 modules=n
54 mkinitrd=n
55 if [ "$1" = "--pxe" ]; then
56 boot_proto="pxe"
57 shift
60 if [ "$1" = "--all" ]; then
61 modules=y
62 mkinitrd=y
63 shift
66 if [ "$1" = "--suffix" ]; then
67 shift
68 krel=${krel}-${1}
69 shift
72 if [ "$1" = "--initrd" ]; then
73 mkinitrd=y
74 shift
77 if [ "$1" = "--disable" ]; then
78 if [ "$boot_proto" = "pxe" ]; then
79 SSH root@$PXE_SERVER " vzt-pxe-boot $host del"
80 exit $?
81 else
82 echo "ERR: --disable option valid only for pxe boot mode"
83 exit 1
87 title="kernel-$krel"
88 echo "Install kernel to $server via protocol: $boot_proto"
90 if [ $modules == "y" ]; then
91 make modules_install || exit 1;
92 tar zcf modules-$krel.tar.gz /lib/modules/$krel \
93 --exclude /lib/modules/$krel/build \
94 --exclude /lib/modules/$krel/source || exit 1
95 scp modules-$krel.tar.gz root@$host:/tmp || exit 1
96 SSH root@$host "rm \-rf /lib/modules/$krel " || exit 1
97 SSH root@$host " tar mzxf /tmp/modules-$krel.tar.gz -C / "|| exit 1
98 SSH root@$host "mkinitrd \-f /boot/initrd-$krel.img $krel $MKINITRD_OPT" || exit 1
99 SSH root@$host " wall 'modules was intalled to /lib/modules/$krel'"
100 rm -f modules-$krel.tar.gz
101 mkinitrd=n
104 ##### pxe boot #####
105 if [ $boot_proto == "pxe" ] ;then
106 echo "$BOOT_OPTS" | egrep "[^[:space:]]+"
107 if [ $? -ne 0 ];then
108 echo "Err: 'BOOT_OPTS' is empty. You must specify correct boot options"
109 exit 1
111 cp arch/$ARCH/boot/bzImage vmlinuz-$krel || exit 1
112 vmlinuz-$krel root@$PXE_SERVER:/$PXE_ROOT/$PXE_KERNEL_DIR/vmlinuz-$krel \
113 || exit 1
114 rm -f vmlinuz-$krel || exit 1
115 SSH root@$PXE_SERVER " chmod 0444 /$PXE_ROOT/$PXE_KERNEL_DIR/vmlinuz-$krel"
116 if [ $mkinitrd == "y" ]; then
117 echo "Using initrd from different host is realy errorprone way."
118 echo "kernel probably can't boot with this initrd image"
119 scp initrd-$krel.img root@$PXE_SERVER:/$PXE_ROOT/$PXE_KERNEL_DIR || exit 1
120 SSH root@$PXE_SERVER " chmod 0444 /$PXE_ROOT/$PXE_KERNEL_DIR/initrd-$krel.img "
122 SSH root@$PXE_SERVER " vzt-pxe-boot $host add vmlinuz-$krel initrd-$krel.img '$BOOT_OPTS' $title"
123 exit $?
126 function grub_setup
128 host=$1
129 shift
130 kernel_img=$1
131 shift
132 initrd_img=$1
133 shift
134 title_text=$1
135 shift
136 boot_opt=$@
138 ssh root@${host} test /boot/${kernel_img} || {
139 cho "Kernel image : /boot/${kernel_img} not found";
140 exit 1;
143 ssh root@${host} test /boot/${initrd_img} || {
144 echo "initrd image :/boot/${initrd_img} not found" ;
145 exit 1;
148 if [ -z "$boot_opt" ]; then
149 args=--copy-default
150 else
151 args='--args=$boot_opt'
153 SSH root@${host} grubby --remove-kernel=/boot/${kernel_img} \
154 --add-kernel=/boot/${kernel_img} \
155 --initrd=/boot/${initrd_img} \
156 $args --title="${title_text}"
157 ret=$?
158 if [ $ret -ne 0 ] ;then
159 echo "Error while grub setup"
160 else
161 echo "savedefault --default=0 --once" | \
162 ssh root@$host "grub --batch"
163 SSH root@$host " wall 'grub: savedefault --default=/boot/\
164 ${kernel_img} --once'"
165 echo "grub setup OK"
167 return $ret
171 ##### local boot #####
172 if [ $boot_proto == "local" ]; then
173 cp arch/$ARCH/boot/bzImage vmlinuz-$krel || exit
174 scp vmlinuz-$krel root@$host:/boot/vmlinuz-$krel || exit 1
175 rm -f vmlinuz-$krel || exit 1
176 #system.map setup
177 scp System.map root@$host:/boot/System.map-$krel || exit 1
178 SSH root@$host "rm -rf /boot/System.map" || exit 1
179 SSH root@$host "ln -s /boot/System.map-$krel /boot/System.map"
181 SSH root@$host "wall 'new kernel was intalled to /boot/vmlinuz-$krel'"
182 if [ $mkinitrd == "y" ]; then
183 SSH root@$host "mkinitrd \-f /boot/initrd-$krel.img $krel $MKINITRD_OPT" || exit 1
185 grub_setup $host vmlinuz-$krel initrd-$krel.img $title $BOOT_OPTS \
186 #SSH root@$host " ls -l "
187 exit $?
189 #################
190 echo "Bad boot protocol" ;
191 exit 1