1. 启动或重启libvirtd服务和messagebus 服务html
/etc/init.d/libvirtd start
/etc/init.d/messagebus restart
查看网络接口列表linux
brctl show
结果以下centos
bridge name bridge id STP enabled interfaces
br0 8000.000c29ce99ea no eth0
virbr0 8000.5254008af910 yes virbr0-nic网络
2.建立虚拟机spa
挂载分区rest
fdisk -lfdisk /dev/sdb
n
p
1
1
回车
p
w
mkfs.ext4 /dev/sdb1
mkdir /data
mount /dev/sdb1 /data
vi /etc/fstab
/dev/adb1 /data ext4 defaults 0 0
mkdir /data/kvm
virt-install --name denny1 --ram 512 --disk path=/data/denny1.img,size=30 --vcpus 1 --os-type linux --os-variant rhel6 --network bridge=br0 --graphics none --console pty,target_type=serial --location 'http://mirrors.163.com/centos/6.7/os/i386/' --extra-args 'console=ttyS0,115200n8 serial'
--name 指定虚拟机的名字
--ram 指定内存分配多少
--disk path 指定虚拟磁盘放到哪里,size=30 指定磁盘大小为30G,这样磁盘文件格式为raw,raw格式不能作快照,后面有说明,须要转换为qcow2格式,若是要使用qcow2格式的虚拟磁盘,须要事先建立qcow2格式的虚拟磁盘。 参考 http://www.361way.com/kvm-qcow2-preallocation-metadata/3354.html 示例:qemu-img create -f qcow2 -o preallocation=metadata /data/test02.img 7G; --disk path=/data/test02.img,format=qcow2,size=7,bus=virtio
--vcpus 指定分配cpu几个
--os-type 指定系统类型为linux
--os-variant 指定系统版本
--network 指定网络类型
--graphics 指定安装经过哪一种类型,能够是vnc,也能够没有图形,在这里咱们没有使用图形直接使用文本方式
--console 指定控制台类型
--location 指定安装介质地址,能够是网络地址,也能够是本地的一个绝对路径,(--location '/mnt/', 其中/mnt/下就是咱们挂载的光盘镜像mount /dev/cdrom /mnt)若是是绝对路径,那么后面还须要指定一个安装介质,好比NFS,假如虚拟机设置ip后,不能连外网,那么就会提示让咱们选择安装途径:code
┌────────┤ Choose a Language ├──────────┐
│ │
│ What language would you like to use │
│ during the installation process? │
│ │
│ Catalan ↑│
│ Chinese(Simplified) ▒│
│ Chinese(Traditional) ▮. │orm
│ Croatian ▒ │
│ Czech ▒ │
│ Danish ▒ │
│ Dutch ▒ │
│ English ↓ │
│ │
│ ┌────┐ │
│ │ OK │ │
│ └────┘ │
│ │
│ │
└───────────────────────────────────┘htm
English -- ipv4 Manual configuration blog
IPv4 address: 192.168.1.116___ / 255.255.255.0___Gateway: 192.168.1.1______________________________Name Server: 8.8.8.8__________________________________