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