Posts in category “Linux”

继续折腾:在 Asus C100P 上安装 postmarketOS 简要记录

这篇blog教你如何将 postmarketOS 安装到 C100P 的内置emmc硬盘上。我装了最新的 edge 系统和 Mate桌面,还余 10G空间可用。

步骤 1: 安装 pmbootstrap

首先,在 Debian 12 上通过 git 安装最新版 pmbootstrap:

git clone https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
cd pmbootstrap
mkdir -p ~/.local/bin
ln -s "$PWD/pmbootstrap.py" ~/.local/bin/pmbootstrap
pmbootstrap --version

确保把 ~/.local/bin 添加到你的 PATH 环境变量中。

步骤 2: 初始化 pmbootstrap

运行 pmbootstrap --init,如果有缺少的依赖包,按提示使用 sudo apt install <package> 安装。对于厂商,选择 google 而不是 asus,对于 codename,选择 veyron

步骤 3: 准备优盘

准备一个优盘并接入电脑,运行 sudo fdisk -l 来确认优盘的设备名(通常是 /dev/sdb 或其他)。一定要小心,不要选错设备名,否则可能会导致数据丢失。然后使用以下命令开始安装:

pmbootstrap install --sdcard /dev/sdx

注意,将 /dev/sdx 替换为你自己的优盘设备名。

步骤 4: 如果出现挂载错误

如果出现挂载错误,尝试换一块优盘。我遇到的问题是,128GB 的 Sandisk 优盘无法正常工作,但换成了一块 32GB 的 SD 卡后就顺利安装了。

步骤 5: 启动到 Asus C100P 上

用准备好的优盘启动 Asus C100P,连接 Wi-Fi 网络。

步骤 6: 安装 pmbootstrap 到 C100P

在 C100P 上安装 pmbootstrap,按照步骤 1 中的方式安装。

步骤 7: 初始化 pmbootstrap

在 C100P 上运行 pmbootstrap init,按照步骤 2 中的说明完成初始化。

步骤 8: 安装到 eMMC

运行以下命令将 postmarketOS 安装到 eMMC:

pmbootstrap install --sdcard /dev/mmcblk0

步骤 9: 完成并移除优盘

安装完成后,拔掉优盘,你的 Asus C100P 上就安装好了 postmarketOS!

AI Prompt for Git Commit Messages

Analyze the following code changes and generate a concise, meaningful git commit message that:

1. Summarizes the main purpose or impact of the changes
2. Is no longer than 100 characters (150 characters maximum if absolutely necessary)
3. Uses present tense and imperative mood (e.g., "Add feature" not "Added feature")
4. Focuses on the "what" and "why" rather than the "how"

Provide ONLY the commit message itself, without any additional text, explanations, or formatting.

Code changes:

I have used it in my bash script ci and it works very well! ...

How to Avoid SSH's "Are you sure you want to continue connecting?" Prompt

If you're tired of seeing the "Are you sure you want to continue connecting (yes/no/[fingerprint])?" prompt every time you SSH into a new server, you're not alone. This security feature, while important, can be a bit of a nuisance for system administrators and developers who frequently connect to new machines. This is especially true when they wish to run a remote command on a newly trusted machine. Let's explore how to streamline this process without completely compromising security.

Understanding the Prompt

First, it's important to understand why this prompt appears. It's a security measure designed to protect you from man-in-the-middle attacks by verifying the authenticity of the server you're connecting to. However, in controlled environments or for non-critical systems, you might want to bypass this prompt.

The Quick Fix: StrictHostKeyChecking

One simple way to avoid this prompt is by using the StrictHostKeyChecking option. You can add this to your SSH command like this:

ssh -o StrictHostKeyChecking=accept-new user@hostname

But what if you want to make this change permanent? You can add it to your SSH config file:

  1. Open or create your SSH config file:

    vim ~/.ssh/config
    
  2. Add the following line:

    StrictHostKeyChecking accept-new
    

This setting will automatically accept and save new host keys without prompting, while still warning you if a known host's key has changed.

Security Considerations

While this method is convenient, it's important to understand the security implications:

  • It automatically accepts keys from new, unknown hosts.
  • It still protects you from potential man-in-the-middle attacks on known hosts.
  • It assumes you trust your network and the new hosts you're connecting to.

When to Use This Method

This approach is best suited for:

  • Environments where you frequently connect to new, trusted hosts.

  • Controlled, secure networks.

  • Scenarios where the convenience outweighs the risk of not manually verifying each new host.

使用 rsync 增量备份文件

通常 A 机器和 B 机器已经在 ~/.ssh/config 中定义并建立了信任关系,因此我们可以直接使用主机别名,而不需要使用 user@B_machine 的方式。

sync_files.sh 脚本

#!/bin/bash

# 定义源和目标目录
SOURCE_DIR="/data/files/"
DEST_DIR="B_machine:~/backups/A_machine/data/files"

# 执行 rsync 命令
rsync -av --exclude='tmp/' "$SOURCE_DIR" "$DEST_DIR"
  1. 确保脚本有执行权限:

    chmod +x sync_files.sh
    
  2. 使用 cron 设置每五分钟执行一次该脚本:

    crontab -e
    

    添加:

    */5 * * * * /path/to/sync_files.sh
    

/var/log/journal 占了2.8GB,有没有办法一劳永逸的解决这个问题?

在 Linux 系统上,/var/log/journal 目录通常用来存储系统日志。如果这个目录占用了过多的空间,可以通过以下几种方法来管理和限制日志的大小:

1. 修改 journald 配置

你可以通过修改 journald 的配置文件来设置日志的最大大小和保留时间:

  1. 打开终端。

  2. 编辑 journald 配置文件:

    sudo nano /etc/systemd/journald.conf
    
  3. 在文件中添加或修改以下配置项:

    [Journal]
    SystemMaxUse=500M
    SystemKeepFree=100M
    SystemMaxFileSize=50M
    SystemMaxFiles=10
    

    这些选项的含义如下:

    • SystemMaxUse:限制日志的总大小。
    • SystemKeepFree:保留的磁盘空间。
    • SystemMaxFileSize:每个日志文件的最大大小。
    • SystemMaxFiles:最大日志文件数。
  4. 保存文件并退出编辑器。

  5. 重新启动 journald 服务以应用更改:

    sudo systemctl restart systemd-journald
    

2. 清理现有日志

如果你想立即释放一些空间,可以手动清理旧的日志文件:

sudo journalctl --vacuum-size=500M

这条命令会将日志文件的总大小限制在 500MB。

3. 定期清理日志

你可以使用 cron 任务来定期清理日志。例如,可以设置一个每天执行的任务来保持日志的大小在一个合理的范围内。

  1. 打开 cron 编辑器:

    crontab -e
    
  2. 添加以下行以每天清理日志:

    0 0 * * * /usr/bin/journalctl --vacuum-time=7d
    

    这样设置后,系统将每天清理超过 7 天的日志。