Spinning up VMs remotely on Ubuntu Server

Also adding a serial console allows you cli access from the VM server:

These are for Ubuntu, change as required for other variants
In the vm guest edit /etc/default/grub to read:
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"

Copy /etc/init/tty1.conf to /etc/init/ttyS0.conf changing the last line to read:


exec /sbin/getty -8 115200 ttyS0 xterm


Run:
enable ttyS0
start ttyS0

On systemd based systems (i.e Ubuntu 16.04) change the second part for:
Create /lib/systemd/system/ttyS0.service with contents:


[Unit]
Description=Serial Console Service

[Service]
ExecStart=/sbin/getty -L 115200 ttyS0 xterm
Restart=always
[Install]

WantedBy=multi-user.target


Run:
systemctl enable ttyS0
systemctl start ttyS0

You should now have console access from virsh using virsh console [vmname]
You will also be able to reboot from virsh and reattach to the console in time to see the grub prompt and boot loading messages. If your vm doesn't require a graphical terminal this should negate the need to use Spice/VNC

Sorry it's not exactly a tutorial, just writing this quickly from memory combined with grep config files.

1 Like

Alright so i ran through some stuff with creating Virtual Machines on command line and ran into some issues when vm is being installed and could not get to install interface through vnc or virt-viewer. Does anyone have a good overall tutorial for command line come up with a better overall guide that runs you through start to finish?
I'm using Fedora 25 server and there official guides don't run through command line very well and i looked through man pages and google and i guess I just need some hand holding to help me out.

Edit-- I seem to have found a better tutorial and see that my other tutorials I was missing some arguments which cant test now cause i got mad and shutdown my server remotely.

You can set up OpenVPN on your Ubuntu server and push routes for your virtual network with your VMs to yourself, you can now have direct VNC access to your VMs, you can forward your ports with iptables, would that work for you?

I use a VPN to remotely get to server through ssh so i don't have to worry about open ports except for vpn. I also use my vpn for files etc.

OK so i failed. Basically when I use virt-install to begin a ubuntu vm and connect to it through tigervnc over my vpn to my house where server is i get a connection refused. I have disabled firewall and Selinux. I can ping the ip address that the vm gets through dhcp. Any ideas?
sudo virt-install --name Unifi --os-type linux --ram 1024 --vcpus=1 --disk path=/Tank/Unifi/unifi.img --graphics vnc --cdrom /Tank/ISO/ubuntu16.iso --bridge br0