Skip to content

Instantly share code, notes, and snippets.

View BlackDex's full-sized avatar

Mathijs van Veluw BlackDex

View GitHub Profile
@BlackDex
BlackDex / mount_qcow2.md
Created July 31, 2019 09:37 — forked from shamil/mount_qcow2.md
How to mount a qcow2 disk image

How to mount a qcow2 disk image

This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.

Step 1 - Enable NBD on the Host

modprobe nbd max_part=8
@BlackDex
BlackDex / ratelimit.nginxconf
Created January 30, 2019 23:28 — forked from ipmb/ratelimit.nginxconf
Nginx reverse proxy with rate limiting
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
@BlackDex
BlackDex / Useful_CEPH_CLI.md
Last active February 27, 2019 13:47
Useful CEPH CLI

Find orphaned objects

rados ls -p <POOLNAME> | grep -vE "($(rados -p <POOLNAME> ls | grep rbd_header | grep -o "\.[0-9a-f]*" | sed -e :a -e '$!N; s/\n/|/; ta' -e 's/\./\\./g'))" | grep -E '(rbd_data|journal|rbd_object_map)'

Select inconsistent PG's and uniq them per OSD

# This output can be used to semi-automate `ceph pg repair` and not do a pg repair on duplicate primary OSDs
ceph pg dump --format json | jq -r '.pg_stats[] | select(.state | contains("active+clean+inconsistent")) | "\(.acting_primary)\t\(.pgid)\t\(.state)"' | sort -k1 | uniq -w4 | awk '{print $2}'
@BlackDex
BlackDex / Misc_CLI_Stuff.md
Last active January 30, 2019 13:59
Misc CLI Stuff

Wipe the start and end of a block device

# Change /dev/SDX on 3 places to the correct block device
# DANGER!!! THIS WILL WIPE EVERYTHING OF THE BLOCK DEVICE
dd if=/dev/zero of=/dev/SDX bs=1M count=1024
dd if=/dev/zero of=/dev/SDX bs=512 seek=$(( $(blockdev --getsz /dev/SDX) - 8192 )) count=8192
@BlackDex
BlackDex / rename-git-branch.sh
Created January 30, 2019 08:06 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@BlackDex
BlackDex / Useful_OpenStack_CLI.md
Last active February 14, 2019 10:27
Useful OpenStack CLI

Filter volumes per availability zone

# Using openstack-cli with jq (Since openstack-cli isn't able to filter or show the az)
AZ="zone" ; for volume_id in $(openstack volume list -fvalue --quote=none --all-projects --sort-column=ID -cID); do openstack volume show -fjson "${volume_id}" | jq -r '. | select(.availability_zone == "'"${AZ}"'") | "\(.id)"'; done

# Using cinder-cli which has the option to show the az, but can't filter if using volumev2
AZ="zone" ; cinder --os-volume-api-version=2 list --all-tenants --sort id:asc --fields id,availability_zone | grep "${AZ}" | awk '{print $2}'

# Get all instance ID's which are using an ephemeral image
openstack server list --all-projects --limit -1 --no-name-lookup --sort-column ID -fjson | jq -r '.[] | select(.Image != "") | "\(.ID)"'
@BlackDex
BlackDex / skylake-tuning-linux.md
Last active May 2, 2020 03:29 — forked from Brainiarc7/skylake-tuning-linux.md
This gist will show you how to tune your Intel-based Skylake, Kabylake and beyond Integrated Graphics Core for performance and reliability through GuC and HuC firmware usage on Linux.

Tuning Intel Skylake and beyond for optimal performance and feature level support on Linux:

Note that on Skylake, Kabylake (and the now cancelled "Broxton") SKUs, functionality such as power saving, GPU scheduling and HDMI audio have been moved onto binary-only firmware, and as such, the GuC and the HuC blobs must be loaded at run-time to access this functionality.

Enabling GuC and HuC on Skylake and above requires a few extra parameters be passed to the kernel before boot.

Instructions provided for both Fedora and Ubuntu (including Debian):

Note that the firmware for these GPUs is often packaged by your distributor, and as such, you can confirm the firmware blob's availability by running:

@BlackDex
BlackDex / blockpeers.sh
Created July 2, 2018 15:58 — forked from jult/blockpeers.sh
blocking p2p peer snoopers and evil corp (for Tixati IP filter and such)
#!/bin/sh
# This script runs every other night at 04:56 CET on a webserver I maintain
# Results are always at: https://jult.net/block.txt ( or https://jult.net/block.txt.gz )
# And much smaller, stripped of BS; https://jult.net/bloc.txt
# For use in Tixati IP filter: https://jult.net/bloc.txt.gz !!!
# And finally a txt file with just the bold IP-ranges: https://jult.net/bl.txt (or https://jult.net/bl.txt.gz )
# Download open block-lists, unpack, filter:
curl -s https://www.iblocklist.com/lists.php | grep -A 2 Bluetack | xargs wget -qO - --limit-rate=500k | gunzip -f | egrep -v '^#' > /tmp/xbp
@BlackDex
BlackDex / Documentation.md
Created April 29, 2018 14:28 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@BlackDex
BlackDex / force-del-maas-subnet
Created November 8, 2017 20:35 — forked from ThinGuy/force-del-maas-subnet
Force delete a subnet in maas
#Workaround for 'Subnet matching query does not exist' error trying to delete a subnet in MaaS
#See bug https://bugs.launchpad.net/maas/+bug/1702527
#Usage force-del-maas-subnet <maas subnet name>
#ex force-del-maas-subnet '192.168.122.0/24'
force-del-maas-subnet() {
unset SN_NAME MAAS_SN_ID MAAS_STATICIP_ID MAAS_INTIP_ID MATCH CONT
export MATCH=false
command -v ipcalc > /dev/null 2>&1 || sudo apt install -yq ipcalc
command -v ipcalc > /dev/null 2>&1 || { printf "This function requires ipcalc. Please install it via \"apt install ipcalc -y\"\n";return; }