Linux System Administration

0 of 85 lessons complete (0%)

Managing Unix File Systems

Mounting File Systems

You don’t have access to this lesson

Please register or sign in to access the course content.

Mounting a file system in Linux refers to attaching a file system (such as a partition on a hard disk, a USB drive, or a network file system) to a directory structure so that the user can access it. A mounted file system becomes part of the overall file hierarchy and can be accessed just like any other directory.

Basic Concepts:

  1. Mount Point:
    • A mount point is the directory where a file system is attached. For example, when you mount a USB drive at /mnt/usb, you can access the contents of the USB drive by navigating to that directory.
  2. Mount Command:
    • The mount command is used to attach file systems to the directory tree.
  3. Unmount Command:
    • The umount command is used to safely detach the file system before removing or disconnecting it.

Mounting a File System

To mount a file system, you need to specify:

  1. Device name: The partition or disk to be mounted (e.g., /dev/sda1).
  2. Mount point: The directory where you want to attach the file system (e.g., /mnt/disk).

Example: Mounting a Partition

Create a Mount Point:
Before mounting a file system, create a directory that will serve as the mount point (if it doesn’t already exist):

Mount the File System:
Use the mount command to mount the file system to the mount point:

/dev/sda1: The partition to be mounted.
/mnt/mydisk: The directory where the file system will be accessible.

Check Mounted File Systems:
To verify that the file system has been mounted successfully, you can use the df or mount command:

or

Access the Mounted File System: Once mounted, you can access the contents of the file system by navigating to the mount point:

Unmounting a File System

To safely remove the file system, it’s important to unmount it first:

Unmount the File System: After unmounting, you will no longer be able to access the file system from the mount point.

Check Unmounted File Systems: To ensure the file system has been successfully unmounted, use:

Persistent Mounting with /etc/fstab

If you want a file system to be automatically mounted at boot time, you can add an entry to the /etc/fstab file. This file defines file systems and their mount points.

Example fstab Entry:

  • /dev/sda1: The partition to be mounted.
  • /mnt/mydisk: The mount point.
  • ext4: The file system type.
  • defaults: Default mount options.
  • 0 0: Dump and fsck options (used for backup and consistency checks).

Lab Exercise: Mounting and Unmounting File Systems

Objective:

Learn how to mount and unmount file systems manually and automatically using /etc/fstab.

Steps:

Check Existing Partitions: Use the lsblk or fdisk command to list available partitions:

or

Create a Mount Point:

Mount the Partition: Mount a partition (e.g., /dev/sdb1) to the mount point /mnt/disk:

Access the File System: Navigate to the mount point and view the files:

Unmount the File System: After accessing the files, unmount the partition:

Add to /etc/fstab for Automatic Mounting: Edit the /etc/fstab file to include an entry for automatic mounting:

Add a line similar to: