use full address for pdu00
[ktest-util.git] / vzt-kernel-install
blobb7563634672843b11c84de35f8581b53a3a8582d
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 || exit 1
93 scp modules-$krel.tar.gz root@$host:/tmp || exit 1
94 SSH root@$host "rm \-rf /lib/modules/$krel " || exit 1
95 SSH root@$host " tar zxf /tmp/modules-$krel.tar.gz -C / "|| exit 1
96 SSH root@$host "mkinitrd \-f /boot/initrd-$krel.img $krel $MKINITRD_OPT" || exit 1
97 rm -f modules-$krel.tar.gz
98 mkinitrd=n
101 ##### pxe boot #####
102 if [ $boot_proto == "pxe" ] ;then
103 echo "$BOOT_OPTS" | egrep "[^[:space:]]+"
104 if [ $? -ne 0 ];then
105 echo "Err: 'BOOT_OPTS' is empty. You must specify correct boot options"
106 exit 1
108 cp arch/$ARCH/boot/bzImage vmlinuz-$krel || exit 1
109 vmlinuz-$krel root@$PXE_SERVER:/$PXE_ROOT/$PXE_KERNEL_DIR/vmlinuz-$krel \
110 || exit 1
111 rm -f vmlinuz-$krel || exit 1
112 SSH root@$PXE_SERVER " chmod 0444 /$PXE_ROOT/$PXE_KERNEL_DIR/vmlinuz-$krel"
113 if [ $mkinitrd == "y" ]; then
114 echo "Using initrd from different host is realy errorprone way."
115 echo "kernel probably can't boot with this initrd image"
116 scp initrd-$krel.img root@$PXE_SERVER:/$PXE_ROOT/$PXE_KERNEL_DIR || exit 1
117 SSH root@$PXE_SERVER " chmod 0444 /$PXE_ROOT/$PXE_KERNEL_DIR/initrd-$krel.img "
119 SSH root@$PXE_SERVER " vzt-pxe-boot $host add vmlinuz-$krel initrd-$krel.img '$BOOT_OPTS' $title"
120 exit $?
123 function grub_setup
125 host=$1
126 shift
127 kernel_img=$1
128 shift
129 initrd_img=$1
130 shift
131 title_text=$1
132 shift
133 boot_opt=$@
135 ssh root@${host} test /boot/${kernel_img} || {
136 cho "Kernel image : /boot/${kernel_img} not found";
137 exit 1;
140 ssh root@${host} test /boot/${initrd_img} || {
141 echo "initrd image :/boot/${initrd_img} not found" ;
142 exit 1;
145 if [ -z "$boot_opt" ]; then
146 args=--copy-default
147 else
148 args='--args=$boot_opt'
150 ssh root@${host} grubby --remove-kernel=/boot/${kernel_img} \
151 --add-kernel=/boot/${kernel_img} \
152 --initrd=/boot/${initrd_img} \
153 $args --title="${title_text}" \
154 --make-default
155 ret=$?
156 if [ $ret -ne 0 ] ;then
157 echo "Error while grub setup"
158 else
159 echo "grub setup OK"
161 return $ret
165 ##### local boot #####
166 if [ $boot_proto == "local" ]; then
167 cp arch/$ARCH/boot/bzImage vmlinuz-$krel || exit
168 scp vmlinuz-$krel root@$host:/boot/vmlinuz-$krel || exit 1
169 rm -f vmlinuz-$krel || exit 1
170 if [ $mkinitrd == "y" ]; then
171 SSH root@$host "mkinitrd \-f /boot/initrd-$krel.img $krel $MKINITRD_OPT" || exit 1
173 grub_setup $host vmlinuz-$krel initrd-$krel.img $title $BOOT_OPTS \
174 #SSH root@$host " ls -l "
175 exit $?
177 #################
178 echo "Bad boot protocol" ;
179 exit 1