OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 # | 4 # |
5 # Common vm functions for use in crosutils. | 5 # Common vm functions for use in crosutils. |
6 | 6 |
| 7 . "$(dirname "$0")/cros_vm_constants.sh" |
| 8 |
7 DEFINE_string kvm_pid "" \ | 9 DEFINE_string kvm_pid "" \ |
8 "Use this pid file. If it exists and is set, use the vm specified by pid." | 10 "Use this pid file. If it exists and is set, use the vm specified by pid." |
9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." | 11 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." |
10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." | 12 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." |
11 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." | 13 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." |
12 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." | 14 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." |
13 | 15 |
14 | |
15 KVM_PID_FILE=/tmp/kvm.$$.pid | 16 KVM_PID_FILE=/tmp/kvm.$$.pid |
16 | 17 |
17 function get_pid() { | 18 function get_pid() { |
18 sudo cat "${KVM_PID_FILE}" | 19 sudo cat "${KVM_PID_FILE}" |
19 } | 20 } |
20 | 21 |
21 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work | 22 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work |
22 # on Hardy. | 23 # on Hardy. |
23 # $1: Path to the virtual image to start. | 24 # $1: Path to the virtual image to start. |
24 function start_kvm() { | 25 function start_kvm() { |
(...skipping 15 matching lines...) Expand all Loading... |
40 local nographics="" | 41 local nographics="" |
41 local usesnapshot="" | 42 local usesnapshot="" |
42 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then | 43 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then |
43 nographics="-nographic" | 44 nographics="-nographic" |
44 fi | 45 fi |
45 | 46 |
46 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then | 47 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then |
47 snapshot="-snapshot" | 48 snapshot="-snapshot" |
48 fi | 49 fi |
49 | 50 |
50 sudo kvm -m 1024 \ | 51 sudo kvm -m ${DEFAULT_MEM} \ |
51 -vga std \ | 52 -vga std \ |
52 -pidfile "${KVM_PID_FILE}" \ | 53 -pidfile "${KVM_PID_FILE}" \ |
53 -daemonize \ | 54 -daemonize \ |
54 -net nic \ | 55 -net nic \ |
55 ${nographics} \ | 56 ${nographics} \ |
56 ${snapshot} \ | 57 ${snapshot} \ |
57 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ | 58 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ |
58 -hda "${1}" | 59 -hda "${1}" |
59 fi | 60 fi |
60 } | 61 } |
61 | 62 |
62 function stop_kvm() { | 63 function stop_kvm() { |
63 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then | 64 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then |
64 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ | 65 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ |
65 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." | 66 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." |
66 else | 67 else |
67 echo "Stopping the KVM instance" | 68 echo "Stopping the KVM instance" |
68 local pid=$(get_pid) | 69 local pid=$(get_pid) |
69 echo "Killing ${pid}" | 70 echo "Killing ${pid}" |
70 sudo kill ${pid} | 71 sudo kill ${pid} |
71 sudo rm "${KVM_PID_FILE}" | 72 sudo rm "${KVM_PID_FILE}" |
72 fi | 73 fi |
73 } | 74 } |
OLD | NEW |