有没有办法让 udisksctl 列出所有分区和块设备?

有没有办法让 udisksctl 列出所有分区和块设备?

我看见https://stackoverflow.com/questions/200960/find-all-storage-devices-attached-to-a-linux-machine#201091虽然这很酷,但我想知道是否可以通过使用 udisksctl 来实现类似的效果。它应该作为帮助给出足够的指示 -

[$] udisksctl help

Usage:
  udisksctl COMMAND

Commands:
  help            Shows this information
  info            Shows information about an object
  dump            Shows information about all objects
  status          Shows high-level status
  monitor         Monitor changes to objects
  mount           Mount a filesystem
  unmount         Unmount a filesystem
  unlock          Unlock an encrypted device
  lock            Lock an encrypted device
  loop-setup      Set-up a loop device
  loop-delete     Delete a loop device
  power-off       Safely power off a drive
  smart-simulate  Set SMART data for a drive

Use "udisksctl COMMAND --help" to get help on each command.

使用

[$] udisksctl status /dev/sd

确实为您提供了所有硬盘、笔式驱动器/SSD 等的列表,但不提供分区。有任何想法吗 ?

答案1

for disk in /dev/sd[a-z] /dev/sd[a-z][a-z]; do
  if test -b $disk; then
    echo; echo ------------------ Disk $disk ------------------
    udisksctl info -b $disk
    for partition in $disk[1-9] $disk[0-9][0-9]; do
      if test -b $partition; then
        echo; echo ------------------ Partition $partition ------------------
        udisksctl info -b $partition
      fi
    done
  fi
done

相关内容