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] |
---|
12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
13 | source $Work_Path/functions_drbl_virt |
---|
14 | |
---|
15 | # [Main] |
---|
16 | |
---|
17 | # = 1. Patch DRBL xen env for client = |
---|
18 | # == Shutdown all drbl client == |
---|
19 | echo "Please check all client are shutdown !!!" |
---|
20 | echo "you can use /opt/drbl/sbin/dcs to shutdown." |
---|
21 | read -p "Push 'Enter' to continue......" |
---|
22 | |
---|
23 | # == Change xen kernel for drbl client == |
---|
24 | check_xen_nu |
---|
25 | Xen_Kernel=$(echo $Xen_Kernel | sed 's/^vmlinuz-//g' ) |
---|
26 | echo $Xen_Kernel > $Work_Home/etc/Xen_Kernel |
---|
27 | # == Copy xen image to /tftpboot/nbi_img/ == |
---|
28 | echo "copy Xen image & Kernel to /tftpboot/nbi_img/" |
---|
29 | cp /boot/*xen* /tftpboot/nbi_img/ |
---|
30 | cp /boot/vmlinuz-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
31 | cp /boot/initrd.img-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
32 | cp /boot/config-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
33 | echo "" |
---|
34 | |
---|
35 | # == Modify PXE booting menu == |
---|
36 | # if menu doesn't has drbl-virt, then add it |
---|
37 | cat /opt/drbl/sbin/generate-pxe-menu | grep "label drbl-virt" >> /dev/null |
---|
38 | if [ $? != 0 ]; then |
---|
39 | # backup generate-pxe-menu |
---|
40 | cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak |
---|
41 | cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak |
---|
42 | |
---|
43 | generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu" |
---|
44 | declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}') |
---|
45 | # delete default |
---|
46 | sed -i 's/^ MENU DEFAULT/ # MENU DEFAULT/g' $generate_PXE_menu |
---|
47 | # modify menu |
---|
48 | sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu |
---|
49 | modify_line=$modify_line+1 |
---|
50 | sed -i "${modify_line}i\ MENU DEFAULT" $generate_PXE_menu |
---|
51 | modify_line=$modify_line+1 |
---|
52 | sed -i "${modify_line}i\ # MENU HIDE" $generate_PXE_menu |
---|
53 | modify_line=$modify_line+1 |
---|
54 | sed -i "${modify_line}i\ MENU LABEL DRBL-Virtualization ($Xen, $Xen_Kernel)" $generate_PXE_menu |
---|
55 | modify_line=$modify_line+1 |
---|
56 | sed -i "${modify_line}i\ kernel mboot.c32" $generate_PXE_menu |
---|
57 | modify_line=$modify_line+1 |
---|
58 | sed -i "${modify_line}i\ append $Xen --- vmlinuz-pxe --- initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu |
---|
59 | modify_line=$modify_line+1 |
---|
60 | sed -i "${modify_line}i\ TEXT HELP" $generate_PXE_menu |
---|
61 | modify_line=$modify_line+1 |
---|
62 | sed -i "${modify_line}i\ ENDTEXT" $generate_PXE_menu |
---|
63 | modify_line=$modify_line+1 |
---|
64 | sed -i "${modify_line}i\ " $generate_PXE_menu |
---|
65 | fi |
---|
66 | |
---|
67 | # = 2. Patch DRBL initrd to support bridge = |
---|
68 | # == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules == |
---|
69 | # backup mkpxeinitrd-net. if already has "drbl-virt add", dones't sed |
---|
70 | cat /usr/bin/mkpxeinitrd-net | grep "# drbl-virt add" >> /dev/null |
---|
71 | if [ $? != 0 ]; then |
---|
72 | cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak |
---|
73 | # copy Xen network scripts |
---|
74 | cp /etc/xen/scripts/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
75 | cp /etc/xen/scripts/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
76 | cp /etc/xen/scripts/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
77 | # patch it to copy command |
---|
78 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}') |
---|
79 | modify_file="/usr/bin/mkpxeinitrd-net" |
---|
80 | sed -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 |
---|
81 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
82 | # patch it to copy modules |
---|
83 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}') |
---|
84 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
85 | modify_line=$modify_line+1 |
---|
86 | sed -i "${modify_line}icp -a --parents kernel/net/bridge/bridge.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
87 | modify_line=$modify_line+1 |
---|
88 | sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
89 | |
---|
90 | # == Add start_xen_bridge.sh to run Xen network-bridge (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) == |
---|
91 | cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh |
---|
92 | #!/bin/bash |
---|
93 | # drbl-virt add |
---|
94 | NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}') |
---|
95 | declare -i NICs_nu=\$(echo \$NICs |wc -l) |
---|
96 | NIC="" |
---|
97 | |
---|
98 | if [ \$NICs_nu -lt 1 ]; then |
---|
99 | for (( i=0 ; i<\$NICs_nu ; i++ )) |
---|
100 | do |
---|
101 | NIC_IP=\$(ifconfig eth\${i} | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g') |
---|
102 | if [ -n \$NIC_IP ]; then |
---|
103 | NIC="eth\${i}" |
---|
104 | break |
---|
105 | fi |
---|
106 | done |
---|
107 | else |
---|
108 | NIC=\$NICS |
---|
109 | fi |
---|
110 | |
---|
111 | bash /bin/network-bridge start netdev=\$NIC |
---|
112 | EOF |
---|
113 | fi |
---|
114 | # == Run start_xen_bridge.sh when booting == |
---|
115 | cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_xen_bridge.sh" >> /dev/null |
---|
116 | if [ $? != 0 ]; then |
---|
117 | # backup linuxrc-or-init |
---|
118 | cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak |
---|
119 | declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}') |
---|
120 | modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init" |
---|
121 | |
---|
122 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
123 | modify_line=$modify_line+1 |
---|
124 | sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file |
---|
125 | fi |
---|
126 | |
---|
127 | |
---|
128 | # = 3. enable xend xendomains daemon in DRBL Client = |
---|
129 | if [ -e /opt/drbl/conf/client-extra-service ]; then |
---|
130 | echo 'service_extra_added="xend xendomains"' >> /opt/drbl/conf/client-extra-service |
---|
131 | else |
---|
132 | echo 'service_extra_added="xend xendomains"' > /opt/drbl/conf/client-extra-service |
---|
133 | fi |
---|
134 | |
---|
135 | # = 4. enable xend xendomains daemon afterr drblpush = |
---|
136 | # /opt/drbl/sbin/drbl-client-service xend on |
---|
137 | |
---|
138 | # = 5. cp xen kernel & initrd to /home/domains = |
---|
139 | if [ ! -e /home/domains ]; then |
---|
140 | mkdir /home/domains |
---|
141 | fi |
---|
142 | cp /tftpboot/nbi_img/*xen* /home/domains |
---|
143 | cp /tftpboot/nbi_img/vmlinuz-pxe /home/domains |
---|
144 | cp /tftpboot/nbi_img/initrd-pxe.img /home/domains |
---|
145 | |
---|