How to mount a usb on Linux

@arch @linux @usb

What to mount?

Before mounting stuff, you want to know the name of your device.

I liked fdisk -l, but I needed sudo rights.

The default basic option that does the job is lsblk -f.

Notice the name of your device, and the type of formatting used.o

Example output lsblk -f:

NAME   FSTYPE LABEL        UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda                                                                            
├─sda1 vfat   UEFI_SYSTEM  B501-E0D3                             196.6M     0% /boot/efi
├─sda2 ext4   AntergosBoot 8013a6e0-0da0-434e-8765-6006020e6463    161M    26% /boot
├─sda3 ext4   AntergosRoot d3e02ce5-2e72-4e59-ad6f-39eedde4920c  115.2G    43% /
└─sda4 swap   AntergosSwap 917f8bf1-593b-4bd1-a621-8c82b1edced8                [SWAP]
sdb                                                                            
└─sdb1 vfat                1827-3B7D                                           
sr0                                    

You see that my USB device is called sdb1 and used the vfat format (which stands for FAT32).

Example output of fdisk -l:

Disk /dev/sdb: 14.61 GiB, 15669919744 bytes, 30605312 sectors
Disk model: Cruzer Glide
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: 0x51ecbc17

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1          32 30605311 30605280 14.6G  c W95 FAT32 (LBA)

As you can see, this shows more detailed information.

Where to mount?

The /mnt directory is just a directory without a special meaning. You can create directories there where you can mount devices, e.g. mkdir /mnt/usb.

How to mount?

Given that we know the usb is at /dev/sdb1 and that we made our directory /mnt/usb, we can run the following command (with sudo rights):

mount /dev/sdb1 /mnt/usb

This command assumes the format will be recognized automatically. To make that step explicit, you can specify the vfat format we found.

mount -t vfat /dev/sdb1 /mnt/usb

Now we just cd into /mnt/usb and voila!

DONE: write a script for this whole process!

  1. Run info command
  2. Grep line concerning the Cruzer glide
  3. Mount
  4. Cd to mounted location.

TODO: options for mounting a device permanently.