🐑

繋いでいるHDDの情報を得るコマンド

2022/03/26に公開

これは何か

スクリプトの中に特定のデバイス(主にHDD)をコマンドからマウントしたいときがあります。

汎用化を考えると/dev/sdb1ではなくLABELUUID情報が欲しいです。
できればユーザー権限で実行できることに加え、未マウントデバイスを表示して欲しいです。
ここでは以下を紹介します。

  • よかったもの
  • lsblk -f
  • systemctl list-units
  • systemd-mount --list
  • gio mount -l
  • よくないもの
  • udisksctl status
  • df

精神衛生上、伏せ字が多いですがご了承ください。

各コマンド実行結果

  • lsblk -f
    • LABEL
    • UUID
$ lsblk -f

NAME   FSTYPE   LABEL          UUID                                 FSAVAIL FSUSE% MOUNTPOINT
loop0  squashfs                                                           0   100% /snap/bare/5
loop1  squashfs                                                           0   100% /snap/core20/1328
loop2  squashfs                                                           0   100% /snap/core20/1376
loop3  squashfs                                                           0   100% /snap/snap-store/558
loop4  squashfs                                                           0   100% /snap/snapd/15177
loop5  squashfs                                                           0   100% /snap/gtk-common-themes/1519
loop6  squashfs                                                           0   100% /snap/snapd/14978
loop7  squashfs                                                           0   100% /snap/gnome-3-38-2004/99
sda                                                                                
└─sda1 ext4     <このHDDのLAVEL>    <このHDDのUUID>                
sdb                                                                                
└─sdb1 ext4     <このHDDのLAVEL>    <このHDDのUUID>                
sdc                                                                                
└─sdc1 ext4     <このHDDのLAVEL>    <このHDDのUUID>                
sdd                                                                                
└─sdd1 ext4     <このHDDのLAVEL>    <このHDDのUUID>                
sde                                                                                
└─sde1 ext4     <このHDDのLAVEL>    <このHDDのUUID>                     656.7G    23% /media/user/<このHDDのLAVEL>
sdf                                                                                
├─sdf1 vfat                    **********                               505.8M     1% /boot/efi
└─sdf2 ext4                    <このHDDのUUID>                          339G    21% /
  • systemctl list-units
    • LABEL
    • UUID
$ systemctl list-units | head -20
  UNIT                                                                                                      LOAD   ACTIVE     SUB       DESCRIPTION                                                              
  proc-sys-fs-binfmt_misc.automount                                                                         loaded active     running   Arbitrary Executable File Formats File System Automount Point            
  dev-fuse.device                                                                                           loaded activating tentative /dev/fuse                                                                
  sys-devices-pci0000:00-0000:00:01.3-*************-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device     loaded active     plugged   WDC_W******++-********* <このHDDのLAVEL>                                      
  sys-devices-pci0000:00-0000:00:01.3-*************-ata1-host0-target0:0:0-0:0:0:0-block-sda.device          loaded active     plugged   WDC_W******++-*********                                                     
  sys-devices-pci0000:00-0000:00:01.3-*************-ata2-host1-target1:0:0-1:0:0:0-block-sdb-sdb1.device     loaded active     plugged   WDC_W******++-********* <このHDDのLAVEL>                                           
  sys-devices-pci0000:00-0000:00:01.3-*************-ata2-host1-target1:0:0-1:0:0:0-block-sdb.device          loaded active     plugged   WDC_W******++-*********                                                     
  sys-devices-pci0000:00-0000:00:01.3-*************-ata5-host4-target4:0:0-4:0:0:0-block-sdc-sdc1.device     loaded active     plugged   TOSHIBA_************* <このHDDのLAVEL>                                             
  sys-devices-pci0000:00-0000:00:01.3-*************-ata5-host4-target4:0:0-4:0:0:0-block-sdc.device          loaded active     plugged   TOSHIBA_*************                                                       
  sys-devices-pci0000:00-0000:00:01.3-*************-ata6-host5-target5:0:0-5:0:0:0-block-sdd-sdd1.device     loaded active     plugged   ST********004-******* <このHDDのLAVEL>                                           
  sys-devices-pci0000:00-0000:00:01.3-*************-ata6-host5-target5:0:0-5:0:0:0-block-sdd.device          loaded active     plugged   ST********004-*******                                                       
  sys-devices-pci0000:00-**************************************************************.device              loaded active     plugged   RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller                
  sys-devices-pci0000:00-0000:00:03.1-0000:08:00.1-sound-card0.device                                       loaded active     plugged   TU116 High Definition Audio Controller                                   
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.2-ata11-host10-target10:0:0-10:0:0:0-block-sde-sde1.device loaded active     plugged   WDC_********+++-0****** <このHDDのLAVEL>                                          
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.2-ata11-host10-target10:0:0-10:0:0:0-block-sde.device      loaded active     plugged   WDC_********+++-0******                                                      
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.2-ata12-host11-target11:0:0-11:0:0:0-block-sdf-sdf1.device loaded active     plugged   メインのSSD***** EFI\x20System\x20Partition                                
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.2-ata12-host11-target11:0:0-11:0:0:0-block-sdf-sdf2.device loaded active     plugged   メインのSSD***** 2                                                         
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.2-ata12-host11-target11:0:0-11:0:0:0-block-sdf.device      loaded active     plugged   メインのSSD*****                                                           
  sys-devices-pci0000:00-0000:00:08.1-0000:0a:00.3-sound-card1.device                                       loaded active     plugged   Family 17h (Models 00h-0fh) HD Audio Controller                          
  • systemd-mount --list
    • LABEL
    • UUID
$ systemd-mount --list
NODE       PATH                   MODEL                WWN                TYPE     LABEL                      UUID                                
/dev/loop0 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop1 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop2 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop3 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop4 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop5 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop6 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/loop7 n/a                    n/a                  n/a                squashfs n/a                        n/a                                 
/dev/sda1  pci-*************-ata-1 WDC_W******++-********* 0x*************** ext4     <このHDDのLAVEL>             <このHDDのUUID>
/dev/sdb1  pci-*************-ata-2 WDC_W******++-********* 0x*************** ext4     <このHDDのLAVEL>                  <このHDDのUUID>
/dev/sdc1  pci-*************-ata-5 TOSHIBA_*************   0x*************** ext4     <このHDDのLAVEL>                  <このHDDのUUID>
/dev/sdd1  pci-*************-ata-6 ST********004-*******   0x*************** ext4     <このHDDのLAVEL>                <このHDDのUUID>
/dev/sde1  pci-0000:0a:00.2-ata-3 WDC_********+++-0******  0x*************** ext4     <このHDDのLAVEL>                <このHDDのUUID>
/dev/sdf1  pci-0000:0a:00.2-ata-4 メインのSSD*****       0x*************** vfat     EFI\x20System\x20Partition **********                           
/dev/sdf2  pci-0000:0a:00.2-ata-4 メインのSSD*****       0x*************** ext4     n/a                        <このHDDのUUID>
  • gio mount -l
    • LABEL
    • UUID ×
$ gio mount -l

Drive(0): WDC W******++-*********
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  Volume(0): <このHDDのLAVEL>
    Type: GProxyVolume (GProxyVolumeMonitorUDisks2)
Drive(1): WDC W******++-*********
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  Volume(0): <このHDDのLAVEL>
    Type: GProxyVolume (GProxyVolumeMonitorUDisks2)
Drive(2): TOSHIBA *************
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  Volume(0): <このHDDのLAVEL>
    Type: GProxyVolume (GProxyVolumeMonitorUDisks2)
Drive(3): ST********004-*******
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  Volume(0): <このHDDのLAVEL>
    Type: GProxyVolume (GProxyVolumeMonitorUDisks2)
Drive(4): WDC ********+++-0******
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  Volume(0): <このHDDのLAVEL>
    Type: GProxyVolume (GProxyVolumeMonitorUDisks2)
    Mount(0): <このHDDのLAVEL> -> file:///media/user/<このHDDのLAVEL>
      Type: GProxyMount (GProxyVolumeMonitorUDisks2)
Drive(5): メインのSSD*****
  Type: GProxyDrive (GProxyVolumeMonitorUDisks2)
  • udisksctl status
    • LABEL ×
    • UUID ×
$ udisksctl status

MODEL                     REVISION  SERIAL               DEVICE
--------------------------------------------------------------------------
WDC W******++-*********      80.00A80  WD-****************      sda     
WDC W******++-*********      80.00A80  WD-****************      sdb     
TOSHIBA *************        FP2A      ****************         sdc     
ST********004-*******        0001      ****************             sdd     
WDC ********+++-0******       01.00A01  WD-****************      sde     
メインのSSD*****            M3CR043   ****************         sdf   

こうすると分かる

$ udisksctl info -b /dev/sdb1

/org/freedesktop/UDisks2/block_devices/sdb1:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdb1
    DeviceNumber:               2065
    Drive:                      '/org/freedesktop/UDisks2/drives/WDC_W******++_*********_WD_****************'
    HintAuto:                   false
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 true
    Id:                         by-id-ata-WDC_W******++-*********_WD-****************-part1
    IdLabel:                    <このHDDのLAVEL>
    IdType:                     ext4
    IdUUID:                     <このHDDのUUID>
    IdUsage:                    filesystem
    IdVersion:                  1.0
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sdb1
    ReadOnly:                   false
    Size:                       2000397795328
    Symlinks:                   /dev/disk/by-id/ata-WDC_W******++-*********_WD-****************-part1
                                /dev/disk/by-id/wwn-0x****************-part1
                                /dev/disk/by-label/<このHDDのLAVEL>
                                /dev/disk/by-partuuid/****************
                                /dev/disk/by-path/pci-*************-ata-2-part1
                                /dev/disk/by-uuid/<このHDDのUUID>
    UserspaceMountOptions:      
  org.freedesktop.UDisks2.Filesystem:
    MountPoints:        
    Size:               2000397795328
  org.freedesktop.UDisks2.Partition:
    Flags:              0
    IsContained:        false
    IsContainer:        false
    Name:               
    Number:             1
    Offset:             1048576
    Size:               2000397795328
    Table:              '/org/freedesktop/UDisks2/block_devices/sdb'
    Type:               0x83
    UUID:               *********-01
$ udisksctl info -d WDC_W******++_*********_WD_****************

/org/freedesktop/UDisks2/drives/WDC_W******++_*********_WD_****************:
  org.freedesktop.UDisks2.Drive:
    CanPowerOff:                false
    Configuration:              {}
    ConnectionBus:              
    Ejectable:                  false
    Id:                         WDC-W******++-*********-WD-****************
    Media:                      
    MediaAvailable:             true
    MediaChangeDetected:        true
    MediaCompatibility:         
    MediaRemovable:             false
    Model:                      WDC W******++-*********
    Optical:                    false
    OpticalBlank:               false
    OpticalNumAudioTracks:      0
    OpticalNumDataTracks:       0
    OpticalNumSessions:         0
    OpticalNumTracks:           0
    Removable:                  false
    Revision:                   80.00A80
    RotationRate:               -1
    Seat:                       seat0
    Serial:                     WD-****************
    SiblingId:                  
    Size:                       2000398934016
    SortKey:                    *********/00fixed/sd____b
    TimeDetected:               1648254154207087
    TimeMediaDetected:          1648254154207087
    Vendor:                     
    WWN:                        0x*********
  org.freedesktop.UDisks2.Drive.Ata:
    AamEnabled:                                 false
    AamSupported:                               false
    AamVendorRecommendedValue:                  0
    ApmEnabled:                                 false
    ApmSupported:                               false
    PmEnabled:                                  true
    PmSupported:                                true
    ReadLookaheadEnabled:                       true
    ReadLookaheadSupported:                     true
    SecurityEnhancedEraseUnitMinutes:           266
    SecurityEraseUnitMinutes:                   266
    SecurityFrozen:                             true
    SmartEnabled:                               true
    SmartFailing:                               false
    SmartNumAttributesFailedInThePast:          0
    SmartNumAttributesFailing:                  0
    SmartNumBadSectors:                         0
    SmartPowerOnSeconds:                        71092800
    SmartSelftestPercentRemaining:              0
    SmartSelftestStatus:                        success
    SmartSupported:                             true
    SmartTemperature:                           305.15000000000003
    SmartUpdated:                               1648278602
    WriteCacheEnabled:                          true
    WriteCacheSupported:                        true

実際のマウント

gioコマンドやudisksctlコマンドなどをスクリプト中に入れれば良いと思います。

$ gio mount -d <このHDDのUUID>

Discussion