4

I'm having this issue under Xubuntu 21.10 (kernel 5.11.0-41-generic).

When clicking on a USB external drive label in Thunar's sidebar after I've plugged it in (so it shows up but is still unmounted), the drive mounts with a different "label" each time. It's always mounted in the same parent folder, but the folder it's mounted to is /media/$USER/DRIVE_NAME$NUMBER, where $NUMBER is a number that increments each time I mount the drive.

How do I mount the drive to the same mountpoint each time it's plugged in?

mpboden
  • 3,046
hood
  • 41

2 Answers2

3

You can tell the mount point in /etc/fstab. So you would set the name, and your partition would always mount with the same name. The header of the file is reasonably explanatory

$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>

see 1:

  1. Run a combination of sudo fdisk -l and sudo blkid to identify the UUID of your partition.
  2. Edit with sudo nano /etc/fstab (or use the editor of your choice).
  3. Add a line like UUID="xxxx-xxxx" /media/<mount point of your choice> ext4 defaults,user,auto 0 1.
  4. Reboot.

The exact flags to use should be fine tuned. You have to create directory /media/<mount point of your choice> for the mount to take place.

1

Here are the steps that I use to mount automatically an USB drive:

1. Create mount point

$ sudo mkdir /mount/<usb-drive-name>

<usb-drive-name> name it how you like, but please keep in mind that

Mount points should not have spaces in the names.

2. Find out the UUID and TYPE of your drive

$ sudo blkid

will give you a list of mounted drives, find your USB drive:

...
/dev/sda1: LABEL="my-usb-drive" UUID="e6a1db23-be63-4b39-b263-e68101bb179d" TYPE="ext4"
...

3. Edit fstab

(I use vim, but any editor is good)

$ sudo vim /etc/fstab

Usually it looks like this:

# /etc/fstab: static file system information.
#
# These are the filesystems that are always mounted on boot, you can
# override any of these by copying the appropriate line from this file into
# /etc/fstab and tweaking it as you see fit.  See fstab(5).
#
# <file system> <mount point>  <type>  <options>  <dump> <pass>
/dev/root       /              ext4    defaults        0 1
/swfile         none           swap    sw              0 0

Add this line if TYPE is ext4 (linux partition):

# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/swfile              none                  swap           sw                                           0 0
UUID="e6a1db23-be63-4b39-b263-e68101bb179d" /media/<usb-drive-name> ext4 defaults                      0 2

Add this line if TYPE is ntfs (windows partition):

# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/swfile              none                  swap           sw                                           0 0
UUID="e6a1db23-be63-4b39-b263-e68101bb179d" /media/<usb-drive-name> ntfs defaults                      0 0

Add this line if TYPE is fat (all OS partition):

# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/swfile              none                  swap           sw                                           0 0
UUID="e6a1db23-be63-4b39-b263-e68101bb179d" /media/<usb-drive-name> fat defaults                       0 0

The PASS (fsck order param) explanation:

In practice, use "1" for your root partition / and 2 for the rest. All partitions marked with a "2" are checked in sequence and you do not need to specify an order.

For the pass param, use "0" to disable checking the file system at boot or for network shares.

Here are the fstab options explained.

4. (optional) Add USB drive to your home directory

If you want that mounted usb drive to appear also automatically in your HOME directory, add this line to fstab:

# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/swfile              none                  swap           sw                                           0 0
UUID="e6a1db23-be63-4b39-b263-e68101bb179d" /media/<usb-drive-name> ext4 defaults                      0 2
/media/<usb-drive-name>  /home/<USERNAME>/<usb-drive-name>  none  bind                                 0 0
Mischa
  • 346