summaryrefslogtreecommitdiff
path: root/contrib/fedora/nm-live-vm/run.sh
blob: b887b98f16b8bedc6a88a50d16718c40a115a1db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
# vim: ft=sh ts=4 sts=4 sw=4 et ai
# -*- Mode: bash; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-

# Three network interfaces
NET_OPTIONS="-net nic -net user,hostfwd=tcp:127.0.0.1:10022-:22 -net nic -net user -net nic -net user"

OS="Linux"
if [ -f /etc/redhat-release ]; then
    OS=`cat /etc/redhat-release | cut -d" " -f1,2,3,4`
fi

MEMORY=$((3*1024))

DIR="$(dirname "$(readlink -f "$0")")"
SDIR="$DIR/share"
if [ -n "$1" ]; then
    SDIR="$1"
fi
mkdir -p "$SDIR"

cd "$DIR"

if [ "$OS" == "Red Hat Enterprise Linux" ]; then
    # qemu-kvm is installed in /usr/libexec on RHEL6
    # and redirects its output to VNC server

    rpm -q qemu-kvm tigervnc >&2 || exit 1

    PATH=$PATH:/usr/libexec

    qemu-kvm -vnc :0 -m $MEMORY $NET_OPTIONS -kernel vmlinuz -append "video=1024x640 rootfstype=ramfs" -initrd initramfs.img &

    sleep 1
    vncviewer localhost

else
    # all other distros

    QEMU="qemu-kvm"
    which $QEMU &>2 || {
        ARCH=`uname -m`
        which qemu-system-$ARCH &>2 || { echo "Neither '$QEMU' nor 'qemu-system-$ARCH' available"; exit 1; }
        QEMU="qemu-system-$ARCH -enable-kvm"
    }

    $QEMU -m $MEMORY -net nic $NET_OPTIONS -virtfs "local,path=$SDIR,mount_tag=host0,security_model=none,id=host0" -device "virtio-9p-pci,fsdev=host0,mount_tag=host0" -kernel vmlinuz -append "video=1024x640 rootfstype=ramfs" -initrd initramfs.img
fi