Wednesday, February 9, 2022

How To Mount USB Drive in linux

Mount USB Drive In Linux Using Command Line

1. Detect Plugged In USB Device

Once you plug in your USB device to your system USB port, run the following command to locate the USB device:

sudo lsblk

root@plex:/# sudo lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop7                       7:7    0  43.4M  1 loop /snap/snapd/14549
sda                         8:0    0   7.3T  0 disk
├─sda1                      8:1    0   128M  0 part
└─sda2                      8:2    0   7.3T  0 part
root@pl:/#

Now you can see the detected USB device named ‘sda’ which is 7.3TB (its an 8TB usb drive so this is correct).  Looking at the breakdown below it, you'll notice that there is a "sda2" that is set to 7.3TB, you'll mount that.

Your device name may differ on device name and size.

2. Create a Mount Point

Now we need to give this USB drive its location name in linux.  
I'm going to put this in the "media" section, giving the USB drive a unique name "mediadrive".  

sudo mkdir /media/mediadrive

However, creating a directory to mount and access a drive is an optional step, you can also directly attach it to ‘/media’ directory.

3. Mount USB Drive To Mount Point

We’re now ready to link the USB device to the Linux filesystem and access its data. To do the same, we’ll use the ‘mount’ utility program. Replace sda2 with the drive name that matches your USB drive.

sudo mount /dev/sda2 /media/mediadrive

4. Check For The Device Mounted

Run the command below.  You should now see the mounted name showing up in the list.  

sudo lsblk

root@plex:/media# sudo lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT

sda                         8:0    0   7.3T  0 disk
├─sda1                      8:1    0   128M  0 part
└─sda2                      8:2    0   7.3T  0 part /media/mediadrive
sdb                         8:16   0 232.9G  0 disk
├─sdb1                      8:17   0     1M  0 part
├─sdb2                      8:18   0     1G  0 part /boot
└─sdb3                      8:19   0 231.9G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0   100G  0 lvm  /
 
You'll notice that /media/mediadrive is showing up in list.

Now you should be able to change to that location and see the media inside

cd /media/mediadrive

No comments:

Post a Comment

Feel free to leave a comment! If you have any information that you think should be included, please do so here and I'll get it added in.