systemd로 디스크를 어떻게 끄나요?

systemd로 디스크를 어떻게 끄나요?

SSD와 기존 하드 디스크가 모두 포함된 Ubuntu 시스템이 여러 대 있는데, 하드 디스크는 가끔씩만 사용됩니다.

소음, 발열, 전력 소모를 줄이고 하드 디스크의 수명을 연장한다는 이유로 부팅할 때마다 끄고 필요할 때만 깨우고 싶습니다.

hdparm -y(또는 -Y)은 명령줄에서 꽤 잘 작동하고 내가 원하는 것을 정확히 수행합니다.

그러나 실행할 시스템 서비스를 작성하는 hdparm것은 작동하지 않습니다. 더 정확하게 말하자면, 작동하고 디스크가 실제로 절전 모드로 전환되지만(디버깅에서 알 수 있듯이) 시스템에 하드 디스크에 액세스하는(따라서 절전 모드를 해제하는) 무언가가 있기 때문에 즉시 다시 깨어납니다(그리고 깨어 있는 상태를 유지합니다). it) 시스템 부팅 프로세스의 마지막 부분에 있습니다.

hdparm -y그렇다면 더 이상 다른 프로세스가 뒤따르지 않을 정도로 늦게 부팅 프로세스에 를 넣을 수 있는 방법은 무엇입니까 ?

내 마지막 추측은 systemd의 기본 대상을 그래픽에서 새 대상(슬리피디스크)으로 변경하는 것인데, 이는 이전 그래픽 대상에 따라 달라집니다.

하지만 디스크를 끄는 더 쉽고 간단한 방법은 없을까요?

문안 인사

답변1

디스크 유틸리티를 열고 10분 동안 활동이 없으면 드라이브가 자동으로 스핀다운되도록 설정합니다.

답변2

hdparm의 -S 옵션을 사용하십시오. 이는 드라이브에서 유지해야 하는 스핀다운 시간 제한을 설정합니다.

$ hdparm --help
-S   Set standby (spindown) timeout

$ hdparm -S 60 /dev/sdd
/dev/sdd:
 setting standby to 60 (5 minutes)

대문자 'S'라는 점에 유의하세요.

답변3

다음 스크립트를 사용하여 유휴 디스크를 스핀다운하도록 "강제"합니다. 여기서 강제란 많은 WD 드라이브가 자체 스핀다운에 문제가 있기 때문에 드라이브에 직접 명령을 내리는 것을 의미합니다. 아마도 이를 필요에 따라 확장할 수 있습니다. 스크립트에 주석이 잘 되어 있어서 아주 쉽게 수정할 수 있을 것입니다. 20분 마다 호출하고 cron필요에 따라 조정합니다.

spindown.sh

#!/usr/bin/env bash

logger "[SPINDOWN] Checking disk activity and spinning down idles..."

# Exit during maintenance
if pgrep snapraid > /dev/null; then
    logger "[SPINDOWN] Detected snapRAID maintenance. Exiting.";
    exit 0
fi

# Specify any drives you want to ignore; separate multiple drives by spaces; e.g. "sda sdb"
IGNORE_DRIVES=""

PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

# Check for idle disks and spin them down unless smartd is running tests

# Create a file on the ramdisk and cycle it to test for disk activity
(   if [ ! -f /dev/shm/diskstats_1 ]; then 
        logger "[SPINDOWN] Creating initial state file on ramdisk";
        touch /dev/shm/diskstats_1;
    fi ; 
    logger "[SPINDOWN] Updating state files on ramdisk";
    mv /dev/shm/diskstats_1 /dev/shm/diskstats_2; 
    cat /proc/diskstats > /dev/shm/diskstats_1 ) > /dev/null 2>&1

# Find all removable USB drives, so we can ignore them later,
# see http://superuser.com/a/465953
REMOVABLE_DRIVES=""
for _device in /sys/block/*/device; do
    if echo $(readlink -f "$_device")|egrep -q "usb"; then
        _disk=$(echo "$_device" | cut -f4 -d/)
        REMOVABLE_DRIVES="$REMOVABLE_DRIVES $_disk"
    fi
done

# Append detected removable drives to manually ignored drives
IGNORE_DRIVES="$IGNORE_DRIVES $REMOVABLE_DRIVES"

# Loop through all the array disks and spin down the idle disks. Will find all drives sda > sdz AND sdaa > sdaz...
logger "[SPINDOWN] Looping through drives to detect idle state"
for disk in `find /dev/ -regex '/dev/sd[a-z]+' | cut -d/ -f3`
do
    # Skip removable USB drives and those the user wants to ignore
    if [[ $IGNORE_DRIVES =~ $disk ]]; then
        continue
    fi

    # Skip SSDs
    if [[ $(cat /sys/block/$disk/queue/rotational) -eq 0 ]]; then
        continue
    fi

    # Check if drive exists
    if [ -e /dev/$disk ]; then
        logger "[SPINDOWN] Checking drive $disk"
        # Check if drive is currently spinning
        if [ "$(smartctl -i -n standby /dev/$disk | grep "ACTIVE or IDLE")" ]; then
            logger "[SPINDOWN] Disk $disk is ACTIVE or IDLE. Checking for selftest"
            # Check if smartctl is currently not running a self test
            if [ $(smartctl -a /dev/$disk | grep -c "Self-test routine in progress") = 0 ]; then
            logger "[SPINDOWN] Disk $disk is not running a self test. Checking activity."
                # Check if drive has been non idle since last run
                if [ "$(diff /dev/shm/diskstats_1 /dev/shm/diskstats_2 | grep $disk )" = "" ]; then
                    logger "[SPINDOWN] Spinning down /dev/$disk `df -h | grep /dev/$disk | rev | cut -d ' ' -f 1 | rev`"
                    hdparm -y /dev/$disk
                fi
            else
                logger "[SPINDOWN] /dev/$disk is running Self-test routine. Skipping."
            fi
        fi
    fi
done

특정 질문에 따라 systemd로 어떻게 수행합니까? ... 이 스크립트를 호출하는 타이머 파일을 생성합니다(참조:https://wiki.archlinux.org/index.php/Systemd/Timers)

관련 정보