Skip to content

Instantly share code, notes, and snippets.

@PaulFurtado
PaulFurtado / init
Created October 21, 2014 02:17
Script to run arch with any kernel version in DigitalOcean
#!/bin/sh
# Digital Ocean stores the arch kernel outside of the VM's disk and the hypervisor boots the
# kernel directly. This hack allows you to boot any arch kernel version by using kexec to
# basically turn the DO-provided kernel into a bootloader.
#
# By default, the DO kernel is started with /sbin/init as its command line and /sbin/init
# is a symlink to /usr/lib/systemd/systemd. By replacing /sbin/init with this shell script
# which calls kexec, we can boot a kernel on the VM's disk.
@PaulFurtado
PaulFurtado / usb_reset.py
Last active June 22, 2024 22:44
Reset USB device from python
"""
Example code for resetting the USB port that a Teensy microcontroller is
attached to. There are a lot of situations where a Teensy or Arduino can
end up in a bad state and need resetting, this code is useful for
"""
import os
import fcntl
import subprocess
# Add grub to the EFI boot manager
efibootmgr -c -g -d /dev/sda -p 1 -w -L "Grub" -l /boot/efi/EFI/boot/bootx64.efi
# Builds a 64-bit grub image in the default EFI bootloader location.
mkdir '/boot/efi/EFI/boot'
grub-mkimage --directory '/usr/lib/grub/x86_64-efi' --prefix '(hd0, gpt1)' --output '/boot/efi/EFI/boot/bootx64.efi' --format 'x86_64-efi' --compression 'auto' 'fat' 'part_gpt' 'ext2'