[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] |
---|
| 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 (1)Xen network scripts (2)command (3)modules == |
---|
[217] | 19 | # backup mkpxeinitrd-net. if already has "drbl-virt add", doesn't sed |
---|
[209] | 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 |
---|
[218] | 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/ |
---|
[219] | 27 | |
---|
[209] | 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 | modify_line=$modify_line+1 |
---|
| 39 | sed -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) == |
---|
| 42 | cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh |
---|
| 43 | #!/bin/bash |
---|
| 44 | # drbl-virt add |
---|
| 45 | NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}') |
---|
[217] | 46 | declare -i NICs_nu=\$(echo \$NICs |wc -w) |
---|
[209] | 47 | NIC="" |
---|
| 48 | |
---|
| 49 | if [ \$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 |
---|
| 58 | else |
---|
| 59 | NIC=\$NICS |
---|
| 60 | fi |
---|
| 61 | |
---|
| 62 | bash /bin/network-bridge start netdev=\$NIC |
---|
| 63 | EOF |
---|
| 64 | fi |
---|
| 65 | # == Run start_xen_bridge.sh when booting == |
---|
| 66 | cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_xen_bridge.sh" >> /dev/null |
---|
| 67 | if [ $? != 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 |
---|
| 76 | fi |
---|