Difference between revisions of "Virtual Machine (KVM)"

Jump to navigation Jump to search
m (→‎Create Workstation (GUI): Added listen=0.0.0.0 to graphics so VNC listens on more than just loopback)
 
(4 intermediate revisions by the same user not shown)
Line 43: Line 43:


=== Create Server (no GUI) ===
=== Create Server (no GUI) ===
Update paths to reflect where install ISO, and where VM disk files are intended to be.   
Update <code>location</code> path to reflect where your install ISO is located, and the <code>disk</code> path for where VM disk files are intended to be.   


The <code>--extra-args "console=ttyS0"</code> option allows a local console to be accessed from the host machine (to allow OS install etc before the VM is on a network), though note that it can't be used with <code>--cdrom</code>, so <code>--location</code> has been used instead.
The <code>--extra-args "console=ttyS0"</code> option allows a local console to be accessed from the host machine (to allow OS install etc before the VM is on a network), though note that it can't be used with <code>--cdrom</code>, so <code>--location</code> has been used instead.  Note that where installing Ubuntu guests v22.04 and upwards the kernel and initrd paths on the ISO need to be specified with the ISO location.


<pre>
<pre>
virt-install \
virt-install \
--virt-type=kvm \
--virt-type=kvm \
--name server-name \
--name ubuntu22-vm \
--ram 1024 \
--ram 2048 \
--vcpus=1 \
--vcpus=1 \
--os-variant=ubuntu16.04 \
--os-variant=ubuntu16.04 \
--network=bridge=br0,model=virtio \
--network=bridge=br0,model=virtio \
--graphics none \
--graphics none \
--disk path=/mnt/md0/kvm/vm/server-name.img,size=20,bus=virtio \
--disk path=/mnt/md0/kvm/vm/ubuntu22-vm.img,size=20,bus=virtio \
--extra-args "console=ttyS0" \
--extra-args "console=ttyS0" \
--location /mnt/md0/kvm/iso/ubuntu-16.04.3-server-amd64.iso
--location ubuntu-22.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd
</pre>
</pre>


You should be presented with the console of the VM as it installs, however if you lose connection etc, connect to the console of the server using <code>virsh console <server-name></code>.  Make sure you set a static IP and install SSH during setup (select '''OpenSSH server''' during ''Software selection'' section). Once installation is completed, SSH to the server and setup normal console access (as the instructions in the section below).  Its highly recommended that you follow the steps below to ensure that Console access is available via the KVM host if needed.
You should be presented with the console of the VM as it installs, however if you lose connection etc, connect to the console of the server using <code>virsh console <server-name></code>.  Make sure you set a static IP and install SSH during setup (select '''OpenSSH server''' during ''Software selection'' section). Once installation is completed, SSH to the server and setup normal console access (as the instructions in the section below).  Its highly recommended that you follow the steps below to ensure that Console access is available via the KVM host if needed.
==== Eject CD-ROM ====
If you need to eject the CD-ROM towards the end o the installation process, first identify the disk target name (eg hda, hdb, etc) then eject
virsh edit server-name
virsh change-media server-name hda --eject


==== Console Access ====
==== Console Access ====
Line 87: Line 92:
</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 anothet SSH session connected to the host (typically VNC uses ports starting from 5900 upwards).
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 144: Line 149:
To disable issue
To disable issue
  virsh autostart vm-name --disable
  virsh autostart vm-name --disable
To see what machines are/aren't set to start automatically
virsh list --all --autostart
virsh list --all --no-autostart




[[Category:KVM]]
[[Category:KVM]]

Navigation menu