Skip to content

Linux Disk Mounting

📁 Create Mount Point

Create a directory to use as a mount point:

mkdir -p /mnt/external_data               # Create mount point directory
mkdir -p /media/usb_drive                 # Alternative for removable media
ls /mnt                                   # List existing mount points
mkdir -p /mnt/wsl/external_data           # Shared mount point across WSL2 distributions

🔌 Mount a Disk

Mount a disk with various filesystem options:

sudo mount -t auto /dev/sdg1 /mnt/external_data      # Auto-detect filesystem
sudo mount -t ext4 /dev/sdg1 /mnt/external_data      # Mount ext4 explicitly
sudo mount -t vfat /dev/sdg1 /mnt/external_data      # Mount FAT32
sudo mount -t exfat /dev/sdg1 /mnt/external_data     # Mount exFAT
sudo mount -t xfs /dev/sdg1 /mnt/external_data       # Mount XFS
sudo mount -t ntfs-3g /dev/sdg1 /mnt/external_data   # Mount NTFS (Windows drives)
sudo mount -o ro /dev/sdg1 /mnt/external_data        # Mount read-only
sudo mount -o rw,noexec /dev/sdg1 /mnt/external_data # Mount read-write, no exec

🪟 Mount Windows Drives in WSL2

WSL2 allows you to mount standard Windows partitions (like D:) as well as attach bare physical drives.

# Mount a standard Windows partition (e.g., D: drive) using drvfs
sudo mkdir -p /mnt/d
sudo mount -t drvfs D: /mnt/d

# Unmount a drvfs drive
sudo umount /mnt/d

To mount a bare physical disk (e.g., an ext4 Linux drive) into WSL2, run this from an Administrator PowerShell prompt in Windows:

wmic diskdrive list brief                                            # List available physical disks
wsl --mount \\.\PHYSICALDRIVE1 --ext4                                # Mount entire disk as ext4
wsl --mount \\.\PHYSICALDRIVE1 --partition 2 --type ext4             # Mount specific partition
wsl --unmount \\.\PHYSICALDRIVE1                                     # Unmount the physical disk

✅ Verify Mount

Confirm the disk is mounted and accessible:

df -h | grep sdg                          # Show disk usage for sdg
df -h /mnt/external_data                  # Show usage for specific mount point
mount | grep sdg                          # Check if disk is mounted
lsblk                                     # List all block devices in tree view
lsblk -f                                  # Include filesystem info
findmnt /mnt/external_data                # Show mount details

🔐 Fix Permissions

Adjust ownership and access rights after mounting:

sudo chown -R $USER:$USER /mnt/external_data         # Give current user ownership
sudo chmod -R 755 /mnt/external_data                  # Set standard permissions
sudo chmod -R 777 /mnt/external_data                  # Full access for all users
ls -la /mnt/external_data                             # Verify permissions

🔍 Inspect Disk & Filesystem

Identify device names, UUIDs, and filesystem types before mounting:

lsblk                                     # List block devices
lsblk -f                                  # Show filesystem types and UUIDs
sudo fdisk -l                             # List all partitions
sudo blkid                                # Show UUIDs and filesystem types
sudo blkid /dev/sdg1                      # Info for specific partition
sudo file -s /dev/sdg1                    # Detect filesystem type
sudo parted -l                            # Show partition table

🔁 Persistent Mount via /etc/fstab

Make the mount survive reboots:

# Step 1: Get the UUID of the partition
UUID=$(sudo blkid -s UUID -o value /dev/sdg1)

# Step 2: Append entry to fstab
echo "UUID=$UUID /mnt/external_data ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab

# Step 3: Test fstab changes without rebooting
sudo mount -a

# Step 4: Verify the mount applied
df -h | grep external_data

Warning

Always use nofail so the system still boots if the drive is unplugged.


fstab Field Reference

<device/UUID>  <mountpoint>  <fstype>  <options>  <dump>  <pass>
Field Common Values Description
device UUID=... or /dev/sdg1 Device identifier (UUID preferred)
mountpoint /mnt/external_data Where to mount
fstype ext4, ntfs-3g, vfat, auto Filesystem type
options defaults Standard rw, exec, auto, async flags
options nofail Skip errors on boot if disk missing
options ro Mount read-only
options noatime Don't update access timestamps (faster)
options uid=1000,gid=1000 Set owner for FAT/NTFS
dump 0 0 = disable backup
pass 0 / 1 / 2 fsck order: 0=skip, 1=root, 2=others

Filesystem Type Reference

Filesystem Mount Flag Install Package Use Case
Auto-detect -t auto Unknown filesystem
ext4 -t ext4 built-in Default Linux filesystem
NTFS -t ntfs-3g ntfs-3g Windows drives
FAT32 -t vfat built-in USB drives, SD cards
exFAT -t exfat exfat-fuse Large USB/SD cards
XFS -t xfs built-in High-performance Linux
Btrfs -t btrfs built-in Snapshots, modern Linux
ZFS -t zfs zfsutils-linux Enterprise / NAS
tmpfs -t tmpfs built-in RAM-based temp storage
NFS -t nfs nfs-common Network file shares

Install Required Packages

sudo apt install -y ntfs-3g               # NTFS support
sudo apt install -y exfat-fuse exfatprogs # exFAT support
sudo apt install -y nfs-common            # NFS client support
sudo apt install -y zfsutils-linux        # ZFS support

NFS Network Mount

Mount a shared folder from another machine on the network:

sudo apt install -y nfs-common                                        # Install NFS client
sudo mount -t nfs 192.168.1.100:/shared /mnt/nfs_share               # Mount NFS share
sudo mount -t nfs -o ro 192.168.1.100:/shared /mnt/nfs_share         # Mount read-only
showmount -e 192.168.1.100                                            # List NFS exports on server

# Persistent NFS fstab entry
echo "192.168.1.100:/shared /mnt/nfs_share nfs defaults,nofail 0 0" | sudo tee -a /etc/fstab

ISO / Image File Mount

Mount a disk image or ISO without burning it:

sudo mount -o loop image.iso /mnt/iso                                 # Mount ISO file
sudo mount -o loop,ro disk.img /mnt/image                            # Mount disk image read-only
sudo losetup -f disk.img                                              # Attach image to loop device
sudo losetup -l                                                       # List loop devices
sudo losetup -d /dev/loop0                                            # Detach loop device

Unmount a Disk

Safely detach a disk before unplugging:

sudo umount /mnt/external_data            # Unmount by mount point
sudo umount /dev/sdg1                     # Unmount by device name
sudo umount -f /mnt/external_data         # Force unmount (if busy)
sudo umount -l /mnt/external_data         # Lazy unmount (detach when free)
sudo fuser -m /mnt/external_data          # Show processes using the mount
sudo fuser -km /mnt/external_data         # Kill processes and unmount

Filesystem Check & Repair

Run fsck to detect and fix filesystem errors (unmount first):

sudo umount /dev/sdg1                     # Must unmount before checking
sudo fsck /dev/sdg1                       # Auto-repair filesystem
sudo fsck -y /dev/sdg1                    # Auto-yes to all repairs
sudo fsck -n /dev/sdg1                    # Dry-run, no changes
sudo e2fsck -f /dev/sdg1                  # Force check on ext2/3/4
sudo ntfsfix /dev/sdg1                    # Fix NTFS errors (basic)

Troubleshooting

Symptom Cause Fix
mount: unknown filesystem type Missing driver/package sudo apt install ntfs-3g or exfat-fuse
mount: /dev/sdg1 is already mounted Previously mounted sudo umount /dev/sdg1 first
mount: wrong fs type or bad superblock Corrupt or unknown FS sudo file -s /dev/sdg1 to check
target is busy when unmounting Process using mount sudo fuser -km /mnt/external_data
Boot hangs after fstab edit Bad fstab entry Add nofail option to fstab
Permission denied after mount Ownership not set sudo chown -R $USER:$USER /mnt/external_data
UUID not found Drive not connected lsblk to confirm device name
read-only filesystem error Dirty NTFS or ext4 error sudo fsck -y /dev/sdg1