mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-23 22:40:38 +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`
|
goodbye()
|
||||||
dirname=`dirname $0`
|
{
|
||||||
macaddr=00:0B:DC:9B:D6:DA
|
rm -f $tmp_files
|
||||||
base=dc=priv,dc=lcl
|
}
|
||||||
exe=qemu-kvm
|
|
||||||
qemu_opts=""
|
|
||||||
brctl=`PATH=/usr/sbin:/sbin /usr/bin/which brctl`
|
|
||||||
#nic_model=",model=rtl8139"
|
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
|
@ -21,6 +17,11 @@ EOT
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log()
|
||||||
|
{
|
||||||
|
echo "=========================== $*"
|
||||||
|
}
|
||||||
|
|
||||||
err()
|
err()
|
||||||
{
|
{
|
||||||
echo $* >&2
|
echo $* >&2
|
||||||
|
|
@ -68,20 +69,30 @@ boot_net()
|
||||||
sed '/dhcpHWAddress:/ !d; s/dhcpHWAddress: ethernet *//'`
|
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 dhcpd || /etc/init.d/dhcpd start
|
||||||
ps aux | grep -v grep | grep -q nfsd || /etc/init.d/nfsserver start
|
ps aux | grep -v grep | grep -q nfsd || /etc/init.d/nfsserver start
|
||||||
|
|
||||||
[ "$nic_model" ] || nic_model=",model=e1000"
|
[ "$nic_model" ] || nic_model=",model=e1000"
|
||||||
# need this for net access, would be nicer if it didn't run as root
|
# need this for net access, would be nicer if it didn't run as root
|
||||||
# -nographic
|
# -nographic
|
||||||
do_sudo -E /usr/bin/$exe \
|
|
||||||
|
do_sudo -E /usr/bin/$qemu_exe \
|
||||||
-boot n \
|
-boot n \
|
||||||
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
||||||
-net nic,vlan=0$nic_model,macaddr=$macaddr \
|
-net nic,vlan=0$nic_model,macaddr=$macaddr \
|
||||||
"$qemu_opts"
|
"$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()
|
boot_image()
|
||||||
|
|
@ -89,24 +100,29 @@ boot_image()
|
||||||
local boot_image="$1"
|
local boot_image="$1"
|
||||||
|
|
||||||
test -r "$boot_image" || fatal "inaccessible boot image \"$boot_image\""
|
test -r "$boot_image" || fatal "inaccessible boot image \"$boot_image\""
|
||||||
|
#-net bridge,br=$bridge \
|
||||||
|
|
||||||
xhost +
|
do_sudo -E /usr/bin/$qemu_exe \
|
||||||
do_sudo -E /usr/bin/$exe \
|
-net nic,vlan=0$nic_model,macaddr=00:02:36:22:13:6b \
|
||||||
-net tap,ifname=tap0,vlan=0,script=$tmpdir/qemu-ifup,downscript=$tmpdir/qemu-ifdown \
|
-net nic,vlan=1$nic_model,macaddr=00:02:36:22:13:6c \
|
||||||
-net nic,vlan=0$nic_model,macaddr=$macaddr \
|
-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" \
|
"$qemu_opts" \
|
||||||
-drive format=raw,file=$boot_image
|
-drive format=raw,file=$boot_image
|
||||||
}
|
}
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
{
|
{
|
||||||
local tmpdir=`mktemp -d /tmp/$myname""_XXXXXX`
|
tmpdir=`mktemp -d /tmp/$myname""_XXXXXX`
|
||||||
(
|
(
|
||||||
cd $tmpdir
|
cd $tmpdir
|
||||||
ln -s $0 qemu-ifup
|
ln -s $exe qemu-ifup
|
||||||
ln -s $0 qemu-ifdown
|
ln -s $exe qemu-ifdown
|
||||||
)
|
)
|
||||||
|
|
||||||
|
do_sudo /sbin/modprobe kvm-intel
|
||||||
|
xhost +
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
net)
|
net)
|
||||||
boot_net
|
boot_net
|
||||||
|
|
@ -121,8 +137,26 @@ boot()
|
||||||
|
|
||||||
# -- here we go
|
# -- 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
|
OPTIND=1
|
||||||
while getopts lhb:o:x:n: flag; do
|
while getopts lhb:o:x:n:B: flag; do
|
||||||
case $flag in
|
case $flag in
|
||||||
h)
|
h)
|
||||||
usage 0;;
|
usage 0;;
|
||||||
|
|
@ -136,11 +170,13 @@ while getopts lhb:o:x:n: flag; do
|
||||||
base=`echo $dns_domain | sed 's/\./,/g; s/\(^\|,\)/\1dc=/g'`
|
base=`echo $dns_domain | sed 's/\./,/g; s/\(^\|,\)/\1dc=/g'`
|
||||||
;;
|
;;
|
||||||
x)
|
x)
|
||||||
exe="$OPTARG";;
|
qemu_exe="$OPTARG";;
|
||||||
o)
|
o)
|
||||||
qemu_opts="$OPTARG";;
|
qemu_opts="$OPTARG";;
|
||||||
n)
|
n)
|
||||||
nic_model=",model=$OPTARG";;
|
nic_model=",model=$OPTARG";;
|
||||||
|
B)
|
||||||
|
bridge=$OPTARG;;
|
||||||
*)
|
*)
|
||||||
usage 1;;
|
usage 1;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -149,12 +185,23 @@ shift $(($OPTIND - 1))
|
||||||
|
|
||||||
case $myname in
|
case $myname in
|
||||||
*ifup*)
|
*ifup*)
|
||||||
do_sudo /sbin/ifconfig $1 up
|
set -x
|
||||||
do_sudo $brctl addif priv0 $1
|
#[ "$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*)
|
*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
|
do_sudo /sbin/ifconfig $1 down
|
||||||
;;
|
;;
|
||||||
qemu.sh)
|
qemu.sh)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue