Skip to content

Instantly share code, notes, and snippets.

@smoser
smoser / mdserv
Created Oct 11, 2011
simple python web server that mimicks ec2 instance metadata service
View mdserv
#!/usr/bin/python
"""
To use this to mimic the EC2 metadata service entirely, run it like:
# where 'eth0' is *some* interface. if i used 'lo:0' i got 5 second or so delays on response.
sudo ifconfig eth0:0 169.254.169.254 netmask 255.255.255.255
sudo ./mdserv 169.254.169.254:80
Then:
wget -q http://169.254.169.254/latest/meta-data/instance-id -O -; echo
curl --silent http://169.254.169.254/latest/meta-data/instance-id ; echo
@smoser
smoser / README.md
Last active Mar 23, 2021
qemu to linux mapping of smbios / dmi information
View README.md

Mappings for DMI/SMBIOS to Linux and dmidecode

Information can be put into dmi tables via some qemu-system hosts (x86_64 and aarch64). That information is exposed in Linux under /sys/class/dmi/id and can be read with dmidecode. The names are very annoyingly inconsistent. The point of this doc is to map them.

Mappings

Example qemu cmdline:

qemu-system-x86_64 -smbios type=<type>,field=value[,...]

qemu-system-x86_64 -smbios type=0,vendor=superco,version=1.2.3
@smoser
smoser / gist:4756561
Last active Feb 22, 2021
boot a cloud image in kvm
View gist:4756561
## Install a necessary packages
$ sudo apt-get install kvm cloud-utils genisoimage
## URL to most recent cloud image of 12.04
$ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release"
$ img_url="${img_url}/ubuntu-12.04-server-cloudimg-amd64-disk1.img"
## download the image
$ wget $img_url -O disk.img.dist
## Create a file with some user-data in it
@smoser
smoser / ubuntu-cloud-virtualbox.sh
Last active Feb 15, 2021
example of using Ubuntu cloud images with virtualbox
View ubuntu-cloud-virtualbox.sh
## Install necessary packages
$ sudo apt-get install virtualbox-ose qemu-utils genisoimage cloud-utils
## get kvm unloaded so virtualbox can load
$ sudo modprobe -r kvm_amd kvm_intel
$ sudo service virtualbox stop
$ sudo service virtualbox start
## URL to most recent cloud image of 12.04
$ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release"
@smoser
smoser / README.md
Last active Jan 30, 2021
Boot a specific installed Ubuntu kernel using grub-reboot and grub-set-default
View README.md

Ubuntu Grub Boot Kernel

Boot a specific installed Ubuntu kernel using grub-reboot and grub-set-default.

This allows you to pick what kernel you want to boot on next reboot, or set the default, without having to know much about how grub works or editing config files.

Usage

  Usage: boot-kernel [options] [kernel]
     call grub-reboot or grub-set-default to boot the provided kernel.
@smoser
smoser / README.md
Last active Jan 23, 2021
set up a ssh tunnel only user for ssh proxy jump
View README.md

Set up a ssh tunnel only user

In order to give someone access to hosts that are available only by ssh "bouncing" (ProxyJump), add a user for this specific purpose.

We have an internal openstack where instances get IPs on per-tenant networks. Each tenant has a 'bastion' host that has a "public" ip (floating ip). You can access other instances by bouncing through the bastion. From time to time I want to let someone else into an instance. This could be done either with:

a.) just give them shell access to the bastion and let them hop through. Sharing an unrestricted shell account on my bastion is less than ideal. b.) assign a floating/"public" IP to the instance so they could go directly in. Floating IPs are limited, so this is less than ideal.

So instead, I have set up a single user as described here that can only be used for ProxyJump. It allows others proxied access to my instances but without granting them full shell access.

@smoser
smoser / example-output
Last active Jan 17, 2021
shell benchmarks: compare grep and pipe versus awk or sed only
View example-output
LANG=C
3156 out.full
76 out.100
50 out.50
20 out.20
3302 total
awk: /usr/bin/gawk
sed: /bin/sed
grep: /bin/grep
----
@smoser
smoser / notify-send-nox
Created Apr 7, 2011
send a message like notify-send without X
View notify-send-nox
#!/bin/sh
# send a notify message without access to DISPLAY
# taken from src/notify-osd.xml in notify-osd and from example in gdbus(1)
# 'notify-send' requires 'DISPLAY' and access to other context
# this script does not
#
# **** UGH ****
# This depends on DBUS_SESSION_BUS_ADDRESS variable, which is still "per-session"
# so, in an environment where you have access to neither, you can't really do this.
#
@smoser
smoser / .gitignore
Last active Dec 30, 2020
cloud-init ubuntu nocloud example with network config
View .gitignore
*.img
*.raw
@smoser
smoser / README.md
Last active Dec 20, 2020
update or add to an initramfs or initrd with contents of a directory
View README.md

Update an initramfs with contents of a directory without root

This tool allows you to take a initramfs and add contents of a directory to it. This is very useful if you need to test initramfs, you can simply take the original and add your files "over".

Also, because it does not extract the original cpio archive, it works without root.

Usage:

Usage: overlay-initramfs [ options ] source-initramfs directory [output]