i3 NUC as KVM server running Slackware
This is my new KVM server:
- Intel Next Unit of Computing Kit D34010WYKH - Barebone - UCFF - Mobile Intel QS77 Express - 1 x Core i3 4010U / 1.7 GHz - HD Graphics 4400 - GigE
- Samsung 840 EVO MZ-7TE120 - Solid state drive - 120 GB - internal - 2.5" - SATA 6Gb/s
- Kingston ValueRAM - DDR3L - 8 GB - SO DIMM 204-pin - 1600 MHz / PC3-12800 - CL11 - 1.35 V
This NUC has been a demo model which I could buy for a friendly price from a friendly supplier.
Like all NUC's, there is no VGA output, only HDMI. This particular NUC has a mini-HDMI connector. In order to put Linux on to it, I first had to buy a mini-HDMI to HDMI adapter.
NUC systems require just a small amount of electrical power, so using one as an KMV-server to replace several real hardware servers is increasing your electricity efficiency.
The i3 processor allows for running a real hypervisor, so the virtual machines will fly at almost native speed.
Back to Slackware
Because systemd is imho not the Unix way to go, and the current Debian version is based on systemd, I preferred not to install Debian as host OS on this box.
In the '90-ies I used to run Slackware on my boxes without any problems so I decided to give Slackware a change as host OS.
KVM requires a 64bits version of the Linux kernel, so I choose to install Slackware64.
There is no need to install the full Slackware64 distribution, only several packages of the A, AP, L and N series are required.
Compile and install qemu
Download qemu from qemu.org, I downloaded qemu-2.2.1.tar.bz2.
Configure without need for X (no need for it on a headless server).
./configure --prefix=/opt/qemu-2.2.1 --disable-gtk make make install ln -s /opt/qemu-2.2.1 /opt/qemu-latest
This way qemu is installed in /opt/qemu-2.2.1 with a symlink to /opt/qemu-latest.
I have the following setup:
- /opt/qemu-latest/bin : qemu binaries
- /opt/qemu-latest/vm : images for the virtual machines
- /opt/qemu-latest/scripts : scripts for starting virtual machines
( There are also directories like /opt/qemu-latest/share that were created by running make install. )
Create ifup and ifdown scripts
#!/bin/sh /usr/sbin/openvpn --mktun --dev $1 --user `id -un` /sbin/ifconfig $1 0.0.0.0 promisc up /usr/sbin/brctl addif br0 $1
#!/bin/sh brctl delif br0 $1 /usr/sbin/openvpn --rmtun --dev $1
Yes, it uses /usr/sbin/openvpn to create and destroy the tun devices. This was quite a surprise, but it works [tm].
Setup network bridge
Edit the file rc.inet1.conf to setup the bridge.
Change the lines about eth0:
# Config information for eth0: IPADDR="" NETMASK="" USE_DHCP="" DHCP_HOSTNAME=""
And the lines about br0:
IFNAME="br0" BRNICS="eth0" IPADDR="192.168.1.2" NETMASK="255.255.255.0" USE_DHCP="" DHCP_HOSTNAME=""
Keep the line about the gateway unchanged:
# Default gateway IP address: GATEWAY="192.168.1.1"
Restart networking to aply the changes:
Check the network configuration with the command ifconfig.
Run virtual machines
This is how I start my vm's:
qemu-system-x86_64 \ -vnc 192.168.1.2:1 \ -cpu qemu64 \ -m 512 \ -net nic,vlan=0,model=virtio \ -net tap,vlan=0,ifname=tap0 \ -enable-kvm \ --drive file=/opt/qemu-latest/vm/imageone.img,if=virtio,index=1,media=disk \ --drive file=/opt/qemu-latest/vm/imagetwo.img,if=virtio,index=2,media=disk
This is an example of a vm with two discs (running a Raid-1 vm as a development and testing method for preparing a "real iron" machine which will get two real discs in Raid-1).
-vnc 192.168.1.2:1 is so I can have vnc-connection to the console of the
vm, and expects the kvm-server to run on ip-address 192.168.1.2. If your server runs on
a different ip-adress, then change this line accordingly.
Protect the SSD against wear
- Mount SSD partitions with options noatime,discard.
- Mount /var/log and /home in RAM (tmpfs)