现在的位置: 首页 > 综合 > 正文

Gentoo 系统 KVM 桥接 tap 启动脚本

2013年10月06日 ⁄ 综合 ⁄ 共 907字 ⁄ 字号 评论关闭

Gentoo 启动 init 机制不同于 Debian 和 Redhat, 具体细节尚未总结。

现备份一 KVM tap 启动脚本:kvm_net

#!/sbin/runscript
# Copyright chencheng use kvm
# Distributed under the terms of the GNU General Public License v2
# $Header: $

user_id=999
dev_num=3

depend() {
    need net.br0
    need modules
}


start() {
    ebegin "Start kvm-net"
    /sbin/modprobe kvm-intel
    #tapx=`tunctl -u nehc|awk '{print $2}'|cut -c 2,3,4,5`
    for((i=0;i<${dev_num};i++))
    do
        tapx=`/usr/bin/tunctl -b -u ${user_id}`
        brctl addif br0 ${tapx}
        ifconfig ${tapx} promisc up
        echo "${tapx} ready now! "
    done
    eend $?
}

stop() {
    ebegin "Stop kvm-net"
    for((i=0;i<${dev_num};i++))
    do
        brctl delif br0 tap$i
        ifconfig tap$i down
        tunctl -d tap$i
    done
    /sbin/modprobe -r kvm-intel
    eend $?
}

restart() {
    stop
    start
}

启动脚本不同于普通脚本在于可以:rc-update add kvm-net 将 kvm-net 加入运行级别

另外,贴一 kvm 脚本:start_kvm

#!/bin/bash
# created by chencheng
# use it to start virtual machine 
# $1 refer machine name
# $2 refer tap name
kvm -net nic,macaddr=00:00:00:00:00:00 -net tap,ifname=$2,script=no,downscript=no -m 300 /home/nehc/vms/$1/$1.img -daemonize
      

这个就简单啦 ....

抱歉!评论已关闭.