diff --git a/bin/cros_start_vm b/bin/cros_start_vm new file mode 100755 index 0000000000..3ecced9f69 --- /dev/null +++ b/bin/cros_start_vm @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Simple wrapper scipt to start a vm using the vm lib. + +. "$(dirname $0)/../common.sh" +. "$(dirname $0)/../lib/cros_vm_lib.sh" +. "$(dirname "$0")/../lib/cros_vm_constants.sh" + +DEFINE_string image_path "" "Full path of the VM image" + +set -e + +# Parse command line. +FLAGS "$@" || exit 1 +eval set -- "${FLAGS_ARGV}" + +# Use latest if not specified. +if [ -z "${FLAGS_image_path}" ]; then + LATEST_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh)/${DEFAULT_QEMU_IMAGE}" + info "Using latest vm image ${LATEST_IMAGE}" + FLAGS_image_path=${LATEST_IMAGE} +fi + +[ -e "${FLAGS_image_path}" ] || die "Image ${FLAGS_image_path} does not exist." + +start_kvm "${FLAGS_image_path}" + +echo "ssh root@${HOSTNAME} -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no" diff --git a/lib/cros_vm_lib.sh b/lib/cros_vm_lib.sh index 8f98926ccc..f36804d378 100644 --- a/lib/cros_vm_lib.sh +++ b/lib/cros_vm_lib.sh @@ -28,15 +28,15 @@ function start_kvm() { local pid=$(get_pid) # Check if the process exists. if ps -p ${pid} > /dev/null ; then - echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." + echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2 else # Let's be safe in case they specified a file that isn't a pid file. - echo "File ${KVM_PID_FILE} exists but specified pid doesn't." + echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2 exit 1 fi else # No pid specified by PID file. Let's create a VM instance in this case. - echo "Starting a KVM instance" + echo "Starting a KVM instance" >&2 local nographics="" local usesnapshot="" if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then @@ -65,7 +65,7 @@ function start_kvm() { function ssh_ping() { "$(dirname $0)"/../ssh_test.sh \ --ssh_port=${FLAGS_ssh_port} \ - --remote=127.0.0.1 + --remote=127.0.0.1 >&2 } # Tries to ssh into live image $1 times. After first failure, a try involves @@ -88,12 +88,12 @@ function retry_until_ssh() { function stop_kvm() { if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ - "--kvm_pid ${KVM_PID_FILE} to re-connect to it." + "--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2 else echo "Stopping the KVM instance" >&2 local pid=$(get_pid) if [ -n "${pid}" ]; then - echo "Killing ${pid}" + echo "Killing ${pid}" >&2 sudo kill ${pid} sudo rm "${KVM_PID_FILE}" else