summaryrefslogtreecommitdiffstats
path: root/archievm
blob: f03d89f80f74790848d8c55818b4b9f58ad99d9c (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
#!/bin/zsh
# Virtio somehow broken

#[[ ! $(whoami) == 'root' ]] && exit 1
#sudo modprobe -a -v kvm kvm_intel virtio virtio_pci  virtio_balloon virtio_blk virtio_net virtio_console virtio_rng 9pnet_virtio
sudo modprobe -a -v kvm kvm_intel

debugk=0
nographic=1
huge=1
test=0
ksm=0
runas="raghavendra"
DIR="/home/raghavendra/Arch/qemu"
bzImage="$DIR/kvmImage"
image="/media/Sparowes/Virt/Archie.img"
soutput=1
#append="root=/dev/vda3"

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

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
            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 ]];then
    echo 296 | sudo tee /proc/sys/vm/nr_hugepages
    hugearg=" -mem-path /media/hugepages -mem-prealloc "
    #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 512 $hugearg $snap \
    -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=passthrough,mount_tag=share \
    -virtfs local,path=/var/cache/pacman/pkg,security_model=passthrough,mount_tag=pacman \
    $external -runas $runas   $=EARGS"

#echo "$cmdline"
#exit
eval $=cmdline

if [[ $ksm == 1 ]];then
    echo 1  | sudo tee /sys/kernel/mm/ksm/run
fi
echo "sudo -u $runas sshfs -p 2222 [email protected]:/ /mnt-qemu" | xclip -i
#rlwrap -pgreen socat - $DIR/archie.sock
rlwrap socat - $DIR/archie.sock
#qemu-kvm -name Archie -enable-kvm -m 512 -snapshot -drive file=/media/Inkq/Virt/Archie.img,if=virtio -vga std  -kernel ~/Arch/qemu/kvmImage  -initrd /boot/kernel26.img -append root=/dev/vda3
#qemu-kvm -name Archie -enable-kvm -m 512 -snapshot -hda /media/Inkq/Virt/Archie.img -vga std  -kernel ~/Arch/qemu/kvmImage  -initrd /boot/kernel26-wye.img  -append "root=/dev/sda3 console=ttyS0 earlyprintk=serial,ttyS0" -serial file:/tmp/x.log#