1 | #!/bin/bash |
---|
2 | # Program: |
---|
3 | # DRBL virt module |
---|
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 | # [Variable Declation] |
---|
12 | cpu_flag="no" |
---|
13 | Linux_bit="" |
---|
14 | Linux_Distribution="" |
---|
15 | Linux_Version="" |
---|
16 | VMM_select="" |
---|
17 | |
---|
18 | # [Check Root] |
---|
19 | function check_root(){ |
---|
20 | if [ $USER != "root" ]; then |
---|
21 | echo -e "Please change root to run it!" |
---|
22 | exit |
---|
23 | fi |
---|
24 | } |
---|
25 | |
---|
26 | function check_root_run(){ |
---|
27 | if [ $USER != "root" ]; then |
---|
28 | echo -e "Please change root to run it!" |
---|
29 | sudo su -c ~/"$0" "$@" |
---|
30 | exit |
---|
31 | fi |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | # [Check CPU support] |
---|
36 | function cpu_check(){ |
---|
37 | egrep '(vmx|svm)' --color=always /proc/cpuinfo > /dev/null |
---|
38 | if [ $? == 0 ]; then |
---|
39 | cpu_flag="yes" |
---|
40 | fi |
---|
41 | } |
---|
42 | |
---|
43 | # [Check System Version] |
---|
44 | function check_systemInfo(){ |
---|
45 | Linux_bit=$(uname -m) |
---|
46 | Linux_Distribution=$(lsb_release -i | awk '{print $3}') |
---|
47 | Linux_Version=$(lsb_release -r | awk '{print $2}') |
---|
48 | } |
---|
49 | |
---|
50 | # [Select Hypervisior(Xen/KVM)] |
---|
51 | function VMM_select(){ |
---|
52 | if [ $cpu_flag == "yes" ]; then |
---|
53 | while [ "$VMM_select" != "1" -a "$VMM_select" != "2" ] |
---|
54 | do |
---|
55 | read -p "Which VMM/Hypervisior will be used in DRBL (1)Xen (2)KVM: " VMM_select |
---|
56 | done |
---|
57 | if [ $VMM_select == "1" ]; then |
---|
58 | echo "Xen" > $Work_Home/.tmp/hypervisior |
---|
59 | else |
---|
60 | echo "KVM" > $Work_Home/.tmp/hypervisior |
---|
61 | fi |
---|
62 | else |
---|
63 | echo "Xen will be the only Hypervisior in your DRBL" |
---|
64 | echo -e "Because CPU don't support virtualization, it can't choose KVM to be the Hypervisior" |
---|
65 | echo "" |
---|
66 | VMM_select=1 |
---|
67 | echo "Xen" > $Work_Home/.tmp/hypervisior |
---|
68 | fi |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | # [Create drbl-virt path] |
---|
73 | function install_drbl-virt_dir(){ |
---|
74 | mkdir -p $Work_Home/.tmp |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | # [Check Hypervisior] |
---|
79 | function check_hypervisior(){ |
---|
80 | hypervisior=$(cat $Work_Home/.tmp/hypervisior) |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | # [Check Debian Xen package] |
---|
85 | function check_debian_xen(){ |
---|
86 | aptitude update |
---|
87 | check_debian_xen_pkg=$(aptitude search xen-linux-system) |
---|
88 | if [ -n $check_debian_xen_pkg ]; then |
---|
89 | check_debian_xen_pkg="yes" |
---|
90 | else |
---|
91 | check_debian_xen_pkg="no" |
---|
92 | fi |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | # [Check Xen kernel] |
---|
97 | function check_xen_nu(){ |
---|
98 | Kernels=$(ls /boot | grep vmlinuz) |
---|
99 | declare -i Kernels_nu=$(echo $Kernels | wc -w) |
---|
100 | Kernel_choose="" |
---|
101 | |
---|
102 | Xens=$(ls /boot | grep -i ^xen) |
---|
103 | declare -i Xen_nu=$(echo $Xen | wc -w) |
---|
104 | Xen_choose="" |
---|
105 | |
---|
106 | jude="no" |
---|
107 | |
---|
108 | while [ $jude != "yes" -a $jude != "y" ] |
---|
109 | do |
---|
110 | declare -i i=1 |
---|
111 | declare -i j=1 |
---|
112 | echo "" |
---|
113 | |
---|
114 | if [ $Kernels_nu -gt 1 ]; then |
---|
115 | for Kernel in $Kernels |
---|
116 | do |
---|
117 | echo "($i) $Kernel" |
---|
118 | i=i+1 |
---|
119 | done |
---|
120 | |
---|
121 | read -p "Xen Kenrel is (1/2/...): " Kernel_choose |
---|
122 | Xen_Kernel=$(echo $Kernels | cut -d " " -f${Kernel_choose}) |
---|
123 | |
---|
124 | else |
---|
125 | Xen_Kernel=$Kernels |
---|
126 | fi |
---|
127 | |
---|
128 | if [ $Xen_nu -gt 1 ]; then |
---|
129 | for Xen in $Xens |
---|
130 | do |
---|
131 | echo "($i) $Xen" |
---|
132 | j=j+1 |
---|
133 | done |
---|
134 | |
---|
135 | read -p "Xen is (1/2/...): " Xen_choose |
---|
136 | Xen=$(echo $Xens | cut -d " " -f${Xen_choose}) |
---|
137 | else |
---|
138 | Xen=$Xens |
---|
139 | fi |
---|
140 | |
---|
141 | read -p "Are you sure (yes/no): " jude |
---|
142 | done |
---|
143 | |
---|
144 | #echo "debug: Xen_Kernel=$Xen_Kernel" |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | function debain-lenny_xen_patch(){ |
---|
149 | echo xen.independent_wallclock=1 >> /etc/sysctl.conf |
---|
150 | echo loop max_loop=255 >> /etc/modules |
---|
151 | echo xenblktap >> /etc/modules |
---|
152 | ln -s /usr/lib/$/bin/tapdisk /usr/sbin |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | function get_Host_IP_range(){ |
---|
157 | cat /etc/drbl/IP_HOST_TABLE | sed "${Host_first_Line}p" |
---|
158 | cat /etc/drbl/IP_HOST_TABLE | sed "${Host_final_Line}p" |
---|
159 | declare -i Host_first_Line=$(cat -n /etc/drbl/IP_HOST_TABLE | grep "# Created by DRBL (drblpush), begin" | awk '{print $1}') |
---|
160 | Host_first_Line=$((${Host_first_Line}+1)) |
---|
161 | |
---|
162 | declare -i Host_final_Line=$(cat -n /etc/drbl/IP_HOST_TABLE | grep "# Created by DRBL (drblpush), end" | awk '{print $1}') |
---|
163 | Host_final_Line=$((${Host_final_Line}-1)) |
---|
164 | #echo "$Host_first_Line" |
---|
165 | #echo "$Host_final_Line" |
---|
166 | |
---|
167 | Host_first_IP=$(cat /etc/drbl/IP_HOST_TABLE | sed -n "${Host_first_Line}p"| awk '{print $1}') |
---|
168 | Host_final_IP=$(cat /etc/drbl/IP_HOST_TABLE | sed -n "${Host_final_Line}p"| awk '{print $1}') |
---|
169 | #echo $Host_first_IP |
---|
170 | #echo $Host_final_IP |
---|
171 | } |
---|
172 | |
---|
173 | function get_VM_IP_range(){ |
---|
174 | echo "" |
---|
175 | echo "Your drbl client IP range $Host_first_IP ~ $Host_final_IP" |
---|
176 | declare -i Host_final_IP_4=$(echo $Host_final_IP | cut -d "." -f4) |
---|
177 | Host_final_IP_4=$(($Host_final_IP_4+1)) |
---|
178 | VM_first_IP=$(echo $Host_final_IP | cut -d "." -f 1-3) |
---|
179 | VM_first_IP="${VM_first_IP}.${Host_final_IP_4}" |
---|
180 | echo "The VM IP Range will start from $VM_first_IP" |
---|
181 | while [ $jude != "yes" -a $jude != "y" ]; |
---|
182 | do |
---|
183 | read "Input your IP range for VM: " VM_IP_range |
---|
184 | done |
---|
185 | echo "VM_first_IP=$VM_first_IP" > $Work_Home/.tmp/IP_VM_TABLE |
---|
186 | echo "VM_IP_range=$VM_IP_range" >> $Work_Home/.tmp/IP_VM_TABLE |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | # [DRBL Check] |
---|
191 | |
---|
192 | |
---|
193 | |
---|