@wenshizhang
2017-01-12T17:07:54.000000Z
字数 8822
阅读 1578
vm
kvm
suse实习
hb_report
Kernel-based Virtual Machine (KVM) is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor. We know kernel pervide this support, so we need more simple tool use this support.
I choice virt-install and virt-manager
You need install those package below:
avahi
libvirt
virt-manager
virt-install
virt-viewer
python-avahi
Then restart service libvirtd
systemctl restart libvirtd
There are two ways to install VM with KVM.
This artical will introduce create VM through virt-install.
New VM need disk, wo should create virtual disk for VM, fortunally linuk have qemu disk manage tool--qemu-img. Qemu-img example under below, more informations check man page.
specific format is qcow2
qemu-img create -f qcow2 /YOUR_IMG_LOCATION/opensuse.qcow2 20G
New VM need network card, so you need create virtual network card. You can create an bridge or use default.
If you choice use network bridge,then you need create bridge with yast2.
#GUI, persistent
yast2 lan -> Network Setting -> Add bridge-> bind to physical device-> configure ip -> done
#CLI, not persistent
brctl addbr BRIDGE_NAME(say br0)
brctl addif br0 eth0(Physical device name)
ifconfiugre eth0 0.0.0.0
ifconfigure br0 up
dhclient br0
In this case you create VM need specific give network--network bridge=YOUR_BRIDGE_NAME
If you choice VM use NAT connect to internet, you should double check network default is active or not.
#check dedault is active or not
virsh net-list --all
#if not then convert to active
virsh net-start default
#this is optional ,you can convert network default to autostart
virsh net-autostart default
Network should be set to defaule when u create VM.--network default
then you can create your VM use virt-install:
#to create a VM ,you need give vm name, size of ram, number fo cpu, mirror path, disk path, network, os type and so on.
virt-install --name YOUR_VM_NAME -r 1024 -vcpus=2 --location=/YOUR_IOS_PATH/ --disk=/YOUR_VDISK_PATH/,size=YOUR_VDISK_SIZE,format=YOUR_VDISK_FORMAT --network YOUR_NETWORK_SETTINGS --os_type=linux --force
If you install virt-viewer, then you can see the install graphics interface.
Because of VM network use NAT, so I only explain the way connect to internet of this type VM.
Good news you do have to do anything, when you create VM you also create local network, but if you host cannot connect to outside same as you guests.
Any way, you create VM successfully, congratulations!
BTW, you may want to open ssh service on your VM, so you can ssh to your VM rather than open VM GUI.
#change sshd congifure
vim /etc/ssh/sshd_config
port 22
permitRootlogin yes
...
#open ssh service
systemctl enable sshd.service
systemctl start sshd.service
#change firewall setting
#I just disable the firewall
systemctl stop SuSEfirewall2
systemctl disable SuSEfirewall2
If you guest connect to outside through then you don't need to read this session.
Then you think you can ssh to your guest, acturelly, you cann't. Ssh will remind you port is already in use, you cannot bind to any address. Well, that's because NAT things.
http://xmodulo.com/access-linux-server-behind-nat-reverse-ssh-tunnel.html
This document will explain and solve your problem.
You can use virsh(CLI) or virt-manager(GUI) to manage you VM. I would like use virsh, because it looks more geek! Anyway, this session main focus on usually usage, more info please check man page.
Virsh is a command line interface tool for managing guests and the hypervisor.
The virsh tool is built on the libvirt management API and operates as an alternative to the xm tool and the graphical guest Manager(virt-manager). Unprivileged users can employ this utility for read-only operations. If you plan on running the xend, you should enable xend to run as a service. After modifying the respective configuration file, reboot the system, and xendwill run as a service. You can use virsh to load scripts for the guest machines.
Subommand | Param | Descriptions | Examples |
---|---|---|---|
list |
--inactive/--all |
Check VM status | virsh list --all |
reboot |
Domain | Reboot guest | virsh reboot Domain_name |
shutdown |
Domain | Shotdown guest | virsh shotdown Domain_name |
TODO |
The first question I met is when I create bridge for VM then host and guest both cannot connect to outside. In order to solve this this problem I try my best do everything I can, I change my netwo
The virsh tool is built on the libvirt management API and operates
as an alternative to the xm tool and the graphical guest
Manager(virt-manager). Unprivileged users can employ this utility
for read-only operations. If you plan on running the xend, you
should enable xend to run as a service. After modifying the
respective configuration file, reboot the system, and xendwill run
as a service. You can use virsh to load scripts for the guest
machines.
Subommand | Param | Descriptions | Examples |
---|---|---|---|
list |
--inactive/--all |
Check VM status | virsh list --all |
reboot |
Domain | Reboot guest | virsh reboot Domain_name |
shutdown |
Domain | Shotdown guest | virsh shotdown Domain_name |
TODO |
The first question I met is when I create bridge for VM then host
and guest both cannot connect to outside. In order to solve this
this problem I try my best do everything I can, I change my network
manager I check kernel route table...Still host cannot connect to
outside but can ping to other PC in LAN. So I have to rollback,
thanks for brtfs!
wenshizhang 文件 发布
Use KVM Create VM
vm kvm suse实习 hb_report
Environment
hosts
OS: OpenSuSE Leap 42.1
Desktop: GNOME
guest
OS: OpenSuSE Leap 42.1
Desktop: GNOME
Network: NAT
Introduce of KVM
Kernel-based Virtual Machine (KVM) is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor. We know kernel pervide this support, so we need more simple tool use this support.
I choice virt-install and virt-manager
Install virt-install/virt-mananger and related dependencies
You need install those package below:
avahi
libvirt
virt-manager
virt-install
virt-viewer
python-avahi
Then restart service libvirtd
systemctl restart libvirtd
Create VM with virt-install/virt-manager
There are two ways to install VM with KVM.
virt-install:CLI,manager VM use virsh
virt-manager:GUI,easy to operating
This artical will introduce create VM through virt-install.
New VM need disk, wo should create virtual disk for VM, fortunally linuk have qemu disk manage tool--qemu-img. Qemu-img example under below, more informations check man page.
specific format is qcow2
qemu-img create -f qcow2 /YOUR_IMG_LOCATION/opensuse.qcow2 20G
New VM need network card, so you need create virtual network card. You can create an bridge or use default.
If you choice use network bridge,then you need create bridge with yast2.
yast2 lan -> Network Setting -> Add bridge-> bind to physical device-> configure ip -> done
brctl addbr BRIDGE_NAME(say br0)
brctl addif br0 eth0(Physical device name)
ifconfiugre eth0 0.0.0.0
ifconfigure br0 up
dhclient br0
In this case you create VM need specific give network--network bridge=YOUR_BRIDGE_NAME
If you choice VM use NAT connect to internet, you should double check network default is active or not.
virsh net-list --all
virsh net-start default
virsh net-autostart default
Network should be set to defaule when u create VM.--network default
then you can create your VM use virt-install:
virt-install --name YOUR_VM_NAME -r 1024 -vcpus=2 --location=/YOUR_IOS_PATH/ --disk=/YOUR_VDISK_PATH/,size=YOUR_VDISK_SIZE,format=YOUR_VDISK_FORMAT --network YOUR_NETWORK_SETTINGS --os_type=linux --force
If you install virt-viewer, then you can see the install graphics interface.
Connect VM to outside
Because of VM network use NAT, so I only explain the way connect to internet of this type VM.
Good news you do have to do anything, when you create VM you also create local network, but if you host cannot connect to outside same as you guests.
Any way, you create VM successfully, congratulations!
BTW, you may want to open ssh service on your VM, so you can ssh to your VM rather than open VM GUI.
open ssh service
vim /etc/ssh/sshd_config
port 22
permitRootlogin yes
...
systemctl enable sshd.service
systemctl start sshd.service
systemctl stop SuSEfirewall2
systemctl disable SuSEfirewall2
then you can ssh to your VM
Manage your VM
You can use virsh(CLI) or virt-manager(GUI) to manage you VM. I would like use virsh, because it looks more geek! Anyway, this session main focus on usually usage, more info please check man page.
Virsh is a command line interface tool for managing guests and the hypervisor.
The virsh tool is built on the libvirt management API and operates as an alternative to the xm tool and the graphical guest Manager(virt-manager). Unprivileged users can employ this utility for read-only operations. If you plan on running the xend, you should enable xend to run as a service. After modifying the respective configuration file, reboot the system, and xendwill run as a service. You can use virsh to load scripts for the guest machines.
Subommand Param Descriptions Examples
list --inactive/--all Check VM status virsh list --all
reboot Domain Reboot guest virsh reboot Domain_name
shutdown Domain Shotdown guest virsh shotdown Domain_name
TODO
Questions
The first question I met is when I create bridge for VM then host and guest both cannot connect to outside. In order to solve this this problem I try my best do everything I can, I change my network manager I check kernel route table...Still host cannot connect to outside but can ping to other PC in LAN. So I have to rollback, thanks for brtfs!
+
@wenshizhang 2017-01-12 14:16 字数 阅读 0rk manager I check kernel route table...Still host cannot connect to outside but can ping to other PC in LAN. So I have to rollback, thanks for brtfs!