Introduction / Why This Is Needed
Disk mounting is the process that makes a file system on a physical storage medium (HDD, SSD, flash drive) accessible within Linux's unified directory hierarchy. Without this step, the operating system cannot read or write data to the device. This guide will help you:
- Connect any new or external disk manually.
- Configure automatic mounting at system boot.
- Understand key concepts: devices, mount points, file systems.
After completing this, you will be able to work with data on any connected disk just like folders in your home directory.
Requirements / Preparation
Before you begin, ensure that:
- You have administrator privileges (access to
sudo). - The disk is physically connected and detected by the system.
- Utilities for working with file systems are installed (they are usually present by default). For NTFS, you may need the
ntfs-3gpackage:# For Debian/Ubuntu sudo apt update && sudo apt install ntfs-3g # For CentOS/Fedora sudo dnf install ntfs-3g - A mount point (an empty directory) has been created. Typically,
/mntor/mediais used.
Step-by-Step Instructions
Step 1: Identify the Device and Its Partitions
First, you need to find out how the system names your disk. The simplest way is the lsblk command, which shows all block devices as a tree.
lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238,5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 238G 0 part /
sdb 8:16 0 1,8T 0 disk
└─sdb1 8:17 0 1,8T 0 part
Here, sdb1 is the first partition on the second disk (sdb). Pay attention to the SIZE to avoid confusing devices.
Alternative: sudo fdisk -l provides more detailed information, including the file system type.
Step 2: Create a Mount Point
A mount point is a regular folder, but it must exist before mounting. Create it in a standard location (/mnt) or anywhere else convenient.
sudo mkdir -p /mnt/mydata
The -p flag allows you to create the entire directory chain if it doesn't exist and doesn't cause an error if the directory already exists.
Step 3: Mount the Disk Temporarily (for Testing)
Now, connect the disk to the mount point. Use mount, specifying the device and the mount point.
sudo mount /dev/sdb1 /mnt/mydata
Important: If the file system is not ext4 (e.g., ntfs, exfat, fat32), specify its type explicitly using the -t flag. Often for NTFS, the ntfs-3g driver is required:
sudo mount -t ntfs-3g /dev/sdb1 /mnt/mydata
After this, the disk's contents will be accessible in /mnt/mydata. You can verify with ls /mnt/mydata.
Step 4: Configure Automatic Mounting via fstab
To have the disk mount automatically at every boot, add an entry to the configuration file /etc/fstab (file systems table).
Open the file for editing:
sudo nano /etc/fstab
Add a new line to the end of the file. The line format is:
<device> <mount_point> <fs_type> <options> <dump> <pass>
Example for an ext4 partition:
/dev/sdb1 /mnt/mydata ext4 defaults 0 2
Example for NTFS with correct permissions for the current user (UID 1000, GID 1000):
/dev/sdb1 /mnt/mydata ntfs-3g defaults,uid=1000,gid=1000,dmask=022,fmask=133 0 0
uidandgid— the user and group IDs that will receive permissions on files. You can find them with theidcommand.dmaskandfmask— permission masks for directories and files (022 = rwxr-xr-x, 133 = rw-r--r--).
Tip: Instead of /dev/sdb1, you can use a UUID (a unique identifier) that won't change if you reconnect cables. Find the UUID with sudo blkid. Example:
UUID=1234-ABCD /mnt/mydata ntfs-3g defaults 0 0
Save the file (Ctrl+O, Enter, Ctrl+X in nano). To apply the changes without rebooting, run:
sudo mount -a
If the command completes without errors, the configuration is correct.
Step 5: Verify the Result
- Temporary mount:
mount | grep mydataordf -h | grep mydata. - Automount: Reboot the system (
sudo reboot). After logging in, rundf -hagain and ensure your disk is in the list and mounted at the correct point. - Permissions: Try creating a file in the mount point under your own name:
touch /mnt/mydata/test.txt. If it works — the permissions are set correctly.
Potential Issues
mount: /mnt/mydata: special device /dev/sdb1 does not exist.- Cause: Incorrect device name. Double-check with
lsblk. - Solution: Specify the correct partition path (e.g.,
/dev/nvme0n1p2for NVMe).
- Cause: Incorrect device name. Double-check with
mount: /mnt/mydata: wrong fs type, bad option, bad superblock...- Cause: The file system type (
-t) is not specified or is incorrect, the file system is corrupted, or the required driver is missing. - Solution: Identify the FS with
sudo fdisk -lorblkid. Install the appropriate package (e.g.,exfat-utilsfor exFAT).
- Cause: The file system type (
Permission deniedwhen writing to NTFS/FAT.- Cause: By default, these file systems do not have Linux permission concepts. All files belong to root.
- Solution: Use the
uid,gid,umaskoptions in fstab or the mount command, as shown in Step 4. For FAT,utf8=1,uid=1000may also help.
- Disk does not mount automatically after editing fstab.
- Cause: A syntax error in fstab or an incorrect UUID/device.
- Solution: Run
sudo mount -a— it will show the specific line with an error. Fix it. Ensure the mount point exists.
Target is busywhen trying to unmount.- Cause: Someone (you or a program) is using files in that mount point.
- Solution: Close all open files and terminals in that directory. You can use
lsof +D /mnt/mydatato find the processes.