[161] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
[213] | 3 | # Path DRBL evironment to support KVM |
---|
| 4 | # Author: |
---|
[161] | 5 | # Jazz, Rock {jazz, rock}@nchc.org.tw |
---|
| 6 | # Version: |
---|
| 7 | # 1.0 |
---|
[213] | 8 | # History: |
---|
| 9 | # 2010/10/18 Rock First release (1.0) |
---|
[161] | 10 | |
---|
| 11 | # [Source] |
---|
[171] | 12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
[178] | 13 | source $Work_Path/functions_drbl_virt |
---|
| 14 | |
---|
[161] | 15 | # [Main] |
---|
[213] | 16 | # = 1. Patch DRBL xen env for client = |
---|
| 17 | # == Shutdown all drbl client == |
---|
[215] | 18 | echo -e "\nPlease shutdown all drbl client !!!" |
---|
| 19 | echo "You can use /opt/drbl/sbin/dcs to shutdown." |
---|
[213] | 20 | read -p "Push [Enter] to continue......" |
---|
[161] | 21 | |
---|
[213] | 22 | # == check KVM Kernel version |
---|
| 23 | check_kvm |
---|
[216] | 24 | echo $KVM_Kernel > $Work_Home/etc/KVM_Kernel |
---|
[161] | 25 | |
---|
[213] | 26 | # == Modify PXE booting menu == |
---|
| 27 | # if menu doesn't has drbl-virt, then add it |
---|
| 28 | cat /opt/drbl/sbin/generate-pxe-menu | grep "label drbl-virt" >> /dev/null |
---|
| 29 | if [ $? != 0 ]; then |
---|
| 30 | # backup generate-pxe-menu |
---|
| 31 | cp /tftpboot/nbi_img/pxelinux.cfg/default /tftpboot/nbi_img/pxelinux.cfg/default.drbl-virt_bak |
---|
| 32 | cp /opt/drbl/sbin/generate-pxe-menu /opt/drbl/sbin/generate-pxe-menu.drbl-virt_bak |
---|
[178] | 33 | |
---|
[213] | 34 | generate_PXE_menu="/opt/drbl/sbin/generate-pxe-menu" |
---|
| 35 | declare -i modify_line=$(cat -n $generate_PXE_menu | grep 'label drbl' | awk 'NR==1 {print $1}') |
---|
| 36 | # delete default |
---|
| 37 | sed -i 's/^ MENU DEFAULT/ # MENU DEFAULT/g' $generate_PXE_menu |
---|
| 38 | # modify menu |
---|
| 39 | sed -i "${modify_line}i\label drbl-virt" $generate_PXE_menu |
---|
| 40 | modify_line=$modify_line+1 |
---|
| 41 | sed -i "${modify_line}i\ MENU DEFAULT" $generate_PXE_menu |
---|
| 42 | modify_line=$modify_line+1 |
---|
| 43 | sed -i "${modify_line}i\ # MENU HIDE" $generate_PXE_menu |
---|
| 44 | modify_line=$modify_line+1 |
---|
[217] | 45 | sed -i "${modify_line}i\ MENU LABEL DRBL-Virtualization (KVM $KVM_Kernel)" $generate_PXE_menu |
---|
[213] | 46 | modify_line=$modify_line+1 |
---|
| 47 | sed -i "${modify_line}i\ kernel vmlinuz-pxe" $generate_PXE_menu |
---|
| 48 | modify_line=$modify_line+1 |
---|
[217] | 49 | sed -i "${modify_line}i\ append initrd=initrd-pxe.img devfs=nomount drblthincli=off selinux=0 nomodeset" $generate_PXE_menu |
---|
[213] | 50 | modify_line=$modify_line+1 |
---|
| 51 | sed -i "${modify_line}i\ TEXT HELP" $generate_PXE_menu |
---|
| 52 | modify_line=$modify_line+1 |
---|
| 53 | sed -i "${modify_line}i\ ENDTEXT" $generate_PXE_menu |
---|
| 54 | modify_line=$modify_line+1 |
---|
| 55 | sed -i "${modify_line}i\ " $generate_PXE_menu |
---|
| 56 | fi |
---|
[161] | 57 | |
---|
[213] | 58 | |
---|
| 59 | # = 2. Patch DRBL initrd to support bridge = |
---|
| 60 | # == Patch /usr/bin/mkpxeinitrd-net (1)Xen network scripts (2)command (3)modules == |
---|
[217] | 61 | # backup mkpxeinitrd-net. if already has "drbl-virt add", doesn't sed |
---|
| 62 | source $Work_Path/drbl_bridge_kvm_patch |
---|
[213] | 63 | |
---|
| 64 | |
---|
| 65 | # = 3. Load KVM module when booting = |
---|
[219] | 66 | if [ -e /opt/drbl/conf/client-extra-service ]; then |
---|
| 67 | grep 'service_extra_added="kvm"' /opt/drbl/conf/client-extra-service |
---|
[213] | 68 | if [ $? -eq 1 ]; then |
---|
[219] | 69 | echo 'service_extra_added="kvm"' >> /opt/drbl/conf/client-extra-service |
---|
[213] | 70 | fi |
---|
[219] | 71 | else |
---|
| 72 | echo 'service_extra_added="kvm"' > /opt/drbl/conf/client-extra-service |
---|
| 73 | fi |
---|
| 74 | # for Debian & Ubuntu |
---|
| 75 | #if [ -e /etc/modules ]; then |
---|
| 76 | # grep kvm /etc/modules |
---|
| 77 | # if [ $? -eq 1 ]; then |
---|
| 78 | # echo "kvm" >> /etc/modules |
---|
| 79 | # fi |
---|
[214] | 80 | # for CentOS & Fedora |
---|
[219] | 81 | #elif [ -e /etc/sysconfig/modules ]; then |
---|
| 82 | # grep -r "modprobe kvm" /etc/sysconfig/modules/ |
---|
| 83 | # if [ $? -eq 1 ]; then |
---|
| 84 | # cat > /etc/sysconfig/modules/kvm.modules << EOF |
---|
| 85 | ##!/bin/sh |
---|
| 86 | #echo -n "Loading kvm module..." |
---|
| 87 | #if \$(/sbin/modprobe kvm) |
---|
| 88 | # then |
---|
| 89 | # echo "[SUCCESS]:" |
---|
| 90 | # else |
---|
| 91 | # echo "[FAILURE]:" |
---|
| 92 | #fi |
---|
| 93 | #EOF |
---|
| 94 | # chmod +x /etc/sysconfig/modules/kvm.modules |
---|
| 95 | # fi |
---|
| 96 | #fi |
---|
[213] | 97 | |
---|
| 98 | # = 4. Copy xen kernel & initrd to /home/domains = |
---|
| 99 | if [ ! -e /home/domains ]; then |
---|
| 100 | mkdir /home/domains |
---|
| 101 | fi |
---|
| 102 | cp /tftpboot/nbi_img/vmlinuz-pxe /home/domains |
---|
| 103 | cp /tftpboot/nbi_img/initrd-pxe.img /home/domains |
---|
| 104 | |
---|
| 105 | |
---|