[161] | 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/07/20 Rock First release (1.0) |
---|
| 10 | |
---|
| 11 | # [Source] |
---|
[171] | 12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
[175] | 13 | source $Work_Path/functions_drbl_virt |
---|
[161] | 14 | |
---|
| 15 | # [Main] |
---|
| 16 | |
---|
[171] | 17 | # = 1. Patch DRBL xen env for client = |
---|
| 18 | # == Shutdown all drbl client == |
---|
| 19 | echo "Please check all client are shutdown !!!" |
---|
| 20 | read -p "Push 'Enter' to continue......" |
---|
[161] | 21 | |
---|
[171] | 22 | # == Change xen kernel for drbl client == |
---|
| 23 | check_xen_nu |
---|
| 24 | Xen_Kernel=$(echo $Xen_Kernel | sed 's/^vmlinuz-//g' ) |
---|
[161] | 25 | |
---|
[171] | 26 | # == Copy xen image to /tftpboot/nbi_img/ == |
---|
| 27 | echo "copy Xen image & Kernel to /tftpboot/nbi_img/" |
---|
[174] | 28 | cp /boot/*xen* /tftpboot/nbi_img/ |
---|
| 29 | cp /boot/vmlinuz-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
| 30 | cp /boot/initrd.img-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
| 31 | cp /boot/config-${Xen_Kernel} /tftpboot/nbi_img/ |
---|
[171] | 32 | echo "" |
---|
| 33 | |
---|
| 34 | # == Modify PXE booting menu == |
---|
[173] | 35 | # backup generate-pxe-menu |
---|
[174] | 36 | cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak |
---|
| 37 | cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak |
---|
[173] | 38 | generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu" |
---|
| 39 | declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}') |
---|
[177] | 40 | # delete default |
---|
[178] | 41 | sed -i 's/^ MENU DEFAULT/ # MENU DEFAULT/d' $generate_PXE_menu |
---|
[173] | 42 | # modify menu |
---|
| 43 | sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu |
---|
| 44 | modify_line=$modify_line+1 |
---|
| 45 | sed -i "${modify_line}i\ MENU DEFAULT" $generate_PXE_menu |
---|
| 46 | modify_line=$modify_line+1 |
---|
[178] | 47 | sed -i "${modify_line}i\ # MENU HIDE" $generate_PXE_menu |
---|
| 48 | modify_line=$modify_line+1 |
---|
[173] | 49 | sed -i "${modify_line}i\ MENU LABEL DRBL-Virtualization ($Xen, $Xen_Kernel)" $generate_PXE_menu |
---|
| 50 | modify_line=$modify_line+1 |
---|
| 51 | sed -i "${modify_line}i\ kernel mboot.c32" $generate_PXE_menu |
---|
| 52 | modify_line=$modify_line+1 |
---|
| 53 | sed -i "${modify_line}i\ append $Xen --- vmlinuz-pxe --- initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu |
---|
| 54 | modify_line=$modify_line+1 |
---|
| 55 | sed -i "${modify_line}i\ TEXT HELP" $generate_PXE_menu |
---|
| 56 | modify_line=$modify_line+1 |
---|
| 57 | sed -i "${modify_line}i\ ENDTEXT" $generate_PXE_menu |
---|
| 58 | modify_line=$modify_line+1 |
---|
| 59 | sed -i "${modify_line}i\ " $generate_PXE_menu |
---|
[171] | 60 | |
---|
| 61 | |
---|
| 62 | # = 2. Patch DRBL initrd to support bridge = |
---|
[174] | 63 | # == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules == |
---|
| 64 | # backup |
---|
| 65 | cp /usr/bin/mkpxeinitrd-net /usr/bin/mkpxeinitrd-net.drbl-virt_bak |
---|
| 66 | # copy Xen network scripts |
---|
| 67 | cp /etc/xen/scripts/network-bridge /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 68 | cp /etc/xen/scripts/xen-network-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 69 | cp /etc/xen/scripts/xen-script-common.sh /usr/lib/mkpxeinitrd-net/initrd-skel/bin/ |
---|
| 70 | # patch it to copy command |
---|
| 71 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep 'include_bin_prog_from_server=' | awk '{print $1}') |
---|
| 72 | modify_file="/usr/bin/mkpxeinitrd-net" |
---|
[177] | 73 | 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 |
---|
[174] | 74 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 75 | # patch it to copy modules |
---|
| 76 | declare -i modify_line=$(cat -n /usr/bin/mkpxeinitrd-net | grep "# Deal with firmwares" | awk '{print $1}') |
---|
| 77 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 78 | modify_line=$modify_line+1 |
---|
| 79 | sed -i "${modify_line}icp -a --parents kernel/net/bridge/bridge.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
| 80 | modify_line=$modify_line+1 |
---|
| 81 | sed -i "${modify_line}icp -a --parents kernel/drivers/xen/netback/netloop.ko \$initrd/lib/modules/\$kernel_ver/" $modify_file |
---|
[171] | 82 | |
---|
[174] | 83 | # == Run Xen network-bridge in booting (/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init) == |
---|
| 84 | cat <<EOF >/usr/lib/mkpxeinitrd-net/initrd-skel/bin/start_xen_bridge.sh |
---|
[177] | 85 | #!/bin/bash |
---|
[174] | 86 | # drbl-virt add |
---|
[176] | 87 | NICs=\$(/sbin/ifconfig | grep eth | awk '{print \$1}') |
---|
| 88 | declare -i NICs_nu=\$(echo \$NICs |wc -l) |
---|
[174] | 89 | NIC="" |
---|
[173] | 90 | |
---|
[178] | 91 | if [ \$NICs_nu -lt 1 ]; then |
---|
[176] | 92 | for (( i=0 ; i<\$NICs_nu ; i++ )) |
---|
[174] | 93 | do |
---|
[176] | 94 | NIC_IP=\$(ifconfig eth\${i} | grep "inet addr" | sed 's/inet addr://g' | sed 's/Bcast.*$//g') |
---|
| 95 | if [ -n \$NIC_IP ]; then |
---|
| 96 | NIC="eth\${i}" |
---|
[174] | 97 | break |
---|
| 98 | fi |
---|
| 99 | done |
---|
| 100 | else |
---|
[176] | 101 | NIC=\$NICS |
---|
[174] | 102 | fi |
---|
[171] | 103 | |
---|
[177] | 104 | bash /bin/network-bridge start netdev=\$NIC |
---|
[174] | 105 | EOF |
---|
| 106 | # backup |
---|
| 107 | cp /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init.drbl-virt_bak |
---|
| 108 | declare -i modify_line=$(cat -n /usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init | grep "# clean the tag file" | awk '{print $1}') |
---|
| 109 | modify_file="/usr/lib/mkpxeinitrd-net/initrd-skel/linuxrc-or-init" |
---|
[171] | 110 | |
---|
[174] | 111 | sed -i "${modify_line}i# drbl-virt add" $modify_file |
---|
| 112 | modify_line=$modify_line+1 |
---|
[177] | 113 | sed -i "${modify_line}ibash /bin/start_xen_bridge.sh" $modify_file |
---|
[175] | 114 | |
---|
[178] | 115 | # = 3. enable xend xendomains daemon in DRBL Client = |
---|
| 116 | if [ -e /opt/drbl/conf/client-extra-service ]; then |
---|
| 117 | echo 'service_extra_added="xend xendomains"' >> /opt/drbl/conf/client-extra-service |
---|
| 118 | else |
---|
| 119 | echo 'service_extra_added="xend xendomains"' > /opt/drbl/conf/client-extra-service |
---|
| 120 | fi |
---|
[175] | 121 | |
---|
[178] | 122 | # = 4. Re-deploy drbl client = |
---|
[175] | 123 | # == Cheange Xen Kernel == |
---|
| 124 | echo "/opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel" |
---|
| 125 | /opt/drbl/sbin/drblsrv-offline -s $Xen_Kernel |
---|
| 126 | echo "" |
---|
| 127 | # == Re-delpoy drbl client == |
---|
| 128 | echo "Re-delpoy drbl client" |
---|
| 129 | echo "/opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf" |
---|
| 130 | /opt/drbl/sbin/drblpush -c /etc/drbl/drblpush.conf |
---|
| 131 | echo "" |
---|
| 132 | |
---|
[178] | 133 | # = 5. enable xend xendomains daemon afterr drblpush = |
---|
| 134 | # /opt/drbl/sbin/drbl-client-service xend on |
---|
| 135 | |
---|