summaryrefslogtreecommitdiffstats
path: root/archievm
blob: b37600dc858daab2de29acecaff4e5294181a42f (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/zsh

lsmod | grep -q kvm_intel || {
    sudo modprobe -a -v kvm kvm_intel
}
debugk=0
nographic=1
mem=512
huge=0
test=0
ksm=0
console=0
runas="raghavendra"
DIR="/home/raghavendra/Arch/qemu"
bzImage="$DIR/kvmImage"
image="/media/Sparowes/Virt/Archie.img"
soutput=1

typeset -A args
args=(d debugk c console n nographic g huge I bzImage t test s soutput)

while getopts ':gn:dI:th' opt;do
    case $opt in
        g|d|t)
            eval $args[$opt]=1
            ;;
        n)
            nographic=$OPTARG
            ;;
        I)
          bzImage=$OPTARG
          ;;
        h)
            print "$0 [-d] [-g] [-n=0|1] [-I=<image>] [-h]
            d: debugk
            g: huge
            c: qemu console 
            t: test
            n: nographic (default=1)
            I: Image (default=$DIR/kvmImage)"
            exit 1
            ;;
    esac
done

shift $(( OPTIND-1 ))
EARGS="[email protected]"

[[ ! -d /mnt-qemu ]] && mkdir -p /mnt-qemu

[[ $nographic == 0 ]] && soutput=0

if [[ $debugk == 1 ]];then
    if [[ $soutput == 1 ]];then
        external=" -kernel $bzImage -initrd /boot/kernel26-.img -append \"root=/dev/vda3 console=ttyS0 earlyprintk=serial,ttyS0\" -serial file:$DIR/console.log "
    else
        external=" -kernel $bzImage -initrd /boot/kernel26-.img -append \"root=/dev/vda3\" "
    fi
fi

if [[ $huge == 1 && $test == 0 ]];then
    echo 148 | sudo tee /proc/sys/vm/nr_hugepages
    hugearg=" -mem-path /media/hugepages "
fi

if [[ $nographic == 1 ]];then
    graph=" -daemonize -nographic "
else
    graph=" -vga std -sdl -no-frame"
fi

if [[ $test == 1 ]];then
    snap=" -snapshot -drive file=$image,if=virtio "
else
    snap=" -drive file=$image,if=virtio,cache=writeback "
fi

    #-virtfs local,path=$DIR/module,security_model=passthrough,mount_tag=module \
    #-m 512 $hugearg $snap  -smp 2,cores=2,maxcpus=4 \
    # -balloon virtio

cmdline="qemu-kvm -name Archie -enable-kvm -s -monitor unix:$DIR/archie.sock,server,nowait  \
    -m $mem $hugearg $snap -smp 2,cores=2 -balloon virtio \
    -net nic,model=virtio,vlan=1 -net user,vlan=1,hostfwd=tcp:127.0.0.1:2222-:22 $=graph \
    -virtfs local,path=$DIR/share,security_model=none,mount_tag=share \
    -virtfs local,path=/var/cache/pacman/pkg,security_model=none,mount_tag=pacman \
    -virtfs local,path=/media/Corona/bldit/.gcov,security_model=none,mount_tag=gcov \
    $external -runas $runas   $=EARGS"

eval $=cmdline || exit 12

if [[ $ksm == 1 ]];then
    echo 1  | sudo tee /sys/kernel/mm/ksm/run
fi
sshfs -p 2222 [email protected]:/home/raghu/gcov /media/Corona/bldit/.gcov
if [[ $console == 1 ]];then
    rlwrap socat - $DIR/archie.sock
else
    if [[ $nographic == 1 ]];then 
        ssh -p 2222 [email protected]
    fi
fi