Absolute sleep
[mirrors/Programs.git] / bash / runvm.sh
CommitLineData
b1739949
H
1#!/bin/bash
2
3#BINARIES
4screen='/usr/bin/screen';
5
6#COMMON
7cd /mnt/data2/uml/; #directory to work in
8umluser='vserver'; #Setuid before run vserver
9umldelay='10'; #Delay (man sleep) before restart after vserver halt/fail
10umldir='/mnt/data2/uml/umldir'; #Directory for umid & pid files
11
12#NETWORK
13hostnic='eth1'; #network interface to operate on
14umlbridge='br0'; #name of bridge between real network and UMLs
15hostip='192.168.2.163'; #ipadres of host
16hostmask='255.255.255.0'; #netmask of host
17hostgw='192.168.2.1'; #default gw of host
18
19#MACHINES
20uml_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############################################################
27echo "
28
29!!!!!!YOU MAY NEED TO SETUP YOUR GUEST OS!!!!!!!
30!!!!!!!!!!OR YOU CAN USE DHCP INSTEAD!!!!!!!!!!!
31root@uml# cat /etc/network/interfaces
32
33auto lo
34iface lo inet loopback
35
36auto eth0
37iface eth0 inet static
38address YOUR.ADD.RESS.HERE
39netmask $hostmask
40gateway $hostgw
41!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42
43";
44############################################################
45
46echo [i] Initializing tuntap networking...
47modprobe tun
48
49echo [i] Initializing "$umlbridge" bridge...
50ifconfig "$hostnic" 0.0.0.0 promisc up
51brctl addbr "$umlbridge"
52brctl setfd "$umlbridge" 0
53brctl sethello "$umlbridge" 0
54brctl stp "$umlbridge" off
55
56echo [i] Adding "$hostnic" interface to "$umlbridge" bridge...
57ifconfig "$umlbridge" "$hostip" netmask "$hostmask" up
58route add default gw "$hostgw"
59brctl addif "$umlbridge" "$hostnic"
60
61echo [!] Now launching all UML Machines...
62new_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
105uml_machines;
106echo [!] All UML Machines launched.
This page took 0.378549 seconds and 4 git commands to generate.