Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
gregjhogan / nvidia-driver-reload
Last active October 20, 2022 19:57
reload nvidia drivers
sudo systemctl stop nvidia-persistenced.service
# only works if nothing is using the GPU
sudo rmmod nvidia_drm nvidia_uvm nvidia_modeset nvidia
nvidia-smi
@gregjhogan
gregjhogan / ubuntu-debug-held-broken-packages.sh
Created October 14, 2022 21:13
ubuntu debug unmet dependencies held broken packages
sudo apt-get install -o Debug::pkgProblemResolver=true -o Debug::Acquire::http=true --no-install-recommends nvidia-driver-520
@gregjhogan
gregjhogan / clover-usb-boot-drive.sh
Last active March 16, 2022 21:13
clover USB boot drive that boots another drive (for example on a NVME drive)
USB_DEV=/dev/sdX # replace X with correct number
USB_MNT=/mnt/usb
sudo mkdir -p /mnt/usb
sudo wipefs -a --force $USB_DEV
sudo dd if=/dev/zero of=${USB_DEV} bs=1M count=100
(
echo n # new partition
echo 1 # partition number 1
echo 2048 # first sector 2048
@gregjhogan
gregjhogan / grub2-usb-boot-drive-chain-load-grub-cfg.sh
Last active March 16, 2022 16:27
grub2 USB boot drive that chain loads another grub config (for example on a NVME drive)
USB_DEV=/dev/sdX # replace X with actual device name
USB_MNT=/mnt/usb
ROOT_LABEL="Ubuntu" # replace with label of root drive you installed ubuntu on
# format
sudo wipefs -a $USB_DEV
sudo dd if=/dev/zero of=${USB_DEV} bs=1M count=128 conv=notrunc
(
echo n # new partition
echo p # primary
echo 1 # partition number 1
@gregjhogan
gregjhogan / find-symlinks-pointing-to-disk-dev.sh
Created September 14, 2021 20:44
find symlinks pointing to a disk device
@gregjhogan
gregjhogan / hdparm-security-erase-enhanced.sh
Created July 3, 2021 17:56
hdparm secure erase hard drive
DISK_DEV=/dev/sd<?>
DISK_PWD="" # leave empty or set to something you will remember
sudo hdparm --user-master u --security-set-pass "$DISK_PWD" $DISK_DEV
sudo hdparm --user-master u --security-erase-enhanced "$DISK_PWD" $DISK_DEV
# secure erase should clear user password and disable security when complete
#sudo hdparm --user-master u --security-disable "$DISK_PWD" $DISK_DEV
@gregjhogan
gregjhogan / ffmpeg-ffplay-stream-raw-video.sh
Created June 30, 2021 18:44
ffmpeg to ffplay stream raw video
# on server (waits for connection)
ffmpeg -framerate 20 -i /path/to/video.hevc -an -c:v copy -f hevc tcp://<server-ip>:8888?listen
# on client (format -f can often be auto-detected)
ffplay -f hevc -i tcp://<server-ip>:8888 -framerate 20
# note that -framerate xx is needed because you can't know the frame rate of a raw hevc file
@gregjhogan
gregjhogan / 7z-cpu-benchmark.sh
Created June 7, 2021 23:08
7z CPU benchmark
# multi-threaded off
7z b -mmt=off
# 4 threads
7z b -mmt=4
@gregjhogan
gregjhogan / git-config-fetch-all-branches.sh
Created June 1, 2021 23:18
git config update to fetch all branches
# get config for which branches will get pulled
git config --get remote.origin.fetch
# e.g. only master: +refs/heads/master:refs/remotes/origin/master
# set config to pull all branches
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
@gregjhogan
gregjhogan / relocate-bad-block.sh
Last active May 21, 2021 18:32
relocate bad block
# https://wiki.archlinux.org/title/Identify_damaged_files#Force_the_disk_to_reallocate_bad_block
# scan entire disk for bad blocks (slow but complete)
sudo badblocks -v -b 4096 /dev/sda
# smartctl test find bad block (fast but not complete)
sudo smartctl -t short /dev/sda
# get block number of error
sudo smartctl -a /dev/sda
...