Setup KVM with console: Unterschied zwischen den Versionen

Aus Ingos Wiki
Wechseln zu: Navigation, Suche
(create page)
 
 
Zeile 109: Zeile 109:
 
* https://www.debian.org/distrib/
 
* https://www.debian.org/distrib/
 
* https://wiki.debian.org/KVM
 
* https://wiki.debian.org/KVM
 +
[[Category:Virtualization]]

Aktuelle Version vom 19. September 2017, 23:25 Uhr

HowTo Setup KVM only with console on Debian 9 (strech)[Bearbeiten]

Author: Ingo Höft, 2017-08-10

I want to have a simple basic linux box with KVM but without graphics and not needed components. So I avoid side effects on testing and can increase its functionality step by step and use it as server (host) for virtual machines only with command line administration as usual for server. For this I always use 'apt install' with option --no-install-recommends so I can decide what I realy need. I simplify this as default for apt-get with:

echo APT::Install-Recommends \"false\"\; > /etc/apt/apt.conf.d/99install-recommends

You need a CPU with virtualization.

I use LVM so I can easy try and error with installations and revert to a clean tested snapshot. For reference here my most used commands:

~$ sudo lvcreate -n snap -s vmhost-vg/root -L 10G   #create snapshot
~$ sudo lvconvert --merge vmhost-vg/snap            #revert to snapshot
~$ sudo lvremove vmhost-vg/snap                     #commit installation

Host Setup[Bearbeiten]

Install a basic system from installation medium in textmode, e.g. from CD-ROM or USB-Stick etc. without Desktop and any graphical environment. That means on tasksel only select "standard system utilities".

   [ ] Debian desktop environment
   [ ] ... GNOME
   [ ] ... Xfce
   [ ] ... KDE
   [ ] ... Cinnamon
   [ ] ... MATE
   [ ] ... LXDE
   [ ] web server
   [ ] print server
   [ ] SSH server
   [*] standard system utilities

After this we have a simple running linux box with console and no graphics.

For my network I setup some additional features like uvesafb (if needed) for better screen output, ssh, sssd, kerberos, nfs4. Install what you need but no xserver-xorg.

Install KVM:

~$ sudo apt --no-install-recommends install qemu-utils qemu-kvm \
            libvirt-clients dnsmasq-base ebtables libvirt-daemon-system \
            virtinst libosinfo-bin firewalld

In particular this will prevent virtinst to install not needed virt-viewer with big overhead for graphics vnc connection to client. Check if you like with: (not needed, information only)

~$ apt --simulate install virt-viewer | less

For system wide installations

~$ export LIBVIRT_DEFAULT_URI=qemu:///system

I put this in .bashrc.

In order to be able to manage virtual machines as regular user, that user needs to be added to some groups:

~$ sudo adduser <youruser> libvirt
~$ sudo adduser <youruser> libvirt-qemu

Guest Setup[Bearbeiten]

Now install your first simple guest debian9 (stretch) with console setup.

Before starting guest installation get rows and columns from your screen on the host. We will need that later. And start the default network if its not running.

~$ stty --all
speed 38400 baud; rows 64; columns 160; line = 0; (example)
...
~$
~$ virsh net-start default
( may also use
~$ virsh net-autostart default )

Install the guest:

~$ virt-install --virt-type kvm \
                --cpu kvm64 \
                --name base \
                --location https://ftp.de.debian.org/debian/dists/stretch/main/installer-amd64/ \
                --os-variant debian9 \
                --extra-args "console=ttyS0" \
                --graphics none \
                --disk size=4 \
                --memory 512 \
;

You may use '--cpu host' for better performance, but may cause issues if migrating the guest to a host without an identical CPU. Show supported CPU models with:

~$ virsh cpu-models x86_64

The installation program of the guest should come up in text mode now and you can complete installation on the guest as usual. I also install only 'standard system utilities' for testing. On reboot on grub boot menu hit 'e', append kernel parameter 'console=ttyS0' and boot with F10.

Login to guest and first set

~$ stty rows 64 columns 160 (or what yours is)
~$

Then next set /etc/default/grub to

GRUB_CMDLINE_LINUX_DEFAULT="quiet console=ttyS0"

Don't forget update-grub.


References[Bearbeiten]