One place for hosting & domains

      How to Mount a File System on Linux

      Mounting or unmounting a file system on Linux is usually straightforward, except when it isn’t. This article teaches you how to mount and unmount file systems, as well as list available and currently mounted file systems. It also explains how to handle the case where file systems won’t unmount because they are in use.

    • You can list the currently mounted file systems from a Linux command line with a simple mount command:


      The following is on an Ubuntu 22.04 LTS Linode, logged in as root:

      sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
      proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
      udev on /dev type devtmpfs (rw,nosuid,relatime,size=441300k,nr_inodes=110325,mode=755,inode64)
      devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
      tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=99448k,mode=755,inode64)
      /dev/sda on / type ext4 (rw,relatime,errors=remount-ro)
      securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
      tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)
      tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)
      cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
      pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
      bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
      systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18031)
      hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
      mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
      debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
      tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
      fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
      configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
      none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
      tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64)
    • You can list the static file system information by displaying /etc/fstab:

      cat /etc/fstab

      The two static file systems for this instance are the root disk and the swap disk:

      # /etc/fstab: static file system information.
      # Use 'blkid' to print the universally unique identifier for a
      # device; this may be used with UUID= as a more robust way to name devices
      # that works even if disks are added and removed. See fstab(5).
      # <file system> <mount point>   <type>  <options>       <dump>  <pass>
      /dev/sda        /               ext4    errors=remount-ro 0     1
      /dev/sdb        none            swap    sw                0     0
    • You can also list and search for file systems using the findmnt command:


      The basic output shows the file system tree:

      TARGET                                SOURCE     FSTYPE     OPTIONS
      /                                     /dev/sda   ext4       rw,relatime,errors=remount-ro
      ├─/sys                                sysfs      sysfs      rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/kernel/security              securityfs securityfs rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/cgroup                    cgroup2    cgroup2    rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot
      │ ├─/sys/fs/pstore                    pstore     pstore     rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/bpf                       bpf        bpf        rw,nosuid,nodev,noexec,relatime,mode=700
      │ ├─/sys/kernel/debug                 debugfs    debugfs    rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/kernel/tracing               tracefs    tracefs    rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/fuse/connections          fusectl    fusectl    rw,nosuid,nodev,noexec,relatime
      │ └─/sys/kernel/config                configfs   configfs   rw,nosuid,nodev,noexec,relatime
      ├─/proc                               proc       proc       rw,nosuid,nodev,noexec,relatime
      │ └─/proc/sys/fs/binfmt_misc          systemd-1  autofs     rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18031
      ├─/dev                                udev       devtmpfs   rw,nosuid,relatime,size=441300k,nr_inodes=110325,mode=755,inode64
      │ ├─/dev/pts                          devpts     devpts     rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
      │ ├─/dev/shm                          tmpfs      tmpfs      rw,nosuid,nodev,inode64
      │ ├─/dev/hugepages                    hugetlbfs  hugetlbfs  rw,relatime,pagesize=2M
      │ └─/dev/mqueue                       mqueue     mqueue     rw,nosuid,nodev,noexec,relatime
      └─/run                                tmpfs      tmpfs      rw,nosuid,nodev,noexec,relatime,size=99448k,mode=755,inode64
        ├─/run/lock                         tmpfs      tmpfs      rw,nosuid,nodev,noexec,relatime,size=5120k,inode64
        │                                   none       ramfs      ro,nosuid,nodev,noexec,relatime,mode=700
        └─/run/user/0                       tmpfs      tmpfs      rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64
    • You can restrict the output various ways, as described in man findmnt, to show only specific devices, mount points, or file system types, such as:

      findmnt -t ext4

      This lists only ext4 file systems:

      /      /dev/sda ext4   rw,relatime,errors=remount-ro
    • If you’re only interested in block devices, you can list them with lsblk:


      Once again, this only lists our Linode’s root and swap disks:

      sda    8:0    0 24.5G  0 disk /
      sdb    8:16   0  512M  0 disk [SWAP]
    • You can mount file systems for a single session using the mount command, and permanently by editing /etc/fstab. Mounting needs to be done by an administrator, either by logging in as root or by using the sudo command. There are some cases where mounting is done automatically, like when you insert a USB flash drive. Here are a few examples using the mount command, plus the preparatory mkdir command to create the mount point.

      Most modern distros automatically mount USB drives when you insert them.

      The network file system (NFS) supports mounting remote file systems as shares for local access.

      You can add the -l (lazy) switch to umount to instruct the system to unmount the device when it’s free. Alternatively, the -f (force) switch makes the system unmount the device right away, at the possible risk of corrupting the file system. The -f switch is primarily intended to unmount unreachable NFS shares.

      Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command. File system mounting and unmounting requires you to be logged in as root, or use the sudo prefix to temporarily take on root privileges.

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.

      Source link