| 1 | #!/bin/bash |
| 2 | |
| 3 | #BINARIES |
| 4 | screen='/usr/bin/screen'; |
| 5 | |
| 6 | #COMMON |
| 7 | cd /mnt/data2/uml/; #directory to work in |
| 8 | umluser='vserver'; #Setuid before run vserver |
| 9 | umldelay='10'; #Delay (man sleep) before restart after vserver halt/fail |
| 10 | umldir='/mnt/data2/uml/umldir'; #Directory for umid & pid files |
| 11 | |
| 12 | #NETWORK |
| 13 | hostnic='eth1'; #network interface to operate on |
| 14 | umlbridge='br0'; #name of bridge between real network and UMLs |
| 15 | hostip='192.168.2.163'; #ipadres of host |
| 16 | hostmask='255.255.255.0'; #netmask of host |
| 17 | hostgw='192.168.2.1'; #default gw of host |
| 18 | |
| 19 | #MACHINES |
| 20 | uml_machines() { #list of UML machines to be executed |
| 21 | #new_uml respawn umlkernel umlrootimg umlmem umlnice umllog tapnic umlmac |
| 22 | #new_uml true linux.uml debtest.img 64M 10 /dev/null tap0 fe:fd:c0:a8:02:89 |
| 23 | new_uml true /opt/uml/linux-2.6.24-rc7 debtest.img 64M 10 log0.txt tap0 fe:fd:c0:a8:02:89 |
| 24 | } |
| 25 | |
| 26 | ############################################################ |
| 27 | echo " |
| 28 | |
| 29 | !!!!!!YOU MAY NEED TO SETUP YOUR GUEST OS!!!!!!! |
| 30 | !!!!!!!!!!OR YOU CAN USE DHCP INSTEAD!!!!!!!!!!! |
| 31 | root@uml# cat /etc/network/interfaces |
| 32 | |
| 33 | auto lo |
| 34 | iface lo inet loopback |
| 35 | |
| 36 | auto eth0 |
| 37 | iface eth0 inet static |
| 38 | address YOUR.ADD.RESS.HERE |
| 39 | netmask $hostmask |
| 40 | gateway $hostgw |
| 41 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 42 | |
| 43 | "; |
| 44 | ############################################################ |
| 45 | |
| 46 | echo [i] Initializing tuntap networking... |
| 47 | modprobe tun |
| 48 | |
| 49 | echo [i] Initializing "$umlbridge" bridge... |
| 50 | ifconfig "$hostnic" 0.0.0.0 promisc up |
| 51 | brctl addbr "$umlbridge" |
| 52 | brctl setfd "$umlbridge" 0 |
| 53 | brctl sethello "$umlbridge" 0 |
| 54 | brctl stp "$umlbridge" off |
| 55 | |
| 56 | echo [i] Adding "$hostnic" interface to "$umlbridge" bridge... |
| 57 | ifconfig "$umlbridge" "$hostip" netmask "$hostmask" up |
| 58 | route add default gw "$hostgw" |
| 59 | brctl addif "$umlbridge" "$hostnic" |
| 60 | |
| 61 | echo [!] Now launching all UML Machines... |
| 62 | new_uml() { |
| 63 | if [ -z "$8" ]; then |
| 64 | echo [!] Failed. Not enough parameters for this machine.; |
| 65 | return; |
| 66 | fi; |
| 67 | |
| 68 | respawn="$1"; |
| 69 | umlkernel="$2"; |
| 70 | umlrootimg="$3"; |
| 71 | umlmem="$4"; |
| 72 | umlnice="$5"; |
| 73 | umllog="$6"; |
| 74 | tapnic="$7"; |
| 75 | umlmac="$8"; |
| 76 | |
| 77 | tunctl -d "$tapnic" |
| 78 | tunctl -u "$umluser" -t "$tapnic" |
| 79 | |
| 80 | echo [i] Adding "$tapnic" interface to "$umlbridge" bridge... |
| 81 | ifconfig "$tapnic" 0.0.0.0 promisc up |
| 82 | brctl addif "$umlbridge" "$tapnic" |
| 83 | |
| 84 | #echo [R] Sleeping 120 before REBOOT.... #DEBUG FEATURE |
| 85 | #sleep 120; |
| 86 | #reboot; |
| 87 | |
| 88 | |
| 89 | echo [S] Starting UML on "$tapnic"... |
| 90 | |
| 91 | #con0=fd:0,fd:1 con1=pty |
| 92 | #$screen -d -m su "$umluser" -c "nice -n $umlnice $umlkernel mem=$umlmem ubd0=$umlrootimg jail eth0=tuntap,$tapnic,$umlmac uml_dir=$umldir umid=$tapnic con0=fd:0,fd:1 con1=pty > $umllog 2>&1" |
| 93 | #su "$umluser" -c "$screen -d -m nice -n $umlnice $umlkernel mem=$umlmem ubd0=$umlrootimg jail eth0=tuntap,$tapnic,$umlmac uml_dir=$umldir umid=$tapnic con0=fd:0,fd:1 con1=pty > $umllog 2>&1" |
| 94 | #nice -n "$umlnice" su "$umluser" -c "$screen -d -m $umlkernel mem=$umlmem ubd0=$umlrootimg jail eth0=tuntap,$tapnic,$umlmac uml_dir=$umldir umid=$tapnic con0=fd:0,fd:1 con1=pty > $umllog 2>&1" |
| 95 | |
| 96 | nice -n "$umlnice" su "$umluser" -c "$screen -d -m bash -c ' |
| 97 | while true; do |
| 98 | $umlkernel mem=$umlmem ubd0=$umlrootimg jail eth0=tuntap,$tapnic,$umlmac uml_dir=$umldir umid=$tapnic con0=fd:0,fd:1 con1=pty > $umllog 2>&1; |
| 99 | sleep $umldelay; |
| 100 | if ( $respawn ); then continue; fi; break; |
| 101 | done; |
| 102 | '"; |
| 103 | } |
| 104 | |
| 105 | uml_machines; |
| 106 | echo [!] All UML Machines launched. |