Friday, June 25, 2021

Linux KVM

 ======bridge========
brctl addif br0 p3p2
brctl addif br1 em1
ifdown br1
ifup br1

========create VM=======

Convert disk:
qemu-img convert -O qcow2 venice-disk1.vmdk psm.qcow2

Booting from an existing qcow2 image
virt-install \
  --name MyImportedVM \
  --description "Imported virtual machine" \
  --graphics vnc,listen=0.0.0.0 \
  --noautoconsole \  
  --os-type=linux \
  --memory 8192 \
  --vcpus=4 \
  --disk path=/var/lib/libvirt/images/importedVM.qcow2,bus=virtio\
  --boot hd \
  --network bridge:br0,model=virtio


Building a new Windows VM
Windows can be difficult on KVM because it doesn't ship with Virtio drivers. Using the non-virtio disk and network emulation is comparatively slow. Things are made harder because virt-install doesn't let you use --cdrom twice. To mount two iso files at once (so virtio drivers can be installed), use the --disk argument with device=cdrom. Also be sure to use bus=ide so Windows can read it before installing the virtio drivers.

The virtio drivers can be downloaded here

virt-install \
  --name Server2019 \
  --description "Windows Server 2019 Template" \
  --os-type=windows \
  --memory 8192 \
  --vcpus=4 \
  --disk path=/var/lib/libvirt/images/windows2019.qcow2,bus=virtio,size=30 \
  --disk /var/lib/libvirt/isos/WindowsServer2019StandardCore_1909.iso,device=cdrom,bus=ide \
  --disk /var/lib/libvirt/isos/virtio-win.iso,device=cdrom,bus=ide \
  --graphics vnc,listen=0.0.0.0 \
  --noautoconsole \
  --network bridge=br0,model=virtio


When installing the OS through your VNC viewer, no drives will show up.
Click the "Load Driver" button, and browse to the virtio iso that was mounted.
Expand the viostor folder and choose your OS. Click the amd64 subdirectory. Click OK.
RedHat VirtIO SCSI Controller should show up, click Next
Finish the install,Once the install finishes the server will turn off.


[root@localhost ~]# virsh console study01  
[root@localhost ~]# virsh start study01  
[root@localhost ~]# virsh shutdown study01  

#force stop
[root@localhost ~]# virsh destroy study01  

# destroy but keep the qcow2 virtual disk
[root@localhost ~]# virsh undefine study01  

[root@localhost ~]# virsh autostart study01  
[root@localhost ~]# virsh autostart --disable study01 
[root@localhost ~]# virsh suspend study01 
[root@localhost ~]# virsh resume study01 

virsh net-edit default
virsh net-edit somenet
virsh net-destroy somenet
virsh net-start somenet


virt-install   --name PSM   --description "PNSO PSM"   --graphics vnc,listen=0.0.0.0   --noautoconsole   --os-type=linux   --memory 8192   --vcpus=8   --disk path=/root/psm/psm.qcow2,bus=virtio  --boot hd   --network bridge:br0,model=virtio

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.