Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Mount drive in linux and set auto-mount at boot - Tech Knowledge Base -... https://confluence.jaytaala.com/display/TKB/Mount+drive+in+linux+an...

What do you think? Discuss, post comments, or ask questions at the end of this article [More
about me]

!"
#$%
&'(
)*(
$+(
$#,-
$&.
*%-
#%"
/0"
#$%
-%1
""%
Created by Jay Ta'ala, last modified on Nov 02, 2021

Guide to mount a drive in linux (deb/ubuntu) and set to auto-mount at boot.

Mount drive
Make a folder (will be mount point)

sudo mkdir /media/data


sudo mount /dev/sdb1 /media/data

Now you can access the drive at /media/data.

Auto-mount at boot
We want the drive to auto-mount at boot. This usually means editing /etc/fstab.
Firstly, it's always best to use the drives UUID. To find the drive's UUID do

ls -al /dev/disk/by-uuid/

Copy the resultant UUID (for your disk) and then open fstab for editing (note I'm using vim here but use whatever editor
you prefer):

sudo vim /etc/fstab

You want to add an entry for the UUID and mount point. Below is an example of an fstab file with an entry added for the
mount above:

# /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>
# / was on /dev/sdb1 during installation
UUID=63a46dce-b895-4c1f-9034-b1104694a956 / ext4 errors=remount-ro 0
# swap was on /dev/sdb5 during installation

1 de 4 15/11/21 13:05
Mount drive in linux and set auto-mount at boot - Tech Knowledge Base -... https://confluence.jaytaala.com/display/TKB/Mount+drive+in+linux+an...

UUID=b9b9ee49-c69c-475b-894b-1279d44034ae none swap sw 0


# data drive
UUID=19fa40a3-fd17-412f-9063-a29ca0e75f93 /media/data ext4 defaults 0 0

Note: the entry added is the last line.

Test fstab
We always want to test the fstab before rebooting (an incorrect fstab can render a disk unbootable). To test do:

findmnt --verify

check the last line for errors. Warnings can help in improving your fstab.

Unmounting drive with umount


You can unmount drives using umount. For example, to unmount the data drive above mount at /media/data you
would do:

sudo umount /media/data

Related articles
Mount drive in linux and set auto-mount at boot
Logging remote ip address when using reverse proxy
Give password-less sudo to a user
Setup SSH with OpenSSH
GoAccess for apache log statistics

ubuntu kb-how-to-article

12 Comments
Type Comment Here (at least 3 chars)

Name (optional) E-mail (optional) Website (optional) Preview Submit

Anonymous • 2 years ago


This is good thanks. How do you auto-mount a fat or fat32 based disk?

2 de 4 15/11/21 13:05
Mount drive in linux and set auto-mount at boot - Tech Knowledge Base -... https://confluence.jaytaala.com/display/TKB/Mount+drive+in+linux+an...

| Reply

Jay Ta'ala • 2 years ago


Try:

UUID=xxx /media/data vfat dmask=000,fmask=0111,user 0 0

Replace xxx with the UUD for the drive. See this post on stackexchange for more info.
| Reply

Cornelis • 2 years ago


Thank you so much for writing this tutorial, I installed Debian 10 Buster two weeks ago, and as a novice my
knowledge of fixing things with the terminal emulator is non existent, but I'm sticking with Debian I'll never go
back to Windows, that's for sure!
| Reply

Anonymous • last year


It works fine for reading, but I can not write... it says ReadOnly FileSystem...

| Reply

Jay • last year


Interesting - need some more info here. Are you attempting to mount an ext4 formatted
dirve/partition?
-1 | Reply

Anonymous • last year


Short, sweet, to the point, and accurate. Thanks!

| Reply

Anonymous • 7 months ago


Notice this comment straight out of the man page for mount:

Note that it is a bad practice to use mount -a for fstab checking. The recommended solution is findmnt --verify

| Reply

Anonymous • 4 months ago


thanks a lot:)

| Reply

Anonymous • last week


I have trying mount the first boot drive partition in /boot for the nvme device .Which I have followed the below
steps! Step 1 : sudo mkdir /boot Step 2 : mount /dev/nvme6n1p1 /boot Step 3 : Adding the UUID in fstab file
UUID ="uuid number" /boot vfat defaults 0 0 Step 4 : Reboot

After reboot partition getting lost and failing with below error

3 de 4 15/11/21 13:05
Mount drive in linux and set auto-mount at boot - Tech Knowledge Base -... https://confluence.jaytaala.com/display/TKB/Mount+drive+in+linux+an...

] Dependency failed for /rooot/boot. [DEPEND] Dependency failed for Local File Systems. [DEPEND] Dependency failed
for Mark the need to relabel after reboot.
I am wondering how rooot is populating here, could you please help here to proceed further.Thanks in advance !
| Reply

Anonymous • 2 days ago


Dependency failed for /rooot/boot.

| Reply

Jay • last week


Is that the actual error (verbatim?)
Dependency failed for /rooot/boot
Did you mean "root"? what is "/rooot"? (note the 3 o's is not normal). Do you have the folder "/rooot"?
| Reply

Jay • last week


Generally /boot is a standard folder on the drive linux is installed to - usually contains grub etc., and
your installer will mount a vfat mount inside it (e.g. /boot/efi etc.), for example on my current system
here is the fstab entry:

UUID=A7AD-2077 /boot/efi vfat umask=0077 0 2


| Reply

4 de 4 15/11/21 13:05

You might also like