クレジットは@Hackermanに行く:
$ cat /sys/block/sda/queue/rotational
0
それが1を返した場合、指定したファイルシステムは、回転メディアです。
私は確実にファイルが回転メディア上であるか否かを決定するシェルスクリプトにこの概念肉付けています(つまり/dev/sda1
がで実装されているプレーンなパーティション上の私の両方のための
#!/bin/bash
set -e
# emits the device path to the filesystem where the first argument lives
fs_mount="$(df -h $1 | tail -n 1 | awk '{print $1;}')"
# if it's a symlink, resolve it
if [ -L "$fs_mount" ]; then
fs_mount="$(readlink -f $fs_mount)"
fi
# if it's a device-mapper like LVM or dm-crypt, then we need to be special
if echo $fs_mount | grep -oP '/dev/dm-\d+' >/dev/null ; then
# get the first device slave
first_slave_dev="$(find /sys/block/$(basename $fs_mount)/slaves -mindepth 1 -maxdepth 1 -exec readlink -f {} \; | head -1)"
# actual device
dev="$(cd $first_slave_dev/../ && basename $(pwd))"
else
dev="$(basename $fs_mount | grep -ioP '[a-z]+(?=\d+\b)')"
fi
# now that we have the actual device, we simply ask whether it's rotational or not
if [[ $(cat /sys/block/$dev/queue/rotational) -eq 0 ]]; then
echo "The filesystem hosting $1 is not on an rotational media."
else
echo "The filesystem hosting $1 is on rotational media."
fi
上記の作品与えられたパスに/dev/mapper/crypt
がマウントされています)。私は近くにLVMがないので、LVMでテストしていません。
Bashが移植可能でないことに対する謝罪。
Linuxの場合: 'cat/sys/block/sda/queue/rotation' ハードディスクの場合は1、SSDの場合は0が必要です。 – Hackerman
@Hackermanまさに私が探していたもの、ありがとう。今は、dm-0を特定のデバイスまでトレースする方法を理解する必要があります。ウサギの穴を下に... –
Naftuli Kayを助けてうれしいです:) – Hackerman