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

Export Your PLEX server library media names in Linux or Windows

LINUX

Make yourself the ROOT user

sudo -i

Verify the location of the "Plex Media Scanner" location.  Depends on the flavor of linux, but usually in in:

/usr/lib/plexmediaserver/

but use this command if you cant find it find / -name "Plex Media Scanner"

Update the path to allow the scanner access to related files.

export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"

Now we are ready to run the scanner.  This command will give you the libraries you can export:

/usr/lib/plexmediaserver/Plex\ Media\ Scanner --list

This will list of your Libraries, each assigned with a number. something like this as an example:

1: Movies   
2: TV Shows 
3: Music
4: Videos

This example is "Movies", so a "1" will be used for the "--section" argument in the next line

/usr/lib/plexmediaserver/Plex\ Media\ Scanner --list --section 1

You'll get a list of movies and folders it has and you can copy /paste it.  
If you want to output it to a file you can use a command like this:

/usr/lib/plexmediaserver/Plex\ Media\ Scanner --list -section 1 > plexlist.txt


WINDOWS

You can also do this from windows if you do the following:

  1. Goto the default plex directory from a command prompt
    "C:\Program Files (x86)\Plex\Plex Media Server"

  2. Enter in the command"
    "Plex Media Scanner.exe" --list

  3. You'll get a  list of available libraries.
    "Plex Media Scanner.exe" --list -section 1

  4. You can print it to the cmd interface, or you can print it to a directory
    "Plex Media Scanner.exe" --list -section 1 > plexlist.txt