Skip to content

Instantly share code, notes, and snippets.

@lowply
Created July 10, 2020 05:24
Show Gist options
  • Save lowply/22553ea79358893548045f69726e3f27 to your computer and use it in GitHub Desktop.
Save lowply/22553ea79358893548045f69726e3f27 to your computer and use it in GitHub Desktop.
KVM memo

Env

  • VMWare Fusion 11.5 on macOS Catalina
  • Guest OS: CentOS 8.2
  • GitHub Enterprise Server 2.20.10
  • Make sure that the Guest OS has
    • more than 100GB of disk space (/home)
    • 2 CPU cores / 16GB memory

Prep

Install qemu-kvm and libvirt tools:

sudo yum install qemu-kvm libvirt virt-install virt-manager libvirt-client virt-viewer

We use /home/kvm as the working directory in this example. Download the qcow2 disk image here.

For debugging

If you want to SSH into the VM before management console starts up, add your ssh pubkey to the GHES image by running the following command:

virt-sysprep -a /home/kvm/github-enterprise-2.20.10.qcow2 --ssh-inject admin:file:/home/lowply/id_ed25519.pub

Install the VM

virt-install \
  --hvm \
  --name GitHubEnterprise \
  --vcpus 2 \
  --memory 16384 \
  --network default \
  --controller type=scsi,model=virtio-scsi \
  --os-variant debian9 \
  --disk /home/kvm/github-enterprise-2.20.10.qcow2,size=100,format=qcow2 \
  --disk path=/home/kvm/data.qcow2,size=100,format=qcow2 \
  --import

List VMs

virsh list
virsh list --all

Shutdown the VM (gracefully)

virsh shutdown GitHubEnterprise

Stop the VM (Power Off)

virsh destroy GitHubEnterprise

Delete the VM

virsh undefine GitHubEnterprise

Grab a screenshot of the console

virsh screenshot GitHubEnterprise --file /tmp/screeenshot.ppm

From your laptop:

ssh vm -- sudo virsh screenshot GitHubEnterprise --file /tmp/screeenshot.ppm && scp vm:/tmp/screeenshot.ppm .

Restart the VM

virsh shutdown GitHubEnterprise
virsh start GitHubEnterprise

You don't have to bind mac address and IP address in the virsh net-edit default, DHCP will take care of it.

Dump the definition xml file

virsh dumpxml GitHubEnterprise

Check the mac and IP addresses

virsh domifaddr GitHubEnterprise

Network related commands

virsh net-list
virsh net-edit default
virsh net-destroy default
virsh net-start default
virsh net-undefine default
virsh net-dumpxml default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment