User Tools

Site Tools


trac.x0blr.com:guides:managing_vms

This is just a summary of what was believed to work; a lot of key information here is inaccurate

Managing VMs


All commands should be performed as the vms user. Use sudo -iu vms to become this user first.

Typical VM commands to control VMs:

  • virsh list= list running (and paused) VMs
  • virsh list –all= list all VMs built, including those that have stopped.
  • virsh suspend VMNAME= hit the pause button on a running VM
  • virsh resume VMNAME = unpause a paused VM
  • virsh start VMNAME = start button on a VM. Don't use this if the VM is paused.
  • virsh shutdown VMNAME = graceful shutdown.
  • virsh destroy VMNAME= ungraceful power off. Safe if the VM is paused.
  • virsh autostart VMNAME= Sets the VM to autostart when the host is restarted.
  • virsh undefine VMNAME<– removes it from virsh list –all. Follow up with rm ~vms/images/VMNAME.qcow2to scrub the storage.

Note: as we are using the "system" namespace, insert "–connect qemu:///system" after the "virsh" command.See the explanation here.

Cloning a VM:

Three stages:

  1. Start the VM to have it running first. Wait a moment for it to complete boot-up sequence - check it by ping or ssh if possible (baseos is 78.129.208.78)
  2. Pause the VM (do not clone a running VM)
  3. Use virt-clone to make a copy of this paused VM.

e.g.: to clone apple to peach use:

virsh list
virsh list --all

virsh start apple

virsh suspend apple

virt-clone -o apple -n peach -f /var/lib/libvirt/vms/images/peach.qcow2

virsh list

Note the format of the command:

  • -o= original (running) VM
  • -nnew VM name (should then be listed)
  • -f= absolute path to the image file, usually matches the VM name.

Changes to BaseOS VM image

Keep this page updated with changes to the Base OS. Use the vms user to pause the VM when changes are complete.

virsh suspend base-v(#)

Then clone the VM using the following

virt-clone -o base-v(old VM Number) -n base-v(New VM Number) -f /var/lib/libvirt/vms/images/base-v(New VM Number).qcow2

You will need to remove the old VM using the following commands

virsh destroy base-v(Old vm number)

virsh undefine base-v(old vm number)

Please also remember to remove the corresponding qcow 2 file from vms home directory/images.


BASE V1

Installed minimal Cent OS 7 system.

Created users Darren, Dave, and Wayne

Change SSH to go through port 22022

Restricted SSH Root and pasword logins.

Installed semanage to change the ssh port.

Added firewall rule to allow traffic through port 22022.

added ssh keys for all users to authorized_keys file.

Added all users to an admin group.

Admin group granted sudo access in a new file located in /etc/sudoers.d

file name 10-admin, file reads as

%admin ALL=(ALL) NOPASSWD:ALL

IP assigned as 78.129.208.29


BASE V2

Changed IP Address to 78.129.208.174

Other Tweaks done by Dave:

  • yum update of all packages, including addition of EPEL repo
  • added rkhunter
  • configured firewallD to permit connections to 22022

BASE V3

Yum Updates Completed


Creating new VMs

Create Virtual Machines using the following changing parts that identify to be changed.

New script created to auto create a VM this is located in the VMS user directory located var/lib/libvirt/vms

./installer.sh

virt-install \
--name linuxmail \
--ram=1024 \
--vcpus=1 \
--disk path=/var/lib/libvirt/images/IMAGENAME.qcow2,bus=virtio,size=10 \
--cdrom /var/lib/libvirt/images/PATH/TO/OS.iso \
--network bridge=eth0,mode=bridge,model=rtl8139,target dev=macvtap2 \
--graphics vnc,port=5910(change this),listen=78.129.208.78,password=Qwerty1234 \
--boot cdrom,hd,menu=on

You will need to upload a certified ISO such as CentOS, Red Hat, Windows etc to the libvirt/images directory in order to use the iso - currently in /var/spool/iso

Note: possible to install from the network rather than downloaded ISO using:

virt-install \
--name centos7 \
--ram 2048 \
--disk path=/var/lib/libvirt/images/centos7.qcow2,size=8 \
--vcpus 1 \
--os-type linux \
--os-variant centos7 \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://mirror.i3d.net/pub/centos/7/os/x86_64/' \  ## network install
--extra-args 'console=ttyS0,115200n8 serial'  ## -- should provide a console window to install into

(copied from https://raymii.org/s/articles/virt-install_introduction_and_copy_paste_distro_install_commands.html#toc_5)

<blockquote>

Be careful not to change or add any network adaptors as this can cause connectivity issues on the host machine. Just use the adaptor in bridge mode allowing eth0 to pass through on MACVTAP2.

</blockquote>

If you would like to follow the install using a program such as VNCViewer. You will need to keep the following line in making sure that the appropriate port is open on the host machine. Please also change the password to your choosing.

--graphics vnc,port=5910(change this),listen=78.129.208.78,password=Qwerty1234 \

NB: 7.3 and above require a minimum of 2G ram for initramfs to be unpacked successfully during install otherwise you run into and 'out of space' error


On the guest VM if you are unable to console in. You can try the following on the guest.

  • systemctl enable serial-getty@ttyS0.service– Enabled on Base Image
  • systemctl start serial-getty@ttyS0.service– Also enabled on Base Image
/var/www/wiki.darrenwindle.co.uk/public_html/data/pages/trac.x0blr.com/guides/managing_vms.txt · Last modified: 2024/12/01 08:40 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki