1 | #!/bin/bash |
---|
2 | # Program: |
---|
3 | # Patch DRBL to bridge eth in booting (KVM) |
---|
4 | # Author: |
---|
5 | # Jazz, Rock {jazz, rock}@nchc.org.tw |
---|
6 | # Version: |
---|
7 | # 1.0 |
---|
8 | # History: |
---|
9 | # 2010/10/12 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 initrd to support bridge = |
---|
18 | # == Patch /usr/bin/mkpxeinitrd-net == |
---|
19 | # backup mkpxeinitrd-net. if already has "drbl-virt add", doesn't sed |
---|
20 | cat /usr/bin/mkpxeinitrd-net | grep "# drbl-virt add" >> /dev/null |
---|
21 | if [ $? != 0 ]; then |
---|
22 | cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak |
---|
23 | # copy Xen network scripts |
---|
24 | cp $Work_Home/conf/initrd_bin/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
25 | cp $Work_Home/conf/initrd_bin/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
26 | cp $Work_Home/conf/initrd_bin/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
27 | |
---|
28 | # patch it to copy command |
---|
29 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}') |
---|
30 | modify_file="/usr/bin/mkpxeinitrd-net" |
---|
31 | 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 |
---|
32 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
33 | # patch it to copy modules |
---|
34 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}') |
---|
35 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
36 | modify_line=$modify_line+1 |
---|
37 | sed -i "${modify_line}icp -a --parents kernel/net/bridge/bridge.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
38 | |
---|
39 | # == Add start_kvm_bridge.sh (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) == |
---|
40 | cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_kvm_bridge.sh |
---|
41 | #!/bin/bash |
---|
42 | # drbl-virt add |
---|
43 | NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}') |
---|
44 | declare -i NICs_nu=\$(echo \$NICs |wc -w) |
---|
45 | |
---|
46 | for NIC in \$NICs |
---|
47 | do |
---|
48 | NIC_IP=\$(ifconfig \$NIC | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g' | sed 's/^[ ]*//') |
---|
49 | |
---|
50 | if [ -n \$NIC_IP ]; then |
---|
51 | break |
---|
52 | fi |
---|
53 | done |
---|
54 | |
---|
55 | # add bridge to eth |
---|
56 | bash /bin/network-bridge start netdev=\$NIC |
---|
57 | EOF |
---|
58 | fi |
---|
59 | # == Run start_kvm_bridge.sh when booting == |
---|
60 | cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_kvm_bridge.sh" >> /dev/null |
---|
61 | if [ $? != 0 ]; then |
---|
62 | # backup linuxrc-or-init |
---|
63 | cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak |
---|
64 | declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}') |
---|
65 | modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init" |
---|
66 | |
---|
67 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
68 | modify_line=$modify_line+1 |
---|
69 | sed -i "${modify_line}ibash /bin/start_kvm_bridge.sh" $modify_file |
---|
70 | fi |
---|