2,187
edits
(Added Move Virtual Machine) |
m (→Create Workstation (GUI): Added note on cancelling he command) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 83: | Line 83: | ||
--cdrom=/mnt/md0/kvm/iso/ubuntu-16.04.3-desktop-amd64.iso \ | --cdrom=/mnt/md0/kvm/iso/ubuntu-16.04.3-desktop-amd64.iso \ | ||
--network=bridge=br0,model=virtio \ | --network=bridge=br0,model=virtio \ | ||
--graphics vnc \ | --graphics vnc,listen=0.0.0.0 \ | ||
--disk path=/mnt/md0/kvm/vm/ubuntu-desktop.img,size=40,bus=virtio | --disk path=/mnt/md0/kvm/vm/ubuntu-desktop.img,size=40,bus=virtio | ||
</pre> | </pre> | ||
Once the command has got as far as <code>Waiting for installation to complete.</code> you need to connect to the VNC console session, to find the port number to connect on query the config from | Once the command has got as far as <code>Waiting for installation to complete.</code> you need to connect to the VNC console session, to find the port number to connect on query the config from ''another'' SSH session connected to the host (typically VNC uses ports starting from 5900 upwards). Cancelling the command causes the VM/domain to power off, which you won't want to happen until you've completed setup of the VM. | ||
virsh dumpxml ubuntu-desktop | grep vnc | virsh dumpxml ubuntu-desktop | grep vnc | ||
Line 101: | Line 101: | ||
# Update the config, if necessary... | # Update the config, if necessary... | ||
#* Disk file path - If the VM disks are in a different path on the new server up date the path in the XML file, look for <code>source file=</code> | #* Disk file path - If the VM disks are in a different path on the new server up date the path in the XML file, look for <code>source file=</code> | ||
#* CPU type - If the physical CPU type is different on the new host, you may need to update the VM config to allow for this, update the <code>cpu mode</code> config to match the capabilities of the destination host | #* CPU type - If the physical CPU type is different on the new host, you may need to update the VM config to allow for this, update the <code>cpu mode</code> config to match the capabilities of the destination host, or just set to <code><cpu mode='host-passthrough'/></code>. See https://www.berrange.com/posts/2018/06/29/cpu-model-configuration-for-qemu-kvm-on-x86-hosts/ for more info. | ||
# Import the VM | # Import the VM | ||
#* EG <code> virsh define /path/to/VMName.xml </code> | #* EG <code> virsh define /path/to/VMName.xml </code> | ||
Line 107: | Line 107: | ||
#* EG <code> virsh start <VMName> </code> | #* EG <code> virsh start <VMName> </code> | ||
== Add Disk == | |||
# Create new disk image file | |||
#* EG <code> qemu-img create -f qcow2 /var/lib/libvirt/images/vm-name-disk1.img 20G </code> | |||
# Attach disk image to virtual machine | |||
#* Use <code>df</code> in the VM to determine next disk label, eg <code>vdb</code> | |||
#* EG <code> qemu-img create -f qcow2 /var/lib/libvirt/images/vm-name-disk1.img 20G -o preallocation=full </code> | |||
#** To create a thin provisioned file use the following (however you may find the disk the OS sees is small (~200K), if so, use the command above) | |||
#** EG <code> virsh attach-disk vm-name /var/lib/libvirt/images/vm-name-disk1.img vdb --cache none </code> | |||
# Update file owner and group to match other disk images | |||
#* EG <code> chown libvirt-qemu /var/lib/libvirt/images/vm-name-disk1.img </code> | |||
#* EG <code> chgrp libvirt-qemu /var/lib/libvirt/images/vm-name-disk1.img </code> | |||
# Attach disk | |||
#* EG <code> virsh attach-disk --domain vm-name /var/lib/libvirt/images/vm-name-disk1.img --target vdb --persistent --config --live </code> | |||
# In the VM, format the disk using defaults.. | |||
#* EG <code> fdisk /dev/vdb </code> | |||
#** EG <code>Command: n </code> | |||
#** EG <code>Partition type: p, </code> | |||
#** EG <code>Partition number: <default>, </code> | |||
#** EG <code>First sector: <default> </code> | |||
#** EG <code>Last sector: <default> </code> | |||
#** EG <code>Command: w </code> | |||
# Format new partition | |||
#* EG <code> mkfs.ext4 /dev/vdb1 </code> | |||
# Create mount directory | |||
#* EG <code> mkdir /vdb1/ </code> | |||
# Mount the the disk | |||
#* EG <code> mount /dev/vdb1 /vdb1/ </code> | |||
# Add an appropriate entry to fstab so the disk gets mounted on next boot | |||
#* EG <code> /dev/vdb1 /vdb1 ext4 defaults 0 0 </code> | |||
== Other Config == | == Other Config == | ||
Line 115: | Line 144: | ||
To disable issue | To disable issue | ||
virsh autostart vm-name --disable | virsh autostart vm-name --disable | ||
[[Category:KVM]] | [[Category:KVM]] |