Table of Contents
Linux
Commands
Some Linux commands seldom used - so sometimes not remembered
which | find executables (candidates) |
|---|---|
watch | repeat command and display output |
pv | Pipe Viewer |
nmap | Network Scanner |
mtr | Ping & Trace Network |
System
Some tipp 'n tricks to handle you linux system in seldom situations
Rescan Blockdevices / Reread Partition Tables
Tipps I found with variable usefullness:
blockdev --rereadpt /dev/sda7
(from VMWare Communities)
partprobe /dev/sdX
hdparm -z /dev/sda
sfdisk -R /dev/sda
echo 1 > /sys/block/sdX/device/rescan
echo "scsi remove-single-device X X X X" > /proc/scsi/scsi echo "scsi add-single-device X X X X" > /proc/scsi/scsi
(X X X X is <AdapterNo.> <Channel> <Id> <LUN>)
echo "- - -" > /sys/class/scsi_host/host<N>/scan
(see Linux Journal)
echo "scsi scsi-scan-devices" > /proc/scsi/scsi
partprobe [options]
(Thanks to linux-poweredge)
sfdisk -R
Force Soft RAID (mdadm) resync
echo "repair" > /sys/block/md127/md/sync_action
Credits: Superuser: how to force mdadm to sync to device after raid6 repair and how to get number of errors?
Force hard reset
In case you are in danger, that your remote system might hang while doing a clean shutdown, a “cold reboot” triggered by software might help
echo b > /proc/sysrq-trigger
Credits and further reading: GEEX, ct' online, kernel.org git.kernel.org
USB
Reset USB device (bus?)
Regain access to an build-in card reader after
udisksctl power-off -b /dev/sdc
/var/log/syslog
Feb 26 16:38:27 myhost udisksd[6074]: Ignoring SCSI command START STOP UNIT failure (Non-GOOD SCSI status from SGIO v3 ioctl: status=2 host_status=0 driver_status=8) on /dev/sdc Feb 26 16:38:27 myhost udisksd[6074]: Powered off /dev/sdc - successfully wrote to sysfs path /sys/devices/pci0000:00/0000:00:1d.7/usb2/2-4/remove Feb 26 16:38:27 myhost kernel: [179303.432273] usb 2-4: USB disconnect, device number 8 Feb 26 16:38:27 myhost colord: device removed: sysfs-HP-HP_Flash_Media_Reader Feb 26 16:38:28 myhost colord-sane: io/hpmud/pp.c 627: unable to read device-id ret=-1
succeeded with:
echo 0 > /sys/bus/usb/drivers/usb/usb2/authorized echo 1 > /sys/bus/usb/drivers/usb/usb2/authorized
Credits: How do you reset a USB Device from the command line? - Ask Ubuntu
Enforce using usb-storage
Enforce using usb-storage for USB device a1b2:c3d4 (e.g. compared to uas)
modprobe usb-storage quirks=a1b2:c3d4:u
Remove a USB drive from the system
echo 1 > /sys/block/sdX/device/delete
will remove /dev/sda, but (assuming the id is 2-3)
echo 1 > /sys/bus/usb/devices/2-3/remove
will also power it down and remove the USB device Revive powered down but connected USB devices
- Find name of host controller (asume it's
usb2for the following) - assert there are no other devices connected
echo '0' > /sys/bus/usb/devices/usb2/authorizedecho '1' > /sys/bus/usb/devices/usb2/authorized
Avoid accidental wakeups after hibernate with systemd
- /etc/systemd/sleep.conf.diff
diff -u -r1.1 sleep.conf --- sleep.conf 2020-04-01 19:23:42+02 1.1 +++ sleep.conf 2022-10-07 10:19:04+02 @@ -18,7 +18,7 @@ #AllowHybridSleep=yes #SuspendMode= #SuspendState=mem standby freeze -#HibernateMode=platform shutdown +HibernateMode=shutdown #HibernateState=disk #HybridSleepMode=suspend platform shutdown #HybridSleepState=disk
References:
Touchpad not working after suspend
rmmod psmouse modprobe psmouse
Configure network based on MAC instead of interface names
- /etc/network/interfaces
auto mac/01:23:45:67:89:ab=mynet iface mynet inet static address 192.168.3.4 netmask 255.255.255.0 gateway 192.168.3.1 dns-nameservers 192.168.1.1
Handle stalled filesystem
List hanging processes
ps -eo pid,state,wchan:30,cmd | awk '$2 ~ /D/ {print}'
List kernel function stack
cat /proc/<PID>/stack
List fuse connections
ls -l /sys/fs/fuse/connections/
Forcibly kill fuse mount
echo 1 > /sys/fs/fuse/connections/<id>/abort
NVME Smart Log
nvme smart-log /dev/nvme0
Copy Bluetooth trust
(root) ~ # diff /var/lib/bluetooth/1A:B2:3C:D4:5E:F6 /7A:B8:9C:D0:A1:2F/info /media/user/other:_var/lib/bluetooth/1A:B2:3C:D4:5E:F6 /7A:B8:9C:D0:A1:2F/info 5c5 < Trusted=true --- > Trusted=false 7c7 < Services=0000110b-0000-1000-8000-00805f9b34fb;0000110c-0000-1000-8000-00805f9b34fb;0000110d-0000-1000-8000-00805f9b34fb;0000110e-0000-1000-8000-00805f9b34fb;00001200-0000-1000-8000-00805f9b34fb; --- > Services=0000110b-0000-1000-8000-00805f9b34fb;0000110e-0000-1000-8000-00805f9b34fb;00001200-0000-1000-8000-00805f9b34fb; 16c16 < Key=9B32FB759673C0274531FC7FB22CA6D5 --- > Key=0306C87338622123FA3BE5014587527F (root) ~ #
- Note, beyond
7A:B8:9C:D0:A1:2F(other device MAC) also the1A:B2:3C:D4:5E:F6(local adapter MAC) being the same on both systems - ignore the
TrustedandServices - copy the
Key