Skip to content

Instantly share code, notes, and snippets.

View dannysauer's full-sized avatar

Danny Sauer dannysauer

View GitHub Profile
# creating a new VG with the second hard disk in the system
sudo virsh pool-define-as default logical - - /dev/sdb libvirt_lvm /dev/libvirt_lvm
sudo virsh pool-build default --overwrite
sudo virsh pool-start default
# as a directory
sauer@helium:~/kubic-project/automation> virsh pool-edit default
<pool type='dir'>
<name>default</name>
<uuid>fdab5cc0-94a6-4349-892c-1fe133158406</uuid>
@dannysauer
dannysauer / gist:b4f8ba1a021a7488d137c7fc14a7d20b
Last active August 3, 2018 14:52
Overriding network namespace

To override name resolution, create a mount namespace and bind mount a special resolv.conf over the top of the original. The IP address will be the first address in the range given to the virtual network. I used 192.168.68.0/22, so the DNS server (dnsmasq) is started by KVM on 192.168.68.1. You can "discover" that by getting the information for the network, then looking at the IP address assigned to the bridge device:

sauer@lightning:~> sudo virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 caasp-dev-net        active     no            yes
sauer@lightning:~$ sudo grep 2019-01-24 /var/log/zypp/history | awk -F\| '$2=="install"{print $3,$4,$5}' | sort
alsa-plugins 1.1.8-1.1 x86_64
apparmor-abstractions 2.13.2-3.1 noarch
apparmor-docs 2.13.2-3.1 noarch
apparmor-parser 2.13.2-3.1 x86_64
apparmor-parser-lang 2.13.2-3.1 noarch
apparmor-profiles 2.13.2-3.1 noarch
apparmor-utils 2.13.2-3.1 noarch
apparmor-utils-lang 2.13.2-3.1 noarch
bison 3.2.4-1.1 x86_64
@dannysauer
dannysauer / raspbian.sh
Created January 26, 2019 05:16
Set up netdata
cd /usr/local/src
sudo mkdir netdata && sudo chown --reference=$HOME netdata/
git clone https://github.com/netdata/netdata.git --depth=100
cd netdata
@dannysauer
dannysauer / commands.sh
Created January 29, 2019 23:56
Leap15 KVM
sudo virt-install --name=leap15_dev --vcpus=8 --memory=$((1024*32)) --disk path=/var/lib/libvirt/local/leap15.qcow --os-variant=opensuse15.1 --import
@dannysauer
dannysauer / math.c
Created April 14, 2019 23:11
Arithmatic parser
// process arbitrary 1+2-(3+(5-1))-2 style equations
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int parse(char[]);
int process(int, char, int);
struct State {
int total;
char operator;
pipe = 1/2;
bearing_id = 3/8;
bearing_od = 7/8;
bearing_w = 9/32;
// max overlap is 0.50 == 50%
pipe_overlap_multiplier = 0.35;
pulley_od = 3;
pulley_lip = 1/16;
@dannysauer
dannysauer / summary.md
Last active October 29, 2019 13:49
testing with proxy
  1. Set up a virtual network that uses nat
  2. Build machines using that network
  3. Figure out what bridge device this network is using (my example is "hundrednet")
    1. virsh net-info hundrednet | grep -i bridge
  4. Configure that network to only communicate internally and to the proxy
    1. sudo iptables -L FORWARD --line-numbers --verbose
    2. find the line for this network like 7 66 7322 ACCEPT all -- virbr2 any 192.168.100.0/24 anywhere
    3. replace that line (line 7 in the example) with one that only accepts traffic to the proxy: sudo iptables -R FORWARD 7 -i virbr2 -s 192.168.100.0/24 -p tcp --dport 3128 -j ACCEPT Note that this uses the same input interface (-i), the same source range (-s), and adds TCP protocol and destination port 3128
@dannysauer
dannysauer / clone.sh
Last active April 3, 2020 05:39
kvm cloning script
#!/bin/bash
# usage: clone.sh [source_domain] target_domain [target_domain_2 ...]
# note - if you want to make more than one clone, you must specify the source.
set -o errexit
SRC=sle15sp1
if (( ${#@} > 1 ))
then
SRC="$1"
shift
@dannysauer
dannysauer / "Static" IP notes.md
Last active December 4, 2019 22:02
Firewall stuff

Rather than set up static IPs in VMs, I'd prefer to use DHCP and just have static assignments. This is basically how I do that:

List the interfaces:

for H in $( sudo virsh list --name | grep proxy ); do echo $H; sudo virsh --quiet domiflist --domain $H; done

For each interface's MAC, add a static lease:

sudo virsh net-update proxynet add-last ip-dhcp-host '<host mac="52:54:00:02:e1:aa" ip="192.168.42.10" />' --live --config