2010年1月14日木曜日

Fedoraでmini2440のQemu環境構築

① sudoの時、PATHが変わってしまうので、下記の命令が.bashrcに追加して解決できた。
alias sudo='sudo env PATH=$PATH'

② Qemuを使う前、bridgeの設定がバッチファイルにまとめ
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: `basename $0` {network interface name}."
exit
fi

# get ipaddress from ifconfig
IPADDR=`/sbin/ifconfig $1 | grep "inet addr" | awk '{ print $2}' | awk 'BEGIN { FS=":" } {print $2}'`
# get netmask from ifconfig
NETMASK=`/sbin/ifconfig $1 | grep "Mask" | awk '{ print $4}' | awk 'BEGIN { FS=":" } {print $2}'`

if [ -z $IPADDR ]; then
echo "Not found the ip address"
exit
elif [ -z $NETMASK ]; then
echo "Not found the netmask"
exit
fi

sudo /sbin/ifconfig br0 down
sudo /usr/sbin/brctl delbr br0
sudo /usr/sbin/brctl addbr br0
sudo /usr/sbin/brctl addif br0 $1
sudo /sbin/ifconfig br0 up
sudo /sbin/ifconfig $1 0.0.0.0 up
sudo /sbin/ifconfig br0 $IPADDR netmask $NETMASK

③起動と終了のスクリプト
[arm@localhost images]$ more ~/tools/qemu-ifup
#! /bin/sh
/sbin/ifconfig $1 0.0.0.0 promisc up
/usr/sbin/brctl addif br0 $1

[arm@localhost images]$ more ~/tools/qemu-ifdown
#! /bin/sh
/usr/sbin/brctl delif br0 $1
/sbin/ifconfig $1 down

④Qemuの命令が長いので、バッチファイルを作ろう
#! /bin/sh
METHOD=$1
SCRIPTPATH="/home/arm/tools"
SCRIPT="$SCRIPTPATH/qemu-ifup"
DOWNSCRIPT="$SCRIPTPATH/qemu-ifdown"
NETFLAG="-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=$SCRIPT,downscript=$DOWNSCRIPT "

if [ $METHOD == "file" ]; then

MACHINE=$4
KERNEL=$2
ROOTFS=$3
EXPECTED_ARGS=3

if [ $# -ge $EXPECTED_ARGS ]; then

if ! [ -f "$KERNEL" ];then
echo "not found kernel file"
exit
elif ! [ -f "$ROOTFS" ];then
echo "not found rootfs file"
exit
elif [ -z "$MACHINE" ];then
MACHINE=versatileab

fi

qemu-system-arm -M $MACHINE -kernel $KERNEL -append root=/dev/sda1 $ROOTFS $NETFLAG
exit
fi

elif [ $METHOD == "nfs" ]; then

MACHINE=$5
NFSPATH=$4
KERNEL=$2
HOSTIP=$3
EXPECTED_ARGS=4

if ! [ -f "$KERNEL" ];then
echo "not found kernel file"
exit
elif [ -z "$MACHINE" ];then
MACHINE=versatileab
fi

qemu-system-arm -M $MACHINE -kernel $KERNEL -append root="/dev/nfs nfsroot=$HOSTIP:$NFSPATH rw ip=dhcp" $NETFLAG
exit
fi

echo "Usage: `basename $0` (file/nfs) Kernel (Rootfs/(Hostip Nfspath) [Machine]"


0 件のコメント:

コメントを投稿