Save 10%Pay yearly on any plan. 6% half-yearly, 3% quarterly. Help centreWhatsAppTelegram TeamsOpen a ticket

How to Mount and Automount Drives in Linux

Mount a drive in Linux by hand, then make it mount at every start with /etc/fstab: find the UUID, write the line and test it safely before you restart.

3 min readBy Soumya

Reviewed by the AmazingRDP technical team

Mounting drives in Linux

Need a server with several drives of its own? See our dedicated servers. See Cheap Dedicated Servers from $38.99

Linux has no drive letters. A drive becomes usable when it is mounted: attached to a folder, after which its files appear inside that folder. Desktop systems do this for USB sticks by themselves. On a server, and for drives that must be there after every restart, you set it up once.

1. Find the drive

lsblk -f

This lists every drive and partition with its file system, label and UUID, and where it is mounted. A new second disk usually appears as sdb or nvme1n1, with partitions such as sdb1. An empty FSTYPE column means the partition has no file system yet and must be formatted first (which erases it): sudo mkfs.ext4 /dev/sdb1.

2. Mount it by hand

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
df -h /mnt/data

The folder is the "mount point". The third line confirms the drive is there and shows its size. To detach it:

sudo umount /mnt/data

The command is umount, without an "n". If it answers "target is busy", a program or a terminal is still inside the folder; sudo lsof +f -- /mnt/data shows which.

A manual mount is gone after a restart. For a permanent one, continue.

3. Mount it at every start: /etc/fstab

Get the partition's UUID. It is a fixed identifier, unlike names such as sdb1, which can change when drives are added:

sudo blkid /dev/sdb1

Make a copy of the file, then open it:

sudo cp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab

Add one line at the end:

UUID=1234abcd-12ab-34cd-56ef-1234567890ab  /mnt/data  ext4  defaults,nofail  0  2
FieldMeaning
UUID=...Which partition
/mnt/dataWhere to mount it (the folder must exist)
ext4Its file system: ext4, xfs, btrfs, ntfs3, exfat, vfat
defaults,nofailOptions. nofail lets the system start even if the drive is missing
0An old backup flag; leave it at 0
2Check the file system at start, after the root drive. Use 0 for NTFS, exFAT and FAT

4. Test before you restart

sudo findmnt --verify
sudo systemctl daemon-reload
sudo mount -a
df -h /mnt/data

findmnt --verify checks the file for mistakes. mount -a mounts everything in it that is not yet mounted; if this works without an error, the restart will too.

Do not skip this on a server. A wrong line without nofail makes the system stop at start-up and wait for a console you may not have. If that happens, use the provider's rescue system to put /etc/fstab.bak back.

Windows drives: NTFS, exFAT and FAT

These file systems do not store Linux owners, so you set them for the whole drive in the options:

UUID=A1B2C3D4E5F60718  /mnt/win  ntfs3  defaults,nofail,uid=1000,gid=1000,umask=022  0  0

uid=1000 and gid=1000 are the first normal user on most systems; id shows yours. On older systems without the ntfs3 driver, install ntfs-3g and write ntfs-3g as the type. A Windows drive that was not shut down properly (Fast Startup) mounts read-only until Windows releases it.

External drives that are not always there

For a USB drive that comes and goes, let the system mount it only when someone opens the folder:

UUID=...  /mnt/usb  ext4  defaults,nofail,noauto,x-systemd.automount,x-systemd.idle-timeout=60  0  2

The system starts without waiting for the drive, mounts it on first use, and lets go of it after a minute of rest.

Give your user the folder

On a Linux file system the mounted drive belongs to root at first. To use it as a normal user:

sudo chown -R $USER:$USER /mnt/data

Network drives

Shares from another machine mount the same way, with a different first field and type. For a Windows or Samba share, install cifs-utils and see Samba on Ubuntu. Add _netdev to the options so that the system waits for the network.

On a dedicated server with several disks you will do this for each data drive: see our dedicated servers. Related guides: uses for old hard drives, Linux data recovery tools and clone Ubuntu Server with Clonezilla.

Questions

How do I mount a drive in Linux?

Create a folder and run sudo mount /dev/sdb1 /mnt/data, with your own partition name.

How do I mount a drive automatically at boot?

Add a line with the partition's UUID to /etc/fstab and test it with sudo mount -a.

What does nofail mean in fstab?

The system starts even if that drive is missing or fails to mount.

Why use the UUID and not /dev/sdb1?

Device names can change when drives are added or removed. The UUID stays the same.