Enable KVM guest console through virsh: Difference between revisions

From AcrodusWiki
(Created page with "Using the virsh console [vm_name] command can be used to get a shell to the vm. This is very handy when there is no virt-manager/desktop environment or no ssh. Although you will need to get a shell up somehow. This assumes that the configuration in the xml is correct with <serial> and <console> sections. sudo systemctl status serial-getty@ttyS0 If this is not active. sudo systemctl enable serial-getty-ttyS0 and sudo systemctl start serial-getty-ttyS0 When creating...")
 
No edit summary
Line 15: Line 15:
Actually im going to add the whole shell script ive used for creating kvm guests.
Actually im going to add the whole shell script ive used for creating kvm guests.


<pre>
#!/bin/bash
#!/bin/bash


Line 38: Line 39:
         --disk          path=/dev/vg1/lv_vm_samba      \
         --disk          path=/dev/vg1/lv_vm_samba      \
         --location      /var/lib/libvirt/images/debian-12.5.0-amd64-DVD-1.iso
         --location      /var/lib/libvirt/images/debian-12.5.0-amd64-DVD-1.iso
</pre>

Revision as of 21:28, 18 November 2024

Using the virsh console [vm_name] command can be used to get a shell to the vm. This is very handy when there is no virt-manager/desktop environment or no ssh. Although you will need to get a shell up somehow.

This assumes that the configuration in the xml is correct with <serial> and <console> sections.

sudo systemctl status serial-getty@ttyS0

If this is not active.

sudo systemctl enable serial-getty-ttyS0 and sudo systemctl start serial-getty-ttyS0

When creating the virtual machine make sure that you use the config --extra-args 'console=ttyS0,115200n8 --- console==ttyS0m115200n8'

Actually im going to add the whole shell script ive used for creating kvm guests.

#!/bin/bash

#Script used to create vm's on KVM

set -e

virt-install                                                            \
        --name          vm_samba                                                \
        --os-variant    debian11                                        \
        --memory        4096                                            \
        --boot          uefi,bootmenu.enable=on,bios.useserial=on       \
        --console       pty,target.type=virtio                          \
        --serial        pty                                             \
        --extra-args 'console=ttyS0,115200n8 --- console=ttyS0,115200n8' \
        --vcpus         2                                               \
        --graphics      none                                            \
        --video         virtio                                          \
        --cpu           host                                            \
        --network       bridge=br0                                      \
        --rng           /dev/urandom                                    \
        --controller    type=scsi,model=virtio-scsi,driver.iommu=on     \
        --disk          path=/dev/vg1/lv_vm_samba       \
        --location      /var/lib/libvirt/images/debian-12.5.0-amd64-DVD-1.iso