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] |
---|
12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
13 | source $Work_Path/functions_drbl_virt |
---|
14 | |
---|
15 | # [Main] |
---|
16 | # = 1. Patch DRBL xen env for client = |
---|
17 | # == Shutdown all drbl client == |
---|
18 | echo -e "\nPlease shutdown all drbl client !!!" |
---|
19 | echo "You can use /opt/drbl/sbin/dcs to shutdown." |
---|
20 | read -p "Push [Enter] to continue......" |
---|
21 | |
---|
22 | # == check KVM Kernel version |
---|
23 | check_kvm |
---|
24 | echo $KVM_Kernel > $Work_Home/etc/KVM_Kernel |
---|
25 | |
---|
26 | # == Modify PXE booting menu == |
---|
27 | # if menu doesn't has drbl-virt, then add it |
---|
28 | cat /opt/drbl/sbin/generate-pxe-menu | grep "label drbl-virt" >> /dev/null |
---|
29 | if [ $? != 0 ]; then |
---|
30 | # backup generate-pxe-menu |
---|
31 | cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak |
---|
32 | cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak |
---|
33 | |
---|
34 | generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu" |
---|
35 | declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}') |
---|
36 | # delete default |
---|
37 | sed -i 's/^ MENU DEFAULT/ # MENU DEFAULT/g' $generate_PXE_menu |
---|
38 | # modify menu |
---|
39 | sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu |
---|
40 | modify_line=$modify_line+1 |
---|
41 | sed -i "${modify_line}i\ MENU DEFAULT" $generate_PXE_menu |
---|
42 | modify_line=$modify_line+1 |
---|
43 | sed -i "${modify_line}i\ # MENU HIDE" $generate_PXE_menu |
---|
44 | modify_line=$modify_line+1 |
---|
45 | sed -i "${modify_line}i\ MENU LABEL DRBL-Virtualization (KVM $KVM_Kernel)" $generate_PXE_menu |
---|
46 | modify_line=$modify_line+1 |
---|
47 | sed -i "${modify_line}i\ kernel vmlinuz-pxe" $generate_PXE_menu |
---|
48 | modify_line=$modify_line+1 |
---|
49 | sed -i "${modify_line}i\ append initrd=initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu |
---|
50 | modify_line=$modify_line+1 |
---|
51 | sed -i "${modify_line}i\ TEXT HELP" $generate_PXE_menu |
---|
52 | modify_line=$modify_line+1 |
---|
53 | sed -i "${modify_line}i\ ENDTEXT" $generate_PXE_menu |
---|
54 | modify_line=$modify_line+1 |
---|
55 | sed -i "${modify_line}i\ " $generate_PXE_menu |
---|
56 | fi |
---|
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 |
---|
62 | source $Work_Path/drbl_bridge_kvm_patch |
---|
63 | |
---|
64 | |
---|
65 | # = 3. Load KVM module when booting = |
---|
66 | if [ -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 |
---|
71 | else |
---|
72 | echo 'service_extra_added="kvm"' > /opt/drbl/conf/client-extra-service |
---|
73 | fi |
---|
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 = |
---|
99 | if [ ! -e /home/domains ]; then |
---|
100 | mkdir /home/domains |
---|
101 | fi |
---|
102 | cp /tftpboot/nbi_img/vmlinuz-pxe /home/domains |
---|
103 | cp /tftpboot/nbi_img/initrd-pxe.img /home/domains |
---|
104 | |
---|
105 | |
---|