Skip to content

Instantly share code, notes, and snippets.

View MatiasVara's full-sized avatar
🥳
Focusing

Matias Ezequiel Vara Larsen MatiasVara

🥳
Focusing
View GitHub Profile
@MatiasVara
MatiasVara / domain_tearwdown.md
Created August 29, 2022 09:47
This gist explains domain teardown in Xen by Andrew Cooper

Domain teardown

For domain teardown, things work roughly like this:

  1. Domain stops execution for whatever reason (shutdown, crash, etc.)
  2. Xen raises VIRQ_DOM_EXC which is a notification to xenstored.
  3. xenstored refreshes it's global idea of which domains are alive, sees that dom$X has transitioned to the Shutdown state, and fires the @releaseDomain watch
  4. Anyone who cares (blk/net-back, userspace daemons inc toolstack) starts cleaning up. Most importantly, unmapping various mappings.
  5. Toolstack evaluates the on_$FOO actions, and by default will clean up the domain
  6. Toolstack issues domain_kill() which is a long running hypercall (potentially minutes) which causes various cleanup actions in Xen.
  7. domain_kill() triggers VIRQ_DOM_EXC a second time, which fires @releaseDomain a second tim
@MatiasVara
MatiasVara / run.sh
Last active September 22, 2023 10:42
This is a cmd script that I use to launch xcp as a kvm guest. This requires to enable nested virtualization.
sudo ~/Desktop/xcp-ng/qemu-upstream/build/qemu-system-x86_64 -m 6G -accel kvm -cpu host -smp 4 -hda xcpdiskforrunx.qcow2 -hdb diskforzfs.qcow2 \
-device e1000,netdev=net0 \
-chardev socket,id=serial0,host=0.0.0.0,port=1235,server=true,wait=false -serial chardev:serial0 \
-netdev user,id=net0,hostfwd=tcp::5556-:22,hostfwd=tcp::5557-:9999 \
-display none -daemonize -pidfile pidfile.txt
@MatiasVara
MatiasVara / set-iso-to-vm.sh
Created July 20, 2022 14:07
This gist adds a cd iso to a VM to boot from.
#!/bin/bash
# See http://blog.coultard.com/2014/12/xenserver-setup-iso-share.html
xe vbd-list vm-uuid=[VM uuid] userdevice=0
xe vbd-param-set uuid=[Device UUID (not VDI UUID)] bootable=false
xe cd-list
xe vbd-list vm-name-label="<VM name>"
xe vm-cd-add vm="<VM name>" cd-name="<ISO name-lable>" device=1
xe vbd-list vm-name-label="newVM" userdevice=1
xe vbd-param-set uuid=[VBD device uuid, NOT vdi-uuid] bootable=true
xe vm-param-set uuid=[VM uuid] other-config:install-repository=cdrom
@MatiasVara
MatiasVara / add-iso-in-xcp-ng.md
Last active July 20, 2022 13:37
This gist explains how to add an ISO to the SR ISO in Xcp-ng

How to add an iso to the list of ISOs

  1. Download the ISO at /opt/xensource/packages/iso (you get this by inspecting the pbd of the ISO sr)
  2. Look for the SR named XCP-ng Tools
  3. Issue a xe sr-scan uuid=xxxx-xxxx-xxxx-xxxx
  4. List the ISOs by using xe cd-list

More info at http://blog.coultard.com/2014/12/xenserver-setup-iso-share.html

@MatiasVara
MatiasVara / forward-vnc.sh
Last active June 23, 2025 21:01
This gist presents how to connect to a VNC server of a VM in Xcp-ng/XenServer.
#!/bin/bash
# Use it as: ./forward-vnc.sh "VM-name"
# Connect a vnc client to 9999
# Note that sudo iptables -I INPUT -p tcp -m tcp --dport 9999 -j ACCEPT
uuid="$(xe vm-list name-label="$1" --minimal)"
domid="$(xe vm-param-get uuid="$uuid" param-name=dom-id)"
socat -d -d TCP4-LISTEN:9999,fork UNIX-CONNECT:/var/run/xen/vnc-"$domid"
@MatiasVara
MatiasVara / prepare_host.sh
Created May 10, 2022 09:39
This script prepares the host before installing Xen from a deb.
apt-get update && apt-get install build-essential bcc wget ftp bin86 gawk bridge-utils iproute2 libcurl4 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg-dev python3-dev libnl-3-dev libnl-cli-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-idiag-3-dev libnl-xfrm-3-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib libx11-dev bison flex xz-utils libyajl-dev gettext libpixman-1-dev libaio-dev markdown pandoc iasl cmake figlet libc6-dev-i386 lzma lzma-dev liblzma-dev libsystemd-dev libzstd1-dev ninja-build -y
@MatiasVara
MatiasVara / install_xen.sh
Created May 10, 2022 09:37
This script installs xen in Ubuntu Bionic from a deb.
sudo dpkg -i xen-upstream-4.15.3-pre.deb
sudo /sbin/ldconfig
mkdir -p /etc/default/grub.d
sudo mkdir -p /etc/default/grub.d
sudo cp xen.cfg /etc/default/grub.d/xen.cfg
sudo update-grub
sudo rm /etc/init.d/xendomains
sudo systemctl enable xen-qemu-dom0-disk-backend.service
sudo systemctl enable xen-init-dom0.service
sudo systemctl enable xenconsoled.service
@MatiasVara
MatiasVara / Dockerfile
Last active December 1, 2022 09:19
This Dockerfile builds Xen-4.15 for Ubuntu Bionic (18.04)
FROM ubuntu:bionic
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install build-essential bcc wget ftp bin86 gawk bridge-utils iproute2 libcurl4 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended pciutils-dev mercurial make gcc libc6-dev zlib1g-dev python python-dev python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg-dev python3-dev libnl-3-dev libnl-cli-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-idiag-3-dev libnl-xfrm-3-dev iasl libbz2-dev e2fslibs-dev git-core uuid-dev ocaml ocaml-findlib libx11-dev bison flex xz-utils libyajl-dev gettext libpixman-1-dev libaio-dev markdown pandoc iasl cmake figlet libc6-dev-i386 lzma lzma-dev liblzma-dev libsystemd-dev libzstd1-dev ninja-build -y
RUN cd ~/ && git clone git://xenbits.xen.org/xen.git && cd xen && git checkout origin/stable-4.15 -b testbranch && ./c