Skip to main content

Base vm server setup

Create a VM

On the hypervisor run the following command:

sudo virt-install --connect qemu:///system \
--network=bridge:VMnetwork \
--initrd-inject="/home/jeremy/ks.cfg" \
--extra-args="ks=file:/ks.cfg console=ttyS0" \
-n $serverName \
-f /home/imgs/$serverName.img \
-r 1024 \
-s 12 \
--location=/home/isos/CentOS-7-x86_64-DVD-1908.iso \
--os-type=centos7.0 \
--accelerate --hvm --graphics none
note

This tutorial assumes ssh has been enabled via the kickstart file.

Configure VM

Change hostname

Change the hostname to something easy to remember and meaningful. For example, if the vm is hosting foreman name it foreman.internal.virtnet.

sudo hostnamectl set-hostname new-hostname.internal.virtnet

Give the vm a quick reboot to ensure changes are set:

sudo halt --reboot

Set IP address

First, get the interface that the vm is using to communicate externally:

ip addr

Most likely this will be eth0.

Now add the following content to the interface config file (be sure to sudo!):

/etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO="static" #Switch to static IP
IPADDR=172.16.0.10 #Set the IP address.
NETMASK=255.255.0.0 #Subnet mask
NETWORK=172.16.0.0 #Network ID
GATEWAY=172.16.0.2 #Gateway
BROADCAST=172.16.255.255 #Broadcast
DNS1=172.16.0.8 #Internal DNS server
DNS2=8.8.8.8 #External DNS server

Once the changes are complete, restart the network:

Heads up!

If you are connected via ssh you will likely loose your connection. Be sure there is a way to access the vm without ssh (eg. using the console on the hypervisor) incase of a malformed network config file.

sudo systemctl restart network

Finally, update the VM:

sudo yum -y update

Wrapping up

You should now have a fully updated vm with the appropriate amount of ram, storage, and cpu power. Along with ssh enabled and a hostname to boot. Specific how-tos can be viewed on the sidebar.

Troubleshooting

Expanding memory

Shutdown VM, edit xml, then start:

virsh
shutdown foreman
edit foreman
# old value
<memory unit='MiB'>1024</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
# new value
<memory unit='MiB'>8192</memory>
#delete <currentMemory unit='KiB'>1048576</currentMemory>
#save
start foreman

Expanding storage

Shutdown VM and list the volumes for the vm:

virsh
shutdown foreman
domblklist foreman

use qemu-img to resize:

#set the size
sudo qemu-img resize /home/imgs/foreman.img 32G

Start the VM back up:

virsh
#check the command worked
domblkinfo foreman vda --human
start foreman