10

How can I tell which device the USB drive is assigned as?

Before inserting the USB drive:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
nvme0n1     259:0    0 238.5G  0 disk 
├─nvme0n1p5 259:3    0  15.9G  0 part [SWAP]
├─nvme0n1p1 259:1    0 222.6G  0 part /
└─nvme0n1p2 259:2    0     1K  0 part 

After:

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1   1.9G  0 disk 
├─sda2        8:2    1   2.4M  0 part 
└─sda1        8:1    1   1.2G  0 part 
nvme0n1     259:0    0 238.5G  0 disk 
├─nvme0n1p5 259:3    0  15.9G  0 part [SWAP]
├─nvme0n1p1 259:1    0 222.6G  0 part /
└─nvme0n1p2 259:2    0     1K  0 part 

Is it /dev/sda??

Jacob Vlijm
  • 83,767
Run
  • 2,639

4 Answers4

14

Simply use lsblk output options to find it out:

lsblk -o NAME,TRAN

which produces:

sda                    sata
├─sda1
└─sda2           
sdb                    usb
└─sdb1                 
sr0                    sata

You can also use other options to get extra information (e.g: SIZE).
If you want a nice clean output use -S:

$ lsblk -So NAME,SIZE,TRAN

NAME   SIZE  TRAN
sda    400G  sata
sdb    16G   usb
sr0    1024M sata
Ravexina
  • 55,668
  • 25
  • 164
  • 183
4

How to find out which of your devices is a usb device

In short:

find /dev/disk -ls | grep usb

Or, on a specific device:

find /dev/disk -ls | grep usb | grep sda

If it has any output, sda is a usb device.

Long version

Information on your devices is to be found in the directory /dev/disk. Specifically the sub directories /dev/disk/by-id and /dev/disk/by-path give us information on wheter a device is a usb device or not. For example a name like:

usb-0930_USB_Flash_Memory_04506470B2D398CF-0:0

makes clear this is a usb drive.

If I run ls -l on the file, the output is:

lrwxrwxrwx 1 root root 9 apr 27 09:21 /dev/disk/by-id/usb-0930_USB_Flash_Memory_04506470B2D398CF-0:0 -> ../../sdb

which clearly shows this is sdb

Using find to filter out usb devices

The find ... -ls command, will subsequently give us the information we need.

You can easily find out which of the devices is a usb device by running the command:

find /dev/disk -ls | grep usb

To check if specifically sda is a usb device, run:

find /dev/disk -ls | grep usb | grep sda

If it has any output, it is a usb device.

It obviously looks like your usb device has two partitions:

sda           8:0    1   1.9G  0 disk 
├─sda2        8:2    1   2.4M  0 part 
└─sda1        8:1    1   1.2G  0 part 
Jacob Vlijm
  • 83,767
0

Look at the syslog (/var/log/syslog) and dmesg right after connecting the USB should show messages about what /dev/sXY device it is, or if it had any problems and didn't get a /dev/sXY name.

Looking at lsblk should match it by size, if it successfully got a /dev/ name and you're sure there are no other similar sized devices attached.

Xen2050
  • 8,705
0

Another option is looking at the output of blkid (optionally executed as root, i.e. as sudo blkid). This will give you the opportunity to match your device not only by size but also by file system and/or partition label. Especially the partion label can be quite helpful.

Going by the output from lsblk you posted, it is quite obvious that your USB device actually is sda. You have one block device, then you connect your USB device, and it now shows two devices. So, obviously, the additional device appeared upon plugging in your USB device, so it should be the same device.

hoe
  • 371