やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

RaspbianでUSB接続したデバイス名を調べる方法まとめ

 SDカードやHDDなどはlsblkがおすすめ。

対象環境

コマンド

  • A. ls /dev
  • B. df
  • C. lsblk
  • D. lsusb
  • E. sudo parted -l
  • F. sudo fdisk -l

A. ls /dev

$ ls /dev
autofs           loop5               ram7     tty15  tty42      uinput
block            loop6               ram8     tty16  tty43      urandom
bsg              loop7               ram9     tty17  tty44      vc-cma
btrfs-control    mapper              random   tty18  tty45      vc-mem
bus              mem                 raw      tty19  tty46      vchiq
cachefiles       memory_bandwidth    rfkill   tty2   tty47      vcio
char             mmcblk0             sda      tty20  tty48      vcs
console          mmcblk0p1           sda1     tty21  tty49      vcs1
cpu_dma_latency  mmcblk0p2           sda2     tty22  tty5       vcs2
cuse             mqueue              sda3     tty23  tty50      vcs3
disk             net                 sda5     tty24  tty51      vcs4
fb0              network_latency     sda6     tty25  tty52      vcs5
fd               network_throughput  sda7     tty26  tty53      vcs6
full             null                sdb      tty27  tty54      vcs7
fuse             ppp                 serial1  tty28  tty55      vcsa
gpiomem          ptmx                sg0      tty29  tty56      vcsa1
hidraw0          pts                 sg1      tty3   tty57      vcsa2
hidraw1          ram0                shm      tty30  tty58      vcsa3
hidraw2          ram1                snd      tty31  tty59      vcsa4
hwrng            ram10               stderr   tty32  tty6       vcsa5
initctl          ram11               stdin    tty33  tty60      vcsa6
input            ram12               stdout   tty34  tty61      vcsa7
kmsg             ram13               tty      tty35  tty62      vcsm
log              ram14               tty0     tty36  tty63      vhci
loop-control     ram15               tty1     tty37  tty7       watchdog
loop0            ram2                tty10    tty38  tty8       watchdog0
loop1            ram3                tty11    tty39  tty9       xconsole
loop2            ram4                tty12    tty4   ttyAMA0    zero
loop3            ram5                tty13    tty40  ttyprintk
loop4            ram6                tty14    tty41  uhid

 RAMディスクなども含まれている。

B. df

$ df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/root        7.8G  6.2G  1.3G   84% /
devtmpfs         459M     0  459M    0% /dev
tmpfs            463M   32M  432M    7% /dev/shm
tmpfs            463M  6.7M  457M    2% /run
tmpfs            5.0M  4.0K  5.0M    1% /run/lock
tmpfs            463M     0  463M    0% /sys/fs/cgroup
/dev/sda6         30G  4.7G   24G   17% /home
tmpfs             32M  236K   32M    1% /var/log
tmpfs             16M   16K   16M    1% /var/tmp
tmpfs            500M   20K  500M    1% /tmp
/dev/mmcblk0p1    63M   22M   42M   35% /boot
/dev/sda5         40G  3.7G   34G   10% /usr
tmpfs             93M     0   93M    0% /run/user/1000
/dev/sda7         26G   44M   24G    1% /media/pi/e46c667d-9f7b-4928-9fc0-9253d9175958
/dev/sda2        118G  1.5G  111G    2% /media/pi/8dad33d8-20b6-4fcb-9976-4d95080c7438

 マウントされていないデバイス/dev/sdbは表示されていない。

C. lsblk

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 223.6G  0 disk 
├─sda1        8:1    0     8G  0 part /
├─sda2        8:2    0   120G  0 part /media/pi/8dad33d8-20b6-4fcb-9976-4d95080c
├─sda3        8:3    0     1K  0 part 
├─sda5        8:5    0    40G  0 part /usr
├─sda6        8:6    0    30G  0 part /home
└─sda7        8:7    0  25.6G  0 part /media/pi/e46c667d-9f7b-4928-9fc0-9253d917
sdb           8:16   0 931.5G  0 disk 
mmcblk0     179:0    0  14.5G  0 disk 
├─mmcblk0p1 179:1    0    63M  0 part /boot
└─mmcblk0p2 179:2    0  14.4G  0 part 

 マウントされていないデバイス/dev/sdbも表示されている。

D. lsusb

$ lsusb
Bus 001 Device 006: ID 05e3:0718 Genesys Logic, Inc. IDE/SATA Adapter
Bus 001 Device 005: ID 046d:c043 Logitech, Inc. MX320/MX400 Laser Mouse
Bus 001 Device 008: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. 
Bus 001 Device 007: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 004: ID 099a:0638 Zippy Technology Corp. Sanwa Supply Inc. Small Keyboard
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 USBデバイスの名前。

E. sudo parted -l

$ sudo parted -l
Error: Can't have a partition outside the disk!
Ignore/Cancel? i                                                          
Error: Can't have a partition outside the disk!
Ignore/Cancel? i                                                          
Model: Netac SS D 240GB (scsi)
Disk /dev/sda: 240GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  8591MB  8590MB  primary   ext4
 2      8591MB  137GB   129GB   primary   ext4
 3      137GB   240GB   103GB   extended
 5      137GB   180GB   42.9GB  logical   ext4
 6      180GB   213GB   32.2GB  logical   ext4
 7      213GB   240GB   27.5GB  logical   ext4


Model: SD SD16G (sd/mmc)
Disk /dev/mmcblk0: 15.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  70.3MB  66.1MB  primary  fat16        lba
 2      70.3MB  15.5GB  15.5GB  primary  ext4

F. sudo fdisk -l

$ sudo fdisk -l
fdisk: cannot open /dev/ram0: 許可がありません
fdisk: cannot open /dev/ram1: 許可がありません
fdisk: cannot open /dev/ram2: 許可がありません
fdisk: cannot open /dev/ram3: 許可がありません
fdisk: cannot open /dev/ram4: 許可がありません
fdisk: cannot open /dev/ram5: 許可がありません
fdisk: cannot open /dev/ram6: 許可がありません
fdisk: cannot open /dev/ram7: 許可がありません
fdisk: cannot open /dev/ram8: 許可がありません
fdisk: cannot open /dev/ram9: 許可がありません
fdisk: cannot open /dev/ram10: 許可がありません
fdisk: cannot open /dev/ram11: 許可がありません
fdisk: cannot open /dev/ram12: 許可がありません
fdisk: cannot open /dev/ram13: 許可がありません
fdisk: cannot open /dev/ram14: 許可がありません
fdisk: cannot open /dev/ram15: 許可がありません
fdisk: cannot open /dev/mmcblk0: 許可がありません
fdisk: cannot open /dev/sda: 許可がありません
fdisk: cannot open /dev/sdb: 許可がありません

 sudoを付与してやるとディスク容量やセクタ単位などがわかる。

$ sudo fdisk -l
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram1: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram2: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram3: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram4: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram5: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram6: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram7: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram8: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram9: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram10: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram11: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram12: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram13: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram14: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram15: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mmcblk0: 14.5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc06b0477

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      137216 30318591 30181376 14.4G 83 Linux

Disk /dev/sda: 223.6 GiB, 240057407488 bytes, 468862124 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2063388e

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1            2048  16779263  16777216    8G 83 Linux
/dev/sda2        16779264 268437503 251658240  120G 83 Linux
/dev/sda3       268437504 468862125 200424622 95.6G  5 Extended
/dev/sda5       268439552 352325631  83886080   40G 83 Linux
/dev/sda6       352327680 415242239  62914560   30G 83 Linux
/dev/sda7       415244288 468862125  53617838 25.6G 83 Linux

Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes