西维蜀黍

【Linux】命令 - strace

strace

strace is a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state. The operation of strace is made possible by the kernel feature known as ptrace.

在Linux世界,进程不能直接访问硬件设备,当进程需要访问硬件设备(比如读取磁盘文件,接收网络数据等等)时,必须由用户态模式切换至内核态模式,通过系统调用访问硬件设备。strace可以跟踪到一个进程产生的系统调用,包括参数,返回值,执行消耗的时间。

  ...


【Golang】打印调用栈信息

debug.Stack() - 打印当前 goroutine 的堆栈

package main

import (
	"fmt"
	"runtime/debug"
)

func test1() {
	test2()
}

func test2() {
	test3()
}

func test3() {
	fmt.Printf("%s", debug.Stack())
	//debug.PrintStack() // equivalent to the above
}

func main() {
	test1()
}
  ...


【Linux】Linux Distribution

Debian

Ubuntu - GNOME

Linux Mint

Pop!_OS - GNOME

ElementiryOS

  ...


【Linux】查看一个运行进程的环境变量

A quick mental dump in case I forget it again next time. First, check your PID:

$ ps faux | grep 'your_process'
508   28818  0.0  0.3  44704  3584 ?  Sl   10:10   0:00  \_ /path/to/your/script.sh

Now, using that PID (in this case, 28818), check the environment variables in /proc/$PID/environ.

$ cat /proc/28818/environ
TERM=linuxPATH=/sbin:/usr/sbin:/bin:/usr/binrunlevel=3RUNLEVEL=3SUPERVISOR_GROUP_NAME=xxxPWD=/path/to/your/homedirLANGSH_SOURCED=1LANG=en_US.UTF-8previous=NPREVLEVEL=N

Now to get that output more readable, you can do two things. Either parse the null character (\0) and replace them by new lines (\n) or use the strings tool that does this for you.

  ...


【Network】反向 DNS 查询(Reverse DNS Lookup)

  ...


【Linux】信号(Signal)

信号(Signal)

Signals are a limited form of inter-process communication (IPC), typically used in Unix, Unix-like, and other POSIX-compliant operating systems. A signal is an asynchronous notification sent to a process or to a specific thread within the same process to notify it of an event. Signals originated in 1970s Bell Labs Unix and were later specified in the POSIX standard.

When a signal is sent, the operating system interrupts the target process’ normal flow of execution to deliver the signal. Execution can be interrupted during any non-atomic instruction. If the process has previously registered a signal handler, that routine is executed. Otherwise, the default signal handler is executed.

  ...


【Linux】命令 - cp

复制文件

# Copy a file to another location:
$ cp path/to/source_file.ext path/to/target_file.ext

# Copy a file into another directory, keeping the filename:
$ cp path/to/source_file.ext path/to/target_parent_directory
  ...


【IoT】Home Assistant 集成 Tuya(涂鸦) 设备

(depreciated) Install the old Tuya Home Assistant Integration

Adding Tuya to your Home Assistant instance can be done via the user interface, by taking the following steps:

After completing, the Tuya integration will be immediately available for use.

During configuration, be careful to select the country code and the platform corresponding to those used by you in the app. Once configuration flow is completed, the devices configured in your app will be automatically discovered.

Additionally, if your username or e-mail address isn’t accepted, please try using your phone number (minus the country code) as your username.

  ...


【IoT】安装 Home Assistant Core

Install on Raspberry Pi

# Install Software Properties Common
sudo apt install -y software-properties-common

# Add the Deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update; sudo apt install -y python3.12

# Update Python 3 to Point to the New Version
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.x 1
sudo update-alternatives --config python3

# verify
python3 --version

# homeassistant 2024.2.4 needs python3.12
sudo apt-get install python3.12-distutils
python3 -m pip install wheel
pip3 install homeassistant==2024.2.4

# 我出现了找不到该版本错误,2024.2.1 Requires-Python >=3.11.0
# 这时候需要升级 Python版本

ref

Install on Ubuntu

  ...


【NAS】DIY NAS

Background

RAID

  • RAID 0

    • File level writes, data duplicated on additional disks with no fault tolerance
  • RAID 1

    • Mirrored block level writes distributed across disks
  • RAID 5

    • 这个模式最少得3块以上的硬盘,属于RAID1 和 RAID0 之间,比如有4块硬盘组RIAD5,那么只会用一块硬盘进行保护,其它的空间可以叠加:
      • 空间大小:2+2+2+ 2 = 6T
    • 这个模式,可以最大的利用磁盘空间,也能保护磁盘,而且如果用SSD的话,硬盘速度也有叠加,不过缺点就是硬盘在损坏以后,换上新的硬盘后,重建数据的时间非常长,而重建过程中,如果再损坏一块硬盘,就全部玩完。
  • RAID 6

  • Block level writes distributed across disks, double distributed parity

  • RAID 10

  • 最多可以坏两个盘

    • RAID0和RAID1的结合,需要4个硬盘才行,先将2个硬盘进行RAID0,再将2个RAID0进行RAID1,可以保住数据安全的同时,提供硬盘速度。
  • RAID 6

    • 就是RAID5模式的加强版,用2个硬盘做冗余
  ...