创建镜像文件:
qemu-img create -f qcow2 1.qcows 40G
用镜像启动虚拟机,安装操作系统:
/usr/libexec/qemu-kvm -m 1024 -hda 1.qcow2 -boot d -cdrom /root/CentOS-6.5-x86_64-minimal.iso -net nic,macaddr=3C:C2:F0:0A:32:0A -vnc :1 -localtime &
安装操作系统步骤省略,关闭装好的系统,添加网络启动:
#!/bin/bash script_path=`dirname "$0"` /usr/libexec/qemu-kvm -m 2048 -hda ${script_path}/1.qcow2 -cpu host -smp core=4,threads=2,socket=4 -net nic,model=rtl8139,macaddr=3C:C2:F0:0A:32:0A -net tap,ifname=tap1,script=${script_path}/ifup.sh -vnc :1 -localtime &
ifup.sh脚本内容:
#!/bin/bash switch=br0 if [ -n "$1" ];then /sbin/ip link set $1 up sleep 0.5s /usr/sbin/brctl addif $switch $1 exit 0 else echo "Error: no interface specified" exit 1 fi
启动虚拟机:
bash /home/virt-machine/virt-01/startup.sh
加入开机启动:
echo ‘/bin/bash /home/virt-machine/virt-01/startup.sh‘ >> /etc/rc.local
ls /home/virt-machine/virt-01/ 1.qcow2 ifup.sh startup.sh
目前只懂对1.qcow2扩容,还没研究出对指定分区扩容,建议在分区时候使用逻辑卷分区,这样扩容就简单一点。
扩容参考:http://www.educity.cn/wenda/579936.html
qemu-kvm
时间: 2024-11-06 07:28:02