-4

A few questions about commands relating to a removable device.

  1. What sort of command can locate the device file used by a USB? As in the directory it creates to open the actual USB.

  2. How do I mount a filesystem to a directory of my choice (e.g. "TechCategory") and check the filesystem for errors?

  3. Can I add a line to /etc/fstab to ensure that the filesystem can be easily mounted in the future?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Malcolm
  • 11

1 Answers1

2

What sort of command can locate the device file used by a USB. As in the directory it creates to open the actual USB.

You can list block devices by using:

$ lsblk

Example Output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 119.2G  0 disk 
|-sda1   8:1    0 488.3M  0 part /efi
|-sda2   8:2    0 109.4G  0 part /
`-sda3   8:3    0   9.4G  0 part [SWAP]
sdb      8:16   0 931.5G  0 disk 
`-sdb1   8:17   0 931.5G  0 part /media/storage
sdc      8:32   1   7.4G  0 disk 
`-sdc1   8:33   1   7.4G  0 part 

Name is the block devices, the indented lines underneath their respective block device are partitions, the mountpoint column will show where they are mounted on the filesystem. (If they are mounted.)

In this example there is a second HDD mounted on /media/storage

There is also a USB device (sdc) which is currently not mounted.

Block devices and their partitions are located under /dev/.

See: https://ss64.com/bash/lsblk.html

how do I mount a filesystem to a directory of my choice e.g. "TechCategory"

You can use the mount command to mount a partition to your filesystem:

$ mount /dev/sdc1 /media/TechCategory

If we go back to our lsblk now, we see:

sdc      8:32   1   7.4G  0 disk 
`-sdc1   8:33   1   7.4G  0 part /media/TechCategory  <-- USB is now mounted here.

See: https://ss64.com/bash/mount.html

and check the filesystem for errors?

You can use the badblocks command, see: How do you use badblocks?

Example:

badblocks -sv /dev/sdc

Can I add a line to /etc/fstab to ensure that the filesystem can be easily mounted in the future?

I would recommend ensuring that you understand how /etc/fstab works before editing it.

$ man fstab 

Another stack exchange answer, Mount an hard drive at start-up

Fashim
  • 31