source: drbl-virt/sbin/drbl_bridge_kvm_patch @ 247

Last change on this file since 247 was 219, checked in by rock, 14 years ago

Add: KVM PXE VM deployment

  • Property svn:executable set to *
File size: 2.9 KB
Line 
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]
12source /opt/drbl-virt/conf/drbl-virt.conf
13source $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
20cat /usr/bin/mkpxeinitrd-net | grep "# drbl-virt add" >> /dev/null
21if [ $? != 0 ]; then
22cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak
23# copy Xen network scripts
24cp $Work_Home/conf/initrd_bin/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
25cp $Work_Home/conf/initrd_bin/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
26cp $Work_Home/conf/initrd_bin/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/
27
28# patch it to copy command
29declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}')
30modify_file="/usr/bin/mkpxeinitrd-net"
31sed -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
32sed -i "${modify_line}i# drbl-virt add" $modify_file
33# patch it to copy modules
34declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}')
35sed -i "${modify_line}i# drbl-virt add" $modify_file
36modify_line=$modify_line+1
37sed -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) ==
40cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_kvm_bridge.sh
41#!/bin/bash
42# drbl-virt add
43NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}')
44declare -i NICs_nu=\$(echo \$NICs |wc -w)
45 
46for NIC in \$NICs
47do
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
53done
54
55# add bridge to eth
56bash /bin/network-bridge start netdev=\$NIC
57EOF
58fi
59# == Run start_kvm_bridge.sh when booting  ==
60cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_kvm_bridge.sh" >> /dev/null
61if [ $? != 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
70fi
Note: See TracBrowser for help on using the repository browser.