How To Automount File Systems on Linux

Today I’m going to show you how to automatically mount a drive at boot time in Linux. My laptop has one SSD and one mechanical drive. I install operating systems on SSD and store files on the mechanical drive. So oftentimes I need to mount the mechanical drive in the file manager manually to access my mp3 and video files. Mounting drive manually is just a waste of time. So I’m going to show you an easy way to automount drive in Linux.

Step 1: Get the Name, UUID and File System Type

Open your terminal, run the following command to see the name of your drive, its UUID(Universal Unique Identifier) and file system type.

sudo blkid

sudo blkid command

In the output of this command, the first column is the name of your drives. The second column is the label of the drive (if you set a label for it) and the third column is the UUID of your drives.

First, you need to know the name of the drive that is going to be automatically mounted. For example, the name of the drive that is going to be automatically mounted on my computer is /dev/sdb9.

Then you need to know its UUID and file system type. As you can see the UUID of /dev/sdb9 is eb67c479-962f-4bcc-b3fe-cefaf908f01e and the file system of /dev/sdb9 is ext4 which is the standard file system in Linux.

Step 2: Make a Mount Point For Your Drive

We are going to make a mount point under /mnt directory. Enter the following command,

sudo mkdir /mnt/<name-of-the-drive>

For example, I issued the following command:

sudo mkdir /mnt/sdb9

Step 3: Edit /etc/fstab File

Run the following command to edit the /etc/fstab file. Nano is a command-line editor on Linux.

sudo nano /etc/fstab

We need to append one line of code at the end of the file. The format of this line of code is as follows:

UUID=<uuid-of-your-drive>  <mount-point>  <file-system-type>  <mount-option>  <dump>  <pass>

Note that you need to separate these items with Tab key. For example, I added the following line to the end of /etc/fstab.

UUID=eb67c479-962f-4bcc-b3fe-cefaf908f01e  /mnt/sdb9  ext4  defaults  0  2

/etc/fstab automount

If you want to automount an NTFS file system, here is an example.

UUID=<uuid-of-ntfs-file-system>   /mnt/ntfs    ntfs    defaults   0   2

If you want to automount a Btrfs file system, then change the file system type to btrfs.

UUID=<uuid-of-btrfs-file-system>   /mnt/btrfs   btrfs   defaults  0   2

Save and close the file. Then run the following command to see if it works.

sudo mount -a

So that’s how you automount a file system in Linux.

Some Explanation

For swap partitions, the mount point field should be specified as none.

The defaults mount option will give users read and write access to the file system.

The value of the dump field is usually zero.

The pass field is used by the fsck program to determine the order in which filesystem checks are done at reboot time. As you can see in this file, the value of the pass field for the root file system is 1. Swap partitions do not need to be checked and the value for them is zero. All other file systems should have a value of 2. So I set the pass value to 2 for my drive.

Can’t Mount Your Disk Drive?

If you see the “can’t read superblock” error when trying to mount your disk drive, please follow the tutorial below to fix this error.

Rate this tutorial
[Total: 35 Average: 4.9]

40 Responses to “How To Automount File Systems on Linux

  • Robert Cotterman
    4 years ago

    Hello, this works beautifully minus one problem, i can’t write to the volumes without using sudo or some other form of root access

    • Xiao Guoan (Admin)
      4 years ago

      You can run the following command to grant read, write and execute permissions. Replace username with your real username and mount-point with the path of mount point.

      sudo setfacl -R -m u:username:rwx mount-point
      • Robert Cotterman
        4 years ago

        Thank you, i will try this once i am finished repairing the pc

  • Thank you, this technique has worked very well for me. I think it is also worth mentioning that if there is an error or typo in fstab, it will boot in emergency mode, at least in my case using Debian 10.

    • Helly Kyle, yes if you don’t do the above process correctly you boot into emergency mode on Ubuntu as well. To fix this simply use nano /etc/fstab and delete the lines that are causing the errors.

  • I also have my OS(ubuntu) on an SSD drive and had the same problem, I opened nautilus from the terminal with root access to open and edit the file with GUI text editor, entered a carriage return, then entered lines as instructed (NTFS file systems) saved the fstab , ^C out of nautilus and reboot then os failed to boot and entered emergency mode from which I deleted the added lines and reboot again, where do you think the problem is? editing the text with graphical tools or opening it with nautilus? cause I’m sure I didn’t make any mistakes typing the directories and device names

    • Xiao Guoan (Admin)
      4 years ago

      Always use a command-line text editor such as Nano to edit system files.

  • Kenneth
    4 years ago

    The trouble with this method is that many people (me!) have a lot of usb drives for various purposes. Trying to maintain a fstab with a listing for each of them would be impossible, not to mention creating all those different mountpoints.

    Better to let udev handle it. If you give the usb drive partitions a label, it will create “/media//

    • Xiao Guoan (Admin)
      4 years ago

      How many USB ports does your computer have?

  • Kenneth
    4 years ago

    The number of usb ports isn’t really the issue with regard to what I said. I didn’t suggest I had dozens of USB drives all plugged in at once. Even if I had only one port, and I plugged in my USB drives one at a time ( I have many! ), each partition on each drive would have its own UUID, and would need its own individual entry in fstab. If I was *sure* no two would be plugged in at the same time, I could escape with just one mountpoint, although any programs and scripts that referenced it might get confused.

    On the other hand, with udev, you just give each partition it’s own label, and all would be taken care of. No fstab changes needed.

    • Xiao Guoan (Admin)
      4 years ago

      By default, when you insert an USB drive to a Linux computer, you need to click the name of the drive in file manager to mount it.

      This article assumes the USB drive is plugged in before the computer boots, adding a fstab entry would automatically mount it. This is useful when the Linux system doesn’t have a GUI or does’t have a monitor connected to it, like a Raspberry Pi.

      • Also just in general its super annoying to have to manually mount a drive on every boot. I just want to be able to use the storage I have on my PC by default. This solution worked perfectly for me!

  • Pierre-Yves
    4 years ago

    Didn’t work for mounting volumes on my RAID5 array. Rebooted in emergency mode where I had to remove the /etc/fstab additional line. Volumes automatically mount when I click on them in Nautilus. Is there a way to see how they are mounted in order to reproduce this in /etc/fstab? (Not a big deal, but until I manually mount them in Nautilus, Plex server doesn’t see the files.)

    My mdadm conf file has the following line:

    ARRAY /dev/md/pv00 metadata=1.2 UUID=f28ef44a:f135a3ed:6314af35:6f68c74c name=nasdcde96:pv00

    What should the /etc/fstab line be ?

  • Humayun Akhtar
    4 years ago

    it is mounted in directory but I want it to show in file manager as moounted like other storage devices like usb .

  • ChiCHiii
    4 years ago

    Is there a way to undo this?

    • Xiao Guoan (Admin)
      4 years ago

      Simply delete the entry you added in the /etc/fstab file.

  • Natetronn
    4 years ago

    Does this look correct to mount an external USB drive?

    UUID=eb67c479-962f-4bcc-b3fe-cefaf908f01e /wdusb         ext4    defaults,nofail,x-systemd.device-timeout=1ms 0 2
    • Natetronn
      4 years ago

      I went with this instead and it seems to be working okay:

      UUID=eb67c479-962f-4bcc-b3fe-cefaf908f01e /wdusb         ext4    defaults,nofail,discard 0 2

      Not totally sure about discard, however.

  • Charles
    3 years ago

    Hi,

    I followed the instructions but can’t see the drive at all

    HELP

    Below is my code

    UUID=01D39AF1CB6EFA00 /mnt/sda1 ntfs defaults 0 2

    • Did you use tab between them?

      • Charles
        3 years ago

        Yes i did use tab. I managed to sort it bu using /media/…….. Instead of /mnt/

        • New Life for Old Tech
          2 years ago

          /media/ instead of /mnt/
          Thank you !!!! You saved my sanity!
          Did this on Gallium OS 3.1.

  • my kali linux os showing
    Escritorio
    file system
    waterbasket

    =

    Desktop
    Computer
    Trash

    How to change this ?

  • Terrance
    3 years ago

    I would really like to be able to use this technique to mount two drives from my in-house server. However, I have never been able to get it to work. The Ubuntu 20.04 server drives show up in Nemo (Linux Mint Cinnamon 19.3), but I get an “operation permitted for root only.” message.

    Here’s the line I am using for one of them. I would like to use a more secure way to log in (store a file), but for now if I could just get THIS part working I’d be happy.

    //192.168.0.7/media/serverhd1 /home/mainuser/ubuntuserver/serverhd1 nfs4 username=YYYYYYY,password=XXXXXXX,dir_mode777,file_mode=0777,iocharset=utf8 0 0
    
  • David Armstrong
    3 years ago

    Thank you! That worked perfectly for me. Very concise and to-the-point.

  • YouFriend
    3 years ago

    Man please, be careful with html tags in comments – its very dangerous to give this kind of option for user without registration – they can inject code and make xss atacks on website’s or what ever they want. Take this comment into consideration – above I have created a button – do you know what can I also ? 😛

  • Thanks for this tutorial, worked flawlessly

  • Hi.
    I have done the similar line in fstab, with a cifs nas mount.
    Working fine but when i restrt the system i have to run the sudo mount -a command to mount the drive.

    How can I mount it automaticly?
    I was reading instructions for a day and I can’t find the soultion.
    I’m using a plex server, watching it outside from home, and if a powercut happens the plex can’t see the files.

    Please help!
    Many thanks

    • Xiao Guoan (Admin)
      2 years ago

      You can create a systemd service to automatically mount the CIFS NAS.

      sudo nano /etc/systemd/system/auto-mount.service

      Add the following lines to this file.

      [Unit]
        Description=Automatically mount all file sysetms at boot time
        After=network-online.target
        Wants=network-online.target
      
      [Service]
        Type=oneshot
        ExecStart=/usr/bin/mount -a
      
      [Install]
        WantedBy=multi-user.target
      

      Save and close the file. Then enable this systemd service.

      sudo systemctl enable --now auto-mount.service
  • Robbie Hatley
    3 years ago

    Cool tutorial, and thanks for sharing! Using this I was able to auto-mount my two main data partitions (mostly containing files generated or accumulated in Windows) in my new Manjaro Linux (I converted my computer to a Windows/Linux dual-booter). These two partitions are “D:” and “E” in Windows, but in Linux they’re “/d” and “/e”.

    One criticism of your tutorial: I found it’s not necessary to put mountpoint dirs in “/mnt”, nor is it necessary to name those dirs after the partition slices that mount there. For example, on my system, partition slice “sdb1” doesn’t have to mount to “/mnt/sdb1”; that does work, yes, but I find that it mounts just fine to “/d”, like so:

    UUID=A0E42A6AE42A4340                     /d             ntfs    defaults  0   2
    UUID=08DF0C4F08DF0C4F                     /e             ntfs    defaults  0   2
    

    That allows for shorter Linux paths, and Linux paths that closely mirror the Windows equivalent:

    "D:\sl\Red Barn.jpg"  ->  "/d/sl/Red Barn.jpg"
    "E:\Music\Pink-Floyd\Keep Talking.mp3"  ->  "/e/Music/Pink-Floyd/Keep Talking.mp3"
    
  • Justyna
    2 years ago

    Hi. I already have data on my disk will it erase the data?

    • Xiao Guoan (Admin)
      2 years ago

      No. Mounting a disk doesn’t delete any of the data.

  • Roland, I have the same problem and have never gotten a fix. On another Xubuntu laptop, I have no problem with the automount, but I can’t see any difference between their settings. Have you ever gotten a fix?

    • Xiao Guoan (Admin)
      2 years ago

      You can create a systemd service to automatically mount all file systems in /etc/fstab.

      sudo nano /etc/systemd/system/auto-mount.service

      Add the following lines to this file.

      [Unit]
        Description=Automatically mount all file sysetms at boot time
        After=network-online.target
        Wants=network-online.target
      
      [Service]
        Type=oneshot
        ExecStart=/usr/bin/mount -a
      
      [Install]
        WantedBy=multi-user.target
      

      Save and close the file. Then enable this systemd service.

      sudo systemctl enable auto-mount.service
  • Gregory
    2 years ago

    make sure you don’t use /mnt/ntfs as a mount point. It should be /mnt/sda3 or something depending on where the drive is that you want to mount. The file system type is handled in the section after the mount point in the command. For example, my mount line for fstab is
    UUID=58F6103DF6101DB6 /mnt/sda3 ntfs defaults 0 2

    Also don’t forget to delete the spaces between the items and replace them with tabs. Even the space after the UUID number is a tab, not a space.

  • sudo findmnt –verify

    Is essential so not to corrupt your bootup

  • peeteebee
    8 months ago

    this is not _auto_ mounting. Just mounting.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here