source: drbl-virt/sbin/drbl_bridge_xen_patch @ 225

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

Add: KVM PXE VM deployment

  • Property svn:executable set to *
File size: 3.3 KB
RevLine 
[209]1#!/bin/bash
2# Program:
[217]3#   Patch DRBL to bridge eth in booting (Xen)
[209]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 (1)Xen network scripts (2)command (3)modules ==
[217]19# backup mkpxeinitrd-net. if already has "drbl-virt add", doesn't sed
[209]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
[218]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/
[219]27
[209]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
38modify_line=$modify_line+1
39sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file
40
41# == Add start_xen_bridge.sh to run Xen network-bridge (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) ==
42cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh
43#!/bin/bash
44# drbl-virt add
45NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}')
[217]46declare -i NICs_nu=\$(echo \$NICs |wc -w)
[209]47NIC=""
48
49if [ \$NICs_nu -lt 1  ]; then
50    for (( i=0 ; i<\$NICs_nu ; i++ ))
51    do
[217]52        NIC_IP=\$(ifconfig eth\${i} | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g' | sed 's/^[ ]*//')
[209]53        if [ -n \$NIC_IP ]; then
54            NIC="eth\${i}"
55            break
56        fi
57    done
58else
59    NIC=\$NICS
60fi
61
62bash /bin/network-bridge start netdev=\$NIC
63EOF
64fi
65# == Run start_xen_bridge.sh when booting  ==
66cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_xen_bridge.sh" >> /dev/null
67if [ $? != 0 ]; then
68    # backup linuxrc-or-init
69    cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak
70    declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}')
71    modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init"
72
73    sed -i "${modify_line}i# drbl-virt add" $modify_file
74    modify_line=$modify_line+1
75    sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file
76fi
Note: See TracBrowser for help on using the repository browser.