mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 12:03:31 +01:00
qemu-boot.sh: Some code cleanup, still a mess, though
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
3067ec7fd7
commit
937654282c
1 changed files with 72 additions and 25 deletions
|
|
@ -1,13 +1,9 @@
|
|||
#!/bin/sh -x
|
||||
#!/bin/bash
|
||||
|
||||
myname=`basename $0`
|
||||
dirname=`dirname $0`
|
||||
macaddr=00:0B:DC:9B:D6:DA
|
||||
base=dc=priv,dc=lcl
|
||||
exe=qemu-kvm
|
||||
qemu_opts=""
|
||||
brctl=`PATH=/usr/sbin:/sbin /usr/bin/which brctl`
|
||||
#nic_model=",model=rtl8139"
|
||||
goodbye()
|
||||
{
|
||||
rm -f $tmp_files
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
|
|
@ -21,6 +17,11 @@ EOT
|
|||
exit 0
|
||||
}
|
||||
|
||||
log()
|
||||
{
|
||||
echo "=========================== $*"
|
||||
}
|
||||
|
||||
err()
|
||||
{
|
||||
echo $* >&2
|
||||
|
|
@ -68,20 +69,30 @@ boot_net()
|
|||
sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'`
|
||||
}
|
||||
|
||||
xhost +
|
||||
do_sudo /sbin/modprobe kvm-intel
|
||||
|
||||
ps aux | grep -v grep | grep -q dhcpd || /etc/init.d/dhcpd start
|
||||
ps aux | grep -v grep | grep -q nfsd || /etc/init.d/nfsserver start
|
||||
|
||||
[ "$nic_model" ] || nic_model=",model=e1000"
|
||||
# need this for net access, would be nicer if it didn't run as root
|
||||
# -nographic
|
||||
do_sudo -E /usr/bin/$exe \
|
||||
|
||||
do_sudo -E /usr/bin/$qemu_exe \
|
||||
-boot n \
|
||||
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
||||
-net nic,vlan=0$nic_model,macaddr=$macaddr \
|
||||
"$qemu_opts"
|
||||
|
||||
# invalid param macaddr
|
||||
# do_sudo -E /usr/bin/$qemu_exe \
|
||||
# -boot n \
|
||||
# -net bridge,br=$bridge,$nic_model,macaddr=$macaddr \
|
||||
# $qemu_opts
|
||||
|
||||
# access denied by ACL files
|
||||
# do_sudo -E /usr/bin/$qemu_exe \
|
||||
# -boot n \
|
||||
# -net bridge,br=$bridge,$nic_model \
|
||||
# $qemu_opts
|
||||
}
|
||||
|
||||
boot_image()
|
||||
|
|
@ -89,24 +100,29 @@ boot_image()
|
|||
local boot_image="$1"
|
||||
|
||||
test -r "$boot_image" || fatal "inaccessible boot image \"$boot_image\""
|
||||
#-net bridge,br=$bridge \
|
||||
|
||||
xhost +
|
||||
do_sudo -E /usr/bin/$exe \
|
||||
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
||||
-net nic,vlan=0$nic_model,macaddr=$macaddr \
|
||||
do_sudo -E /usr/bin/$qemu_exe \
|
||||
-net nic,vlan=0$nic_model,macaddr=00:02:36:22:13:6b \
|
||||
-net nic,vlan=1$nic_model,macaddr=00:02:36:22:13:6c \
|
||||
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
||||
-net tap,ifname=tap1,vlan=1,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
||||
"$qemu_opts" \
|
||||
-drive format=raw,file=$boot_image
|
||||
}
|
||||
|
||||
boot()
|
||||
{
|
||||
local tmpdir=`mktemp -d /tmp/$myname""_XXXXXX`
|
||||
tmpdir=`mktemp -d /tmp/$myname""_XXXXXX`
|
||||
(
|
||||
cd $tmpdir
|
||||
ln -s $0 qemu-ifup
|
||||
ln -s $0 qemu-ifdown
|
||||
ln -s $exe qemu-ifup
|
||||
ln -s $exe qemu-ifdown
|
||||
)
|
||||
|
||||
do_sudo /sbin/modprobe kvm-intel
|
||||
xhost +
|
||||
|
||||
case $1 in
|
||||
net)
|
||||
boot_net
|
||||
|
|
@ -121,8 +137,26 @@ boot()
|
|||
|
||||
# -- here we go
|
||||
|
||||
log running $0 $@
|
||||
|
||||
myname=`basename $0`
|
||||
exe=`readlink -f $0`
|
||||
dirname=`dirname $exe`
|
||||
bridge=priv0
|
||||
#bridge=in1
|
||||
macaddr=00:0B:DC:9B:D6:DA
|
||||
base=dc=priv,dc=lcl
|
||||
qemu_exe=qemu-kvm
|
||||
qemu_opts=""
|
||||
brctl=`PATH=/usr/sbin:/sbin /usr/bin/which brctl`
|
||||
#nic_model=",model=rtl8139"
|
||||
tmp_files=""
|
||||
tmpdir=""
|
||||
|
||||
trap goodbye INT QUIT EXIT KILL TERM PIPE
|
||||
|
||||
OPTIND=1
|
||||
while getopts lhb:o:x:n: flag; do
|
||||
while getopts lhb:o:x:n:B: flag; do
|
||||
case $flag in
|
||||
h)
|
||||
usage 0;;
|
||||
|
|
@ -136,11 +170,13 @@ while getopts lhb:o:x:n: flag; do
|
|||
base=`echo $dns_domain | sed 's/\./,/g; s/\(^\|,\)/\1dc=/g'`
|
||||
;;
|
||||
x)
|
||||
exe="$OPTARG";;
|
||||
qemu_exe="$OPTARG";;
|
||||
o)
|
||||
qemu_opts="$OPTARG";;
|
||||
n)
|
||||
nic_model=",model=$OPTARG";;
|
||||
B)
|
||||
bridge=$OPTARG;;
|
||||
*)
|
||||
usage 1;;
|
||||
esac
|
||||
|
|
@ -149,12 +185,23 @@ shift $(($OPTIND - 1))
|
|||
|
||||
case $myname in
|
||||
*ifup*)
|
||||
do_sudo /sbin/ifconfig $1 up
|
||||
do_sudo $brctl addif priv0 $1
|
||||
set -x
|
||||
#[ "$1" = tap1 ] || exit 0
|
||||
#do_sudo /sbin/ifconfig tap1 up
|
||||
#do_sudo $brctl addif in1 tap0
|
||||
#do_sudo /sbin/ifconfig tap0 up
|
||||
#do_sudo $brctl addif in2 tap1
|
||||
#exit 0
|
||||
|
||||
virt_if=$1
|
||||
do_sudo /sbin/ifconfig $virt_if up
|
||||
# this is most certainly always priv0
|
||||
do_sudo $brctl addif $bridge $virt_if
|
||||
;;
|
||||
|
||||
*ifdown*)
|
||||
do_sudo $brctl delif priv0 $1
|
||||
# this is most certainly always priv0
|
||||
do_sudo $brctl delif $bridge $1
|
||||
do_sudo /sbin/ifconfig $1 down
|
||||
;;
|
||||
qemu.sh)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue