source: drbl-virt/sbin/drbl_kvm_patch.sh @ 247

Last change on this file since 247 was 219, checked in by rock, 14 years ago

Add: KVM PXE VM deployment

  • Property svn:executable set to *
File size: 3.4 KB
Line 
1#!/bin/bash
2# Program:
3#   Path DRBL evironment to support KVM
4# Author:
5#   Jazz, Rock {jazz, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   2010/10/18  Rock    First release (1.0)
10
11# [Source]
12source /opt/drbl-virt/conf/drbl-virt.conf
13source $Work_Path/functions_drbl_virt
14
15# [Main]
16# = 1. Patch DRBL xen env for client =
17# == Shutdown all drbl client ==
18echo -e "\nPlease shutdown all drbl client !!!"
19echo "You can use /opt/drbl/sbin/dcs to shutdown."
20read -p "Push [Enter] to continue......"
21
22# == check KVM Kernel version
23check_kvm
24echo $KVM_Kernel > $Work_Home/etc/KVM_Kernel
25
26# == Modify PXE booting menu ==
27# if menu doesn't has drbl-virt, then add it
28cat /opt/drbl/sbin/generate-pxe-menu | grep "label drbl-virt" >> /dev/null
29if [  $? != 0 ]; then
30# backup generate-pxe-menu
31cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak
32cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak
33
34generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu"
35declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}')
36# delete default
37sed -i 's/^  MENU DEFAULT/  # MENU DEFAULT/g' $generate_PXE_menu
38# modify menu
39sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu
40modify_line=$modify_line+1
41sed -i "${modify_line}i\  MENU DEFAULT" $generate_PXE_menu
42modify_line=$modify_line+1
43sed -i "${modify_line}i\  # MENU HIDE" $generate_PXE_menu
44modify_line=$modify_line+1
45sed -i "${modify_line}i\  MENU LABEL DRBL-Virtualization (KVM $KVM_Kernel)" $generate_PXE_menu
46modify_line=$modify_line+1
47sed -i "${modify_line}i\  kernel vmlinuz-pxe" $generate_PXE_menu
48modify_line=$modify_line+1
49sed -i "${modify_line}i\  append  initrd=initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu
50modify_line=$modify_line+1
51sed -i "${modify_line}i\  TEXT HELP" $generate_PXE_menu
52modify_line=$modify_line+1
53sed -i "${modify_line}i\  ENDTEXT" $generate_PXE_menu
54modify_line=$modify_line+1
55sed -i "${modify_line}i\ " $generate_PXE_menu
56fi
57
58
59# = 2. Patch DRBL initrd to support bridge =
60# == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules ==
61# backup mkpxeinitrd-net. if already has "drbl-virt add", doesn't sed
62source $Work_Path/drbl_bridge_kvm_patch
63
64
65# = 3. Load KVM module when booting =
66if [ -e /opt/drbl/conf/client-extra-service ]; then
67    grep 'service_extra_added="kvm"' /opt/drbl/conf/client-extra-service
68    if [ $? -eq 1 ]; then
69        echo 'service_extra_added="kvm"' >> /opt/drbl/conf/client-extra-service
70    fi
71else
72    echo 'service_extra_added="kvm"' > /opt/drbl/conf/client-extra-service
73fi
74# for Debian & Ubuntu
75#if [ -e /etc/modules ]; then
76#    grep kvm /etc/modules
77#    if [ $? -eq 1 ]; then
78#       echo "kvm" >> /etc/modules
79#    fi
80# for CentOS & Fedora
81#elif [ -e /etc/sysconfig/modules ]; then
82#    grep -r "modprobe kvm" /etc/sysconfig/modules/
83#    if [ $? -eq 1 ]; then
84#        cat  > /etc/sysconfig/modules/kvm.modules << EOF
85##!/bin/sh                 
86#echo -n "Loading kvm module..."
87#if \$(/sbin/modprobe kvm)
88#    then
89#        echo "[SUCCESS]:"
90#    else
91#        echo "[FAILURE]:"
92#fi
93#EOF
94#    chmod +x /etc/sysconfig/modules/kvm.modules
95#    fi
96#fi
97
98# = 4. Copy xen kernel & initrd to /home/domains =
99if [ ! -e /home/domains ]; then
100    mkdir /home/domains
101fi
102cp /tftpboot/nbi_img/vmlinuz-pxe /home/domains
103cp /tftpboot/nbi_img/initrd-pxe.img /home/domains
104
105
Note: See TracBrowser for help on using the repository browser.