[209] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
| 3 | # Path DRBL evironment to support Xen/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 (1)Xen network scripts (2)command (3)modules == |
---|
| 19 | # backup mkpxeinitrd-net. if already has "drbl-virt add", dones'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 /etc/xen/scripts/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 25 | cp /etc/xen/scripts/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 26 | cp /etc/xen/scripts/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 27 | # patch it to copy command |
---|
| 28 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}') |
---|
| 29 | modify_file="/usr/bin/mkpxeinitrd-net" |
---|
| 30 | 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 |
---|
| 31 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 32 | # patch it to copy modules |
---|
| 33 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}') |
---|
| 34 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 35 | modify_line=$modify_line+1 |
---|
| 36 | sed -i "${modify_line}icp -a --parents kernel/net/bridge/bridge.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
| 37 | modify_line=$modify_line+1 |
---|
| 38 | sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
| 39 | |
---|
| 40 | # == Add start_xen_bridge.sh to run Xen network-bridge (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) == |
---|
| 41 | cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh |
---|
| 42 | #!/bin/bash |
---|
| 43 | # drbl-virt add |
---|
| 44 | NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}') |
---|
| 45 | declare -i NICs_nu=\$(echo \$NICs |wc -l) |
---|
| 46 | NIC="" |
---|
| 47 | |
---|
| 48 | if [ \$NICs_nu -lt 1 ]; then |
---|
| 49 | for (( i=0 ; i<\$NICs_nu ; i++ )) |
---|
| 50 | do |
---|
| 51 | NIC_IP=\$(ifconfig eth\${i} | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g') |
---|
| 52 | if [ -n \$NIC_IP ]; then |
---|
| 53 | NIC="eth\${i}" |
---|
| 54 | break |
---|
| 55 | fi |
---|
| 56 | done |
---|
| 57 | else |
---|
| 58 | NIC=\$NICS |
---|
| 59 | fi |
---|
| 60 | |
---|
| 61 | bash /bin/network-bridge start netdev=\$NIC |
---|
| 62 | EOF |
---|
| 63 | fi |
---|
| 64 | # == Run start_xen_bridge.sh when booting == |
---|
| 65 | cat /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "bash /bin/start_xen_bridge.sh" >> /dev/null |
---|
| 66 | if [ $? != 0 ]; then |
---|
| 67 | # backup linuxrc-or-init |
---|
| 68 | cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak |
---|
| 69 | declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}') |
---|
| 70 | modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init" |
---|
| 71 | |
---|
| 72 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 73 | modify_line=$modify_line+1 |
---|
| 74 | sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file |
---|
| 75 | fi |
---|