Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:jshi22
kvmscript
kvm
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File kvm of Package kvmscript
#!/bin/sh usage() { cat >&2 <<HELP $0 [options] Options include: --init Load kernel module and prepare network --deinit Unload kernel module and restore network --start=[lin|win] Start guest OS which you selected HELP } chkroot() { if [ $EUID -ne 0 ]; then echo "$0 $1 needs to be run by root." >&2 exit 1 fi } getif() { ip route | awk '/^default/{print $NF}' } getgw() { ip route | awk '/^default/{print $3}' } check() { ping -I $1 -c 3 $(getgw) return $? } init() { chkroot --init modprobe kvm-amd modprobe tun iptables -I FORWARD -i $ifbr -o $ifbr -j ACCEPT rcnetwork stop 2>/dev/null ip link set $ifhost up brctl addbr $ifbr brctl addif $ifbr $ifhost tunctl -u $usr -t $iftun brctl addif $ifbr $iftun ip link set $iftun up dhcpcd $ifbr } deinit() { chkroot --deinit pkill dhcpcd ip link set $iftun down ip link set $ifbr down brctl delif $ifbr $iftun tunctl -d $iftun brctl delif $ifbr $ifhost brctl delbr $ifbr rcnetwork start iptables -D FORWARD -i $ifbr -o $ifbr -j ACCEPT modprobe -r tun modprobe -r kvm-amd } start() { local kvm='/usr/local/bin/qemu-system-x86_64' local kvm_opt="-boot c -localtime -m 512 -daemonize -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=${iftun},script=no" case "$1" in win) $kvm -hda img/winxp2.qcow2 -no-acpi -cdrom iso/winxp-sp2.iso $kvm_opt ;; lin) $kvm -hda img/sles10sp1-2.qcow2 -cdrom ../add/SLES-10-SP1-DVD-i386-GM-DVD1.iso $kvm_opt ;; esac } ifhost=$(getif) iftun=tap0 ifbr=br0 usr=see opterr=0 exec >/dev/null if [ $# -le 0 ]; then opterr=1 fi while [ $# -gt 0 -a $opterr -eq 0 ]; do opt="${1%%=*}" arg="${1#*=}" shift case "$opt" in --init) init=1 ;; --deinit) deinit=1 ;; --start) if [ "$arg" = "lin" -o "$arg" = "win" ]; then start=1 os="$arg" else opterr=1 fi ;; *) opterr=1 ;; esac done if [ $opterr -ne 0 ]; then usage exit 1 fi if [ -n "$init" ]; then init if ! check $ifbr; then echo "init failed" >&2 exit 1 fi fi if [ -n "$deinit" ]; then deinit fi if [ -n "$start" ]; then start $os fi
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor