Add udev.event-timeout=6000 to kernel command line for newer udev.
[supernested.git] / run-supernested.sh.in
1 #!/bin/bash -
2 # supernested Makefile.am
3 # @configure_input@
4 # (C) Copyright 2014 Red Hat Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 # Written by Richard W.M. Jones <rjones@redhat.com>
21
22 qemu="@QEMU@"
23 image="supernested-@VERSION@-@DISTRO@.qcow2"
24 format=qcow2
25 kernel=kernel
26 initrd=initrd
27 append="panic=1 console=ttyS0 udevtimeout=6000 udev.event-timeout=6000 no_timer_check printk.time=1 root=/dev/sda selinux=0"
28 smp=
29 tcg=
30
31 TEMP=`getopt \
32         -o '' \
33         --longoptions 'help,nested,smp:,tcg' \
34         -n run-supernested.sh -- "$@"`
35 if [ $? != 0 ]; then
36     echo "$0: problem parsing the command line arguments"
37     exit 1
38 fi
39 eval set -- "$TEMP"
40
41 usage ()
42 {
43     echo "$0: Run the supernested appliance."
44     echo "  $0 [--smp=N] [--tcg]"
45     echo "Options:"
46     echo "  --smp=N    Use N virtual CPUs (at all levels)."
47     echo "  --tcg      Use TCG (at all levels) instead of KVM."
48 }
49
50 while true ; do
51     case "$1" in
52         --nested)
53             # When the nested guest calls this script, it uses the
54             # --nested flag.  DO NOT ADD THIS FLAG YOURSELF!
55             image=/dev/sda
56             format=raw
57             kernel=/kernel
58             initrd=/initrd
59             smp="$(
60                 grep -Eo 'supernested.smp=[[:digit:]]+' /proc/cmdline |
61                 grep -Eo '[[:digit:]]+'
62                 )"
63             tcg=
64             if grep -q supernested.tcg=1 /proc/cmdline; then
65                 tcg=1
66             fi
67             shift
68             ;;
69         --smp)
70             smp="$2"
71             shift 2
72             ;;
73         --tcg)
74             tcg=1
75             shift
76             ;;
77         --help)
78             usage
79             exit 0
80             ;;
81         --)
82             shift
83             break
84             ;;
85         *)
86             echo "internal error ($1)"
87             exit 1
88             ;;
89     esac
90 done
91
92 # How much memory to give to the guest?
93 memory="$(
94     grep -Eo '^MemTotal:.*[[:digit:]]+ kB' /proc/meminfo |
95     grep -Eo '[[:digit:]]+'
96     )"
97 if [ -z "memory" ]; then
98     echo "$0: could not get total memory from /proc/meminfo"
99     exit 1
100 fi
101 memory=$((memory / 1024))
102 if [ $memory -lt 2048 ]; then
103     echo "$0: not enough memory left: memory=$memory MB"
104     exit 1
105 fi
106 memory=$((memory - 1500))
107
108 # Get current nesting level from /proc/cmdline, increment it, add it
109 # to the command line.
110 level="$(
111     grep -Eo 'supernested.level=[[:digit:]]+' /proc/cmdline |
112     grep -Eo '[[:digit:]]+'
113     )"
114 if [ -z "$level" ]; then level=0; fi
115 append="$append supernested.level=$((level+1))"
116
117 # Append other parameters to nested command line.
118 append="$append supernested.smp=$smp supernested.tcg=$tcg"
119
120 extra_args=
121 if [ -n "$smp" ]; then extra_args="$extra_args -smp $smp"; fi
122 if [ -n "$tcg" ]; then
123     extra_args="$extra_args -machine accel=tcg"
124 else
125     extra_args="$extra_args -cpu host -machine accel=kvm"
126 fi
127
128 echo "Running"
129 echo "    qemu = $qemu"
130 echo "    extra_args = $extra_args"
131 echo "    memory = $memory"
132 echo "    kernel = $kernel"
133 echo "    initrd = $initrd"
134 echo "    disk = $image"
135 echo "    append = $append"
136
137 # Since this could crash the machine, better to sync ...
138 sync
139
140 exec \
141 "$qemu" \
142     $extra_args \
143     -display none \
144     -m $memory \
145     -no-reboot \
146     -rtc driftfix=slew \
147     -no-hpet \
148     -global kvm-pit.lost_tick_policy=discard \
149     -kernel "$kernel" \
150     -initrd "$initrd" \
151     -device virtio-scsi-pci,id=scsi \
152     -drive file="$image",snapshot=on,cache=unsafe,format="$format",id=hd0,if=none \
153     -device scsi-hd,drive=hd0 \
154     -device virtio-serial-pci \
155     -serial stdio \
156     -device sga \
157     -append "$append"