source: drbl-virt/sbin/drbl_xen_patch.sh @ 182

Last change on this file since 182 was 178, checked in by rock, 14 years ago

Add: (1)client xend enabled (2)setup VM IP range

  • Property svn:executable set to *
File size: 5.5 KB
Line 
1#!/bin/bash
2# Program:
3#   Path DRBL evironment to support Xen/KVM
4# Author:
5#   Jazz, Rock {jazz, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:                                                                                         
9#   2010/07/20  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
17# = 1. Patch DRBL xen env for client =
18# == Shutdown all drbl client ==
19echo "Please check all client are shutdown !!!"
20read -p "Push 'Enter' to continue......"
21
22# == Change xen kernel for drbl client ==
23check_xen_nu
24Xen_Kernel=$(echo $Xen_Kernel | sed 's/^vmlinuz-//g' )
25
26# == Copy xen image to /tftpboot/nbi_img/ ==
27echo "copy Xen image & Kernel to /tftpboot/nbi_img/"
28cp /boot/*xen* /tftpboot/nbi_img/
29cp /boot/vmlinuz-${Xen_Kernel} /tftpboot/nbi_img/
30cp /boot/initrd.img-${Xen_Kernel} /tftpboot/nbi_img/
31cp /boot/config-${Xen_Kernel} /tftpboot/nbi_img/
32echo ""
33
34# == Modify PXE booting menu ==
35# backup generate-pxe-menu
36cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak
37cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak
38generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu"
39declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}')
40# delete default
41sed -i 's/^  MENU DEFAULT/  # MENU DEFAULT/d' $generate_PXE_menu
42# modify menu
43sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu
44modify_line=$modify_line+1
45sed -i "${modify_line}i\  MENU DEFAULT" $generate_PXE_menu
46modify_line=$modify_line+1
47sed -i "${modify_line}i\  # MENU HIDE" $generate_PXE_menu
48modify_line=$modify_line+1
49sed -i "${modify_line}i\  MENU LABEL DRBL-Virtualization ($Xen, $Xen_Kernel)" $generate_PXE_menu
50modify_line=$modify_line+1
51sed -i "${modify_line}i\  kernel mboot.c32" $generate_PXE_menu
52modify_line=$modify_line+1
53sed -i "${modify_line}i\  append $Xen --- vmlinuz-pxe --- initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu
54modify_line=$modify_line+1
55sed -i "${modify_line}i\  TEXT HELP" $generate_PXE_menu
56modify_line=$modify_line+1
57sed -i "${modify_line}i\  ENDTEXT" $generate_PXE_menu
58modify_line=$modify_line+1
59sed -i "${modify_line}i\ " $generate_PXE_menu
60
61
62# = 2. Patch DRBL initrd to support bridge =
63# == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules ==
64# backup
65cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak
66# copy Xen network scripts
67cp /etc/xen/scripts/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
68cp /etc/xen/scripts/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
69cp /etc/xen/scripts/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
70# patch it to copy command
71declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}')
72modify_file="/usr/bin/mkpxeinitrd-net"
73sed -i "${modify_line}c\include_bin_prog_from_server='sleep lspci insmod modprobe rmmod lsmod pkill strings brctl ip egrep awk gawk seq fgrep dirname expr bash'" $modify_file
74sed -i "${modify_line}i# drbl-virt add" $modify_file
75# patch it to copy modules
76declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}')
77sed -i "${modify_line}i# drbl-virt add" $modify_file
78modify_line=$modify_line+1
79sed -i "${modify_line}icp -a --parents kernel/net/bridge/bridge.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file
80modify_line=$modify_line+1
81sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file
82
83# == Run Xen network-bridge in booting (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) ==
84cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh
85#!/bin/bash
86# drbl-virt add
87NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}')
88declare -i NICs_nu=\$(echo \$NICs |wc -l)
89NIC=""
90
91if [ \$NICs_nu -lt 1  ]; then
92    for (( i=0 ; i<\$NICs_nu ; i++ ))
93    do
94        NIC_IP=\$(ifconfig eth\${i} | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g')
95        if [ -n \$NIC_IP ]; then
96            NIC="eth\${i}"
97            break
98        fi
99    done
100else
101    NIC=\$NICS
102fi
103
104bash /bin/network-bridge start netdev=\$NIC
105EOF
106# backup
107cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak
108declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}')
109modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init"
110
111sed -i "${modify_line}i# drbl-virt add" $modify_file
112modify_line=$modify_line+1
113sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file
114
115# = 3. enable xend xendomains daemon in DRBL Client =
116if [ -e /opt/drbl/conf/client-extra-service ]; then
117    echo 'service_extra_added="xend xendomains"' >> /opt/drbl/conf/client-extra-service
118else
119    echo 'service_extra_added="xend xendomains"' > /opt/drbl/conf/client-extra-service
120fi
121
122# = 4. Re-deploy drbl client =
123# == Cheange Xen Kernel ==
124echo "/opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel"
125/opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel                                                                                                                       
126echo ""
127# == Re-delpoy drbl client ==
128echo "Re-delpoy drbl client"
129echo "/opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf"
130/opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf
131echo ""
132
133# = 5. enable xend xendomains daemon afterr drblpush =
134# /opt/drbl/sbin/drbl-client-service xend on
135
Note: See TracBrowser for help on using the repository browser.