Skip to main content

硬盘管理和维护

项目描述

osso-docktool提供了将磁盘注册到 OSSO 仪表板、打印标签和擦除磁盘的工具。

要求(apt install --no-install-recommends):

tmux            # auto cli mode
coreutils       # dd
pwgen           # pwgen
smartmontools   # smartctl
nvme-cli        # nvme
hdparm          # hdparm
sdparm          # sdparm
ledmon          # LED control

# FIXME: /usr/local/bin/run-lessrandom
# FIXME: /usr/local/bin/run-zero-disk

示例用法(以 root 身份):

osso-docktool /dev/sdb

示例设置(以 root 身份):

pip3 install osso-docktool

install -dm0700 /etc/osso-docktool
install /usr/local/share/doc/osso-docktool/local_settings.py.template \
        /etc/osso-docktool/local_settings.py

${EDITOR:-vi} /etc/osso-docktool/local_settings.py
# ^-- fix hostnames, fix tokens
#     get 1 shared token from:
#     https://account.example.com/admin/usertoken/token/
#     If you wish to use the auto process you will want to add the
#     root disk to the IGNORE_DEVICES list.

自动化

/etc/udev/rules.d/10-osso-docktool.rules:

# Match the block device but not the partitions.
KERNEL=="sd[a-z]", SUBSYSTEM=="block", ACTION=="add", ENV{SYSTEMD_WANTS}+="osso-docktool@%k.service", TAG+="systemd"

/etc/systemd/system/osso-docktool@.service:

[Unit]
Description=Notify osso-docktool about disk %i
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/osso-docktool auto-notify --add /dev/%i
ExecStop=/usr/local/bin/osso-docktool auto-notify --remove /dev/%i

当插入磁盘时,这将启动 osso-docktool@<disk>.service通知 osso-docktool 自动进程。该服务是必需的,因为 udev 在没有网络访问权限的受限容器中启动 RUN 命令,并且 systemd 进程在受限容器之外启动。

当磁盘被移除时,systemd 将停止 osso-docktool@<disk>.service。

有几个自动命令请注意,这两个擦除命令都会在不确认的情况下擦除所有与忽略列表不匹配的插入磁盘!

EMAIL=me@example.com osso-docktool auto

默认情况下,它使用 tmux 会话来生成 osso-docktool 命令,但有一个-g|–gui切换开关来切换到图形终端。您可以使用以下命令更改默认图形终端:

update-alternatives --config x-terminal-emulator

其他工具

/usr/local/bin/run-zero-disk (0700):

#!/bin/bash

path=$1
if test -z $path; then
    echo "please supply path as argument"
    exit 1
fi
output=$(dd if=/dev/zero \
   of=$path \
   bs=32M \
   conv=fsync 2>&1)
ret=$?

# Checking output as DD does not exit clean even if whole disk is wiped

if [[ $ret -eq 0 ]]; then
    exit 0
else
    if [[ $output == *'No space left on device'* ]]; then
        echo "Disk $path has been zeroed"
        exit 0
    else
        echo "Something went wrong while writing to $path"
        echo $output
        exit 1
    fi
fi

编译lessrandom.c 并将lessrandom 移动到/usr/local/bin/lessrandom (0700):

lessrandom.c:

#include <stdio.h>
#include <time.h>
#define BUF 4096
int main() {
    FILE *f;
    char buf[BUF];
    f = fopen("/dev/urandom", "rb");
    while (1) {
        if (fread(buf, 1, BUF, f) == BUF) {
            int i;
            for (i = 0; i <= buf[0]; ++i) {
                fwrite(buf, 1, BUF - 1, stdout);
            }
        }
    }
    fclose(f);
    return 0;
}


gcc -Wall lessrandom.c -o lessrandom

/usr/local/bin/run-lessrandom (0700):

#!/bin/bash

path=$1
if test -z $path; then
    echo "please supply path as argument"
    exit 1
fi
output=$(dd if=<(/usr/local/bin/lessrandom) \
   of=$path \
   bs=32M \
   conv=fsync 2>&1)
ret=$?

# Checking output as DD does not exit clean even if whole disk is wiped

if [[ $ret -eq 0 ]]; then
    exit 0
else
    if [[ $output == *'No space left on device'* ]]; then
        echo "Disk $path has been wiped"
        exit 0
    else
        echo "Something went wrong while writing to $path"
        echo $output
        exit 1
    fi
fi

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

osso-docktool-1.9.0.tar.gz (31.6 kB 查看哈希)

已上传 source

内置分布

osso_docktool-1.9.0-py3-none-any.whl (37.0 kB 查看哈希)

已上传 py3