Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: February 9, 2023
In this article, we’ll cover some questions that can arise when starting to manage Linux systems. For example, when installing Linux, we might specify partitions and mounting points that we want to create. However, does Linux create other partitions/mounting points on its own? Are mounting points always related to partitions, or can we mount other things?
Although these questions might seem straightforward, their formulation already includes misconceptions. But before continuing with the explanations, let’s clarify some concepts.
We can understand partitions as portions of the disks dedicated to specific goals. We can have multiple partitions that we can use for purposes such as:
We’ve already discussed what partitions are and what we can use them for. Moreover, we introduced different filesystems that we can set up in our partitions. We’ll now discuss how Linux handles this. To avoid confusion, let’s write file-system to discuss the Linux file directory tree where we see everything displayed. Alternatively, the filesystem is what our partitions have, as described before.
The Linux file-system is based on the root directory, located in /. During startup, the kernel creates this file-system before starting other processes. Within this file-system, the Linux kernel starts to create directories that will point to filesystems. These are folders such as /home, /proc, or /dev.
After the folder creation, the mounting operation associates a directory in the file-system with a filesystem. Therefore, every filesystem should be mounted before accessing it. This means that before accessing data in a filesystem, we need to mount it and link the storage device (filesystem) with a directory in the directory tree (file-system).
Let’s give an example to clarify this. We split the hard drive into two partitions: one for swapping and the other for file storage. The second one has a filesystem of type ex2 that stores a file named foo.txt located under a directory named folder. This yields /folder/foo.txt within the filesystem of the second partition of the hard drive. To access this file, we need to mount the filesystem into a folder located under the / folder of our Linux file-system directory tree, for example, /mnt. Thus, the file will appear in our Linux file-system directory as /mnt/folder/foo.txt.
As a side note, we can access the same filesystem from different file-system directory paths. We need bind mounts to do that.
We can use different tools, such as findmnt, to list all the mounted filesystems in our system:
$ findmnt -oTARGET,SOURCE
TARGET SOURCE
/ /dev/sda5
├─/proc proc
│ └─/proc/sys/fs/binfmt_misc systemd-1
├─/sys sys
│ ├─/sys/kernel/security securityfs
│ ├─/sys/fs/cgroup cgroup2
│ ├─/sys/fs/pstore pstore
│ ├─/sys/fs/bpf bpf
│ ├─/sys/kernel/config configfs
│ ├─/sys/kernel/debug debugfs
│ ├─/sys/kernel/tracing tracefs
│ └─/sys/fs/fuse/connections fusectl
├─/dev dev
│ ├─/dev/shm tmpfs
│ ├─/dev/pts devpts
│ ├─/dev/hugepages hugetlbfs
│ └─/dev/mqueue mqueue
├─/run run
│ ├─/run/credentials/systemd-sysctl.service ramfs
│ ├─/run/credentials/systemd-tmpfiles-setup.service ramfs
│ └─/run/user/1000 tmpfs
│ └─/run/user/1000/gvfs gvfsd-fuse
├─/tmp tmpfs
└─/home /dev/sda6
We’ve requested two outputs. The TARGET is the mounting directory in the file-system. The SOURCE points to the source device. This is either another directory in the /dev folder of the file-system or a filesystem directly.
We can see from the previous command output that there are many mounted filesystems – even if we’ve mounted none of those manually. A Linux file-system mounts, by default, many filesystems at startup. Different distributions of Linux may have different mounted filesystems serving different purposes, but the most common ones are:
Even if those filesystems always appear, we can have other mounting points (and therefore, other filesystems mounted). For example, if we automatically mount an external drive with the mount tool, it will also appear after starting up our system. Also, other services, such as the NFS server, might mount extra filesystems.
The case of the swapping partition is special. Swap is not a filesystem. We don’t need to mount it, and the kernel doesn’t mount it automatically. Swap is only a partition that the system uses as extra memory for paging.
Moreover, we can customize the location where our filesystems appear in the directory file-system. However, there are some file-system directories that we cannot use for our devices. For example, the /proc directory of the file-system always points to the procfs. Therefore, we can neither mount our external hard drive in the /proc directory nor change where the filesystem procfs is.
After defining some concepts and seeing their relationship, let’s return to the original questions.
The first question asked whether Linux creates partitions or mounting points on its own. When installing Linux, we can create as many partitions as we want to divide the hard drive as we please. On those partitions, we can create filesystems and mount those filesystems. Linux on its own doesn’t create new partitions. However, Linux mounts many filesystems on mounting points that are predefined. For example, we see the /proc mounting point that Linux links to the procfs filesystem.
Regarding the second question, we don’t mount partitions, we mount filesystems. This is important because we can mount filesystems that don’t exist on partitions – such as procfs. So, we can say that mounting points are always related to filesystems, regardless of whether they are in a physical partition.
In this article, we’ve talked about three things: partitions, filesystems, and mounting. We’ve clarified two common questions when handling Linux systems. The first is that Linux mounts many filesystems that we don’t create but doesn’t create partitions for us. The second is that we mount filesystems that can be in partitions or not.