How to Auto Mount External Disk Partitions in Ubuntu 22.04 | Fedora 37/38

Last updated: June 22, 2023 — 2 Comments

This tutorial shows how to automatically mount external disk partitions on startup of Ubuntu, Fedora, Debian, and most other Linux.

I bought a new SSD recently. Now, I have 2 solid-state drives (SSDs) connected on my computer. Ubuntu 22.04 is installed on one SSD drive, while another one contains VirtualBox Virtual Machine files.

As result, I have to click open the external SSD partition in file manager every time on startup to mount it. So the files on that SSD are accessible via mount point (usually “/media/username/xxx“). Or, all virtual machines in VirtualBox will be marked as “Inaccessible”.

To make life easier, it’s possible to auto-mount the external file partition. So user doesn’t have to make one more mouse click in file manager every time on startup. And, here’s what I did in Ubuntu 22.04.

 

UPDATE: For most desktop Linux, there’s an easier way to auto-mount disk driver or partitions on startup. See this tutorial for details.

 

Step 1: Get Device Name or ID of External Disk Partition

First, search for and open the “Disks” tool from system app launcher.

Launch Disk

When it opens, select the disk in left pane, and highlight the desired file partition in right. There, copy or write down the Device name (usually /dev/xxx), and UUID.

In my case, I need to get the info about:

  • UUID: 428E68968EE68846F
  • Device name: /dev/nvme0n1p2
  • file system type: NTFS (optional)

In case, your Linux Distro does not have “Disks” utility or you’re running a Linux server. Open terminal and run command:

df -h

Then find out the disk partition name you want to auto-mount on startup. (NOTE: You need to mount the external disk first).

Step 2: Get the user/group ID for current user

To auto-mount the external partition by using current user ownership, you also need to get the user ID and group ID.

For the default user that created while installing Linux, the ID is usually 1000. Just in case, open terminal and run command to get it:

id

get user id

Step 3: Enable Auto-Mount Disk Partition via /etc/fstab

Now, you can edit the “/etc/fstab” file to do the auto-mount configuration that works in most Linux!

To do so, open terminal and run command:

sudo gedit /etc/fstab

For Ubuntu 22.10+ and Fedora workstation, replace gedit with gnome-text-editor. For other Linux, either use your system text editor or nano that works in most Linux.

When the file opens, add the new line in the bottom:

UUID_or_Device_Name  Mount_Point  File_system_type  Options  0  0

In my case, I can use:

/dev/nvme0n1p2 /media/ji/sandisk  ntfs  defaults,uid=1000,gid=1000,umask=022  0  0

There are 6 parts in the new line separated with spaces. They are:

  • Part 1: the device name or UUID. See yours via Step 1.
  • Part 2: the mount point to access the external disk files. If you’ve associated your apps with the external disk files, it’s better to use the previous mount point (See screenshot in Step1).
  • Part 3: the file system type of disk partition (e.g., ext4, fat, ntfs). Get it in step 1, or use “auto” to auto-detect.
  • Part 4: mount options separated with commas but NO space between them. Here I use:
    • defaults – means rw (read & write), auto (auto mount), exec, dev, etc. Run man mount to see more about it.
    • uid – specify the owner.
    • gid – specify the group
    • umask – specify the permissions. The first 0 means read, write and execute permission for user, and the two number 2 mean read and execute permission for group/others.
  • Part 5: Either to backup. Set 0 to not backup.
  • Part 6: Either to check and repair file system. 0 for No.

When done, save the file. For nano text editor, press Ctrl+X, type y and hit Enter to save it. And, the change will apply in next boot.

In addition

The uid=1000,gid=1000,umask=022 section specify the ownership and permissions, but it only works for non-Linux file systems, such as NTFS, FAT, etc, disk partitions.

If you’re going to auto-mount external partition with Linux file-system, such as Ext2/3/4, XFS, JFS, try to change the ownership manually after mount.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

2 responses to How to Auto Mount External Disk Partitions in Ubuntu 22.04 | Fedora 37/38

  1. Clear and concise, thank you

  2. Hi Ji
    Those pictures make it very clear, thanks. I also edited etc/fstab so that partitions – ntfs to allow Windows users to share files – can read/write. All went well, until I re-sized partitions. As “re-size” takes a very long time, I deleted, re-created, and re-copied files in. And then, the system wouldn’t boot. It took me a bit of searching, before I realised the UUIDs had changed and that was the cause.
    Obviously if UUIDs don’t change, end of problem. But given hard disks, sizes, HDD to SSD, etc, many changes. I wonder if it is better to mount the other drives *AFTER* boot up? Does that mean moving all the disk info, say, to a script, then execute after boot? What do you think? Thanks!

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*