====== Scraps ======
Bits and pieces I want to be able to grab quickly. This page will change frequently.
===== Disable power button shutdown =====
edit /etc/systemd/logind.conf
uncomment HandPowerKey, set to ignore
===== Get & Set date w/ epoch time =====
Get from good machine:
date +%s
Set on another:
date -s '@1705865491'
===== Image and Compress Disk =====
dd if=/dev/sda bs=100M | pv -ptera -s500G | lz4 > backup-name.dd.lz4
(-s500G refers to the image size, for estimates)
Mount the whole disk image: (have to un-lz4 first ofc)
kpartx -a -v myimage.disk
mount /dev/mapper/loop0p1 /mnt/myimage
Then, to unmount:
umount /mnt/myimage
kpartx -d -v myimage.disk
===== ntplogtemp =====
#!/bin/bash
/usr/local/bin/ntplogtemp -o -l /chronyLogs/temps
sed '/ZONE0/d' -i /chronyLogs/temps
sed '/sensor/d' -i /chronyLogs/temps
sed -i 's/LM0/CPU/g' /chronyLogs/temps
sed -i 's/LM1/CPU/g' /chronyLogs/temps
===== cycle systemd logs =====
sudo journalctl --rotate ; sudo journalctl --vacuum-time=1s
==== show systemd logs from boot ====
sudo journalctl -b
===== Raspberry Pi =====
==== Quick Pi ID ====
Easy way to get a quick visual indicator to ID a Pi you're remoted into:
Blink pwr LED at 1Hz:
echo timer | sudo tee /sys/class/leds/led1/trigger
Set pwr LED back to monitor voltage:
echo input | sudo tee /sys/class/leds/led1/trigger
==== Heartbeat LED ===
set in config.txt
dtparam=act_led_trigger=heartbeat
==== Grow partition on first boot ====
Add to the end of /boot/cmdline.txt
quiet init=/usr/lib/raspi-config/init_resize.sh
===== chronyc tracking =====
-m flag combines commands. For example: sources -v, tracking, sourcestats -v
chronyc -m 'sources -v' tracking 'sourcestats -v'
===== DHCP and Static IP on the same interface =====
Ubuntu Server 20.04, should apply to netplan in general.
network:
version: 2
ethernets:
eno1:
dhcp4: true
addresses:
- 172.16.1.20/22
gateway4: 172.16.0.1
nameservers:
search:
- syninf.net
addresses:
- 172.16.0.2
===== Find files under certain size and move them =====
find . -type f -size -150M -exec mv {} ../junk \;
===== nmap testers =====
NTP
sudo nmap -sU -p 123 --script ntp-info 172.16.1.6
DHCP
sudo nmap -sU -p 67 --script=dhcp-discover 172.16.0.2
===== Standalone certbot DNS =====
sudo certbot certonly --manual --preferred-challenges dns -d webgis.syninf.net
===== rsync incremental copy =====
[[https://www.redhat.com/sysadmin/sync-rsync|https://www.redhat.com/sysadmin/sync-rsync]]
sudo rsync -avuP /mnt/data/media/ /mnt/six/media/
===== Add NTP Server to PiHole DHCP =====
echo 'dhcp-option=42,172.16.0.2' | sudo tee /etc/dnsmasq.d/42-pihole-dhcp-ntp.conf
Restart pihole
sudo service pihole-FTL reload
===== Build LinuxPTP on Alpine =====
Enable community repository
install deps
apk add alpine-sdk linux-headers bsd-compat-headers
git clone git://git.code.sf.net/p/linuxptp/code linuxptp
make ; make install
===== Cycle Chrony Logs =====
#!/bin/bash
# chrony log rotation
cd /var/log/chrony
mv measurements.log measurements.$(date +"%Y%m%d").log
mv statistics.log statistics.$(date +"%Y%m%d").log
mv tracking.log tracking.$(date +"%Y%m%d").log
sync
chronyc cyclelogs
===== chrony.conf ptp as pps refclock =====
server time-a.nist.gov
server time-a-wwv.nist.gov
refclock SHM 0 poll 3 refid GPS
refclock PHC /dev/ptp0:extpps:nocrossts:pin=0 width 0.1 refid PHC pps
logdir /var/log/chrony
log statistics tracking measurements
driftfile /var/lib/chrony/chrony.drift
dumpdir /etc/chrony/dump
rtcsync
allow
cmdallow
===== Proxmox =====
==== re-number VM ====
1) shut down VM
2) rename the storage
zfs rename pool1/vms/vm-112-disk-0 pool1/vms/vm-1001-disk-0
3) rename the configuration file
export vgNAME=vg-images newVMID=173 oldVMID=175 ; \
sed -i "s/$oldVMID/$newVMID/g" /etc/pve/qemu-server/$oldVMID.conf; mv /etc/pve/qemu-server/$oldVMID.conf /etc/pve/qemu-server/$newVMID.conf; \
unset vgNAME newVMID oldVMID;