Skip to Content
DocsOperationsSystem AdministrationDisks, Mounting & fstab

Disks, Mounting & fstab

Managing disks and partitions is a core skill in Ubuntu 26.04 system administration. This article explains how to view disk information, manually mount partitions, and configure automatic mounting at boot via fstab.

Viewing Disk and Partition Information

lsblk - List Block Devices

# Basic usage lsblk # Example output: # NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS # sda 8:0 0 500G 0 disk # ├─sda1 8:1 0 512M 0 part /boot/efi # ├─sda2 8:2 0 488G 0 part / # └─sda3 8:3 0 11.5G 0 part [SWAP] # sdb 8:16 0 2T 0 disk # └─sdb1 8:17 0 2T 0 part # Show filesystem types and UUIDs lsblk -f # Show more detailed information lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,UUID,LABEL

Other Disk Information Tools

# View partition table sudo fdisk -l # View disk usage df -h # View disk usage of a specific directory du -sh /var/log # View UUIDs of all partitions sudo blkid

Partitioning

Using fdisk for MBR Partitioning

# Partition /dev/sdb sudo fdisk /dev/sdb # fdisk interactive commands: # n - Create a new partition # p - Print partition table # d - Delete a partition # t - Change partition type # w - Write changes and exit

Using gdisk for GPT Partitioning

sudo apt install gdisk sudo gdisk /dev/sdb

Using parted

# Interactive mode sudo parted /dev/sdb # Non-interactive example: create a GPT partition table and one partition sudo parted /dev/sdb mklabel gpt sudo parted /dev/sdb mkpart primary ext4 0% 100%

Formatting Partitions

# Format as ext4 sudo mkfs.ext4 /dev/sdb1 # Format as XFS sudo mkfs.xfs /dev/sdb1 # Format as Btrfs sudo mkfs.btrfs /dev/sdb1 # Format as NTFS (requires ntfs-3g) sudo mkfs.ntfs /dev/sdb1 # Set a volume label sudo e2label /dev/sdb1 "DataDisk"

Mounting and Unmounting

mount - Mounting a Partition

# Create a mount point sudo mkdir -p /mnt/data # Mount a partition sudo mount /dev/sdb1 /mnt/data # Mount as read-only sudo mount -o ro /dev/sdb1 /mnt/data # Mount an ISO file sudo mount -o loop ubuntu-26.04.iso /mnt/iso # Mount an NFS share sudo mount -t nfs 192.168.1.100:/shared /mnt/nfs # Mount a CIFS/SMB share sudo mount -t cifs //192.168.1.100/share /mnt/smb -o username=user,password=pass # View all current mounts mount | column -t findmnt

umount - Unmounting a Partition

# Unmount a partition sudo umount /mnt/data # If the device is busy, find the processes using it sudo lsof +f -- /mnt/data sudo fuser -mv /mnt/data # Force unmount (use with caution) sudo umount -l /mnt/data # Lazy unmount sudo umount -f /mnt/data # Force unmount (NFS)

/etc/fstab Auto-Mount

Warning

Configuration errors in /etc/fstab (such as typos in UUIDs or non-existent mount points) can prevent the system from booting normally. Always back up the file before editing (sudo cp /etc/fstab /etc/fstab.bak), and verify the configuration with sudo mount -a and sudo findmnt --verify after making changes. For non-critical partitions, consider adding the nofail option to prevent boot failures.

fstab File Format

/etc/fstab defines partitions that are automatically mounted at boot. Each line contains six fields:

# <device> <mount point> <filesystem> <options> <dump> <fsck> UUID=xxxx-xxxx /mnt/data ext4 defaults 0 2

Field descriptions:

FieldDescription
DevicePartition identifier; UUID is recommended
Mount pointDirectory path to mount to
Filesystemext4, xfs, btrfs, ntfs, etc.
OptionsMount options, separated by commas
DumpBackup flag, usually 0
FsckBoot check order: 1 for root, 2 for others, 0 to skip

Getting the UUID

# Method 1: blkid sudo blkid /dev/sdb1 # Output: /dev/sdb1: UUID="a1b2c3d4-e5f6-7890-abcd-ef1234567890" TYPE="ext4" # Method 2: lsblk lsblk -f /dev/sdb1 # Method 3: ls symlinks ls -la /dev/disk/by-uuid/

fstab Configuration Examples

# Edit fstab (back up before modifying) sudo cp /etc/fstab /etc/fstab.bak sudo nano /etc/fstab

Common configurations:

# ext4 data partition UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /mnt/data ext4 defaults 0 2 # Mount with specific options UUID=b2c3d4e5-f6a7-8901-bcde-f12345678901 /mnt/ssd ext4 defaults,noatime,discard 0 2 # NTFS partition (Windows data drive) UUID=1234567890ABCDEF /mnt/windows ntfs-3g defaults,uid=1000,gid=1000,umask=022 0 0 # NFS network share 192.168.1.100:/shared /mnt/nfs nfs defaults,_netdev 0 0 # tmpfs (in-memory filesystem) tmpfs /tmp tmpfs defaults,noatime,size=2G 0 0 # swap partition UUID=c3d4e5f6-a7b8-9012-cdef-123456789012 none swap sw 0 0

Common Mount Options

OptionDescription
defaultsEquivalent to rw,suid,dev,exec,auto,nouser,async
noatimeDo not update access time; improves performance
nodiratimeDo not update directory access time
discardEnable TRIM (recommended for SSDs)
nofailDo not block boot if the device is absent
_netdevWait for network before mounting
roMount as read-only
noexecPrevent execution of binaries
nosuidIgnore SUID/SGID bits

Verifying fstab Configuration

# Mount all entries in fstab that are not yet mounted (tests if configuration is correct) sudo mount -a # Verify with findmnt sudo findmnt --verify # If there are errors, restore the backup sudo cp /etc/fstab.bak /etc/fstab

Swap Management

# View current swap swapon --show free -h # Create a swap file sudo fallocate -l 4G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile # Add to fstab to make it persistent echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab # Disable swap sudo swapoff /swapfile

LVM Logical Volume Management

# Install LVM tools sudo apt install lvm2 # Create a physical volume sudo pvcreate /dev/sdb1 # Create a volume group sudo vgcreate mydata /dev/sdb1 # Create a logical volume sudo lvcreate -L 100G -n myvolume mydata # Format and mount sudo mkfs.ext4 /dev/mydata/myvolume sudo mount /dev/mydata/myvolume /mnt/data # Online extend a logical volume sudo lvextend -L +50G /dev/mydata/myvolume sudo resize2fs /dev/mydata/myvolume # View LVM status sudo pvs sudo vgs sudo lvs

Troubleshooting

fstab Mount Failure at Boot

If an fstab misconfiguration prevents booting, use GRUB recovery mode:

# Remount root partition as read-write mount -o remount,rw / # Edit and fix fstab nano /etc/fstab # Reboot reboot

Troubleshooting Insufficient Disk Space

# View partition usage df -h # Find large files sudo find / -type f -size +100M -exec ls -lh {} \; # View directory space usage (sorted) sudo du -sh /* | sort -rh | head -20 # Clean APT cache sudo apt clean sudo apt autoremove
Last updated on