File systems in Linux and Unix-like operating systems, such as macOS, can be mounted, mounted and re-mounted with the terminal. This is a powerful and versatile tool – here you will find everything you need to know.
The Linux File System
The file systems on Linux, macOS, and other Unix-like operating systems do not use separate disk storage device identifiers in the way that Windows does, for example. Windows assigns a drive letter such as C: or D: to each volume, and the file system for each volume is a directory tree that is under that drive letter.
On Linux, the file system is an all-in-one directory tree. The file system of a mounted storage device is grafted onto this tree, so it appears to be an integral part of a contiguous file system. The newly mounted file system can be accessed from the directory to which it is mounted. This directory is called the mount point for this file system.
Many file systems are automatically mounted as a storage volume at boot time or during operation, and are connected to the computer at runtime. Careful system administrators can disable the auto-provisioning features at runtime to control connections to the system.
This means that storage devices connected at runtime may not be deployed automatically and must be provisioned manually. If you deploy a file system manually, you can make decisions about that file system, such as: For example, where the mount point is and whether the file system should be read-only or read-only.
Whether or not This is Not Required You can use the commands
remount to control this important aspect of your Linux system.
Query your file system mount
Mount has a lot of options, but listing all mounted filesystems on your computer does not require any options at all. Just enter
mount and press Enter:
mount lists all the associated file systems in the terminal window.
It can be difficult to search this snapshot with data to find what you are looking for.
You can refine the output by listing
mount to list only the filesystems that are of interest to you. The option
-t (type) tells
mount which type of file system to report.
mount -t tmpfs
mount -t ext4
As an example, we have requested
tmpfs file systems. We get a much more manageable edition.
tmpfs file system appears like a regular mounted file system, but is actually stored in a volatile memory – the -tmp stands for temporary – instead of on a persistent storage device.
You want to use the parameter
tmpfs for the file type you are interested in.
We also issued a command to list
ext4 file systems. This test computer has a single
ext4 file system. It is located on device
sda – the first storage device usually installed on the main hard disk – and is the root of the file system tree on
The other indicators mean:
- rw : The file system is readable and writable.
- relatime : The kernel uses an optimized schema to record file access and change metadata.
- Errors = Remount -o : If a sufficiently fatal error is detected, the file system is re-mounted in read-only mode to allow diagnostics.
] RELATED: Which Linux file system should you use?
Interrogate Your File System with df
df command can also be used to indicate which file systems are mounted and where their mount points are located.
df without parameters, you will get the same information o problem as
Mount Download. In Ubuntu Linux, for example, there is a pseudo-file system
squashfs that was created for each application that was installed with the command
snap . Who wants to see all these files?
df to ignore it – or another file system type – use the option
df -x squashfs
You can easily see the names of the file systems, their capacities, used and free space, and their mount points.
RELATED: Viewing Free Space and Disk Usage on the Linux Terminal
Reattaching All File Systems to fstab
There are entries for all file systems mounted at boot time In a file named
fstab the file system table in
/ etc .
You can use
mount to force an upgrade and reinsert all file systems listed in
fstab . Under normal operating conditions this is not required. If you have problems with multiple file systems, it becomes something special.
You must use
sudo to prompt for your password.
sudo mount -a  mount -a command in a terminal window " width="646" height="97"/>
On a properly working computer, this is somewhat insurmountable.
On a computer with file system issues, resolving the issues may help. If this is not the case, you will receive diagnostic messages on the screen and in the system logs to help you find the cause of the problem.
RELATED: What Is the Linux fstab file and how it works
Mounting an ISO image
It's easy to mount an ISO image with it You can access its contents as part of the file system.  This works with any ISO image. In this example, we happen to use a Tiny Core Linux ISO because it's small and fast to download. (A tiny Linux distribution with a graphical user interface (in 18 MB). You probably have .mp3 files larger than this.)
Issue this command in the same directory as the ISO image. Replace the name of the ISO file that you are mounting.sudo mount -t iso9660 -o loop TinyCore-current.iso / mnt
Because we need it to use
sudoyou have to enter your password.
-t(type) option tells
mountwhat file system type we are mounting. Since it is an ISO file, we specify the type identifier
-o(options) is used to pass additional parameters to
mount. , Our parameter is
mountto use a loop device file to connect to our ISO image. With a loop device file, a file (such as the ISO image) can be deployed and treated as a storage device.
Device files are special files that are used as an interface, so connected devices look like normal files in system files. This is part of what in Linux is all about a file design philosophy.
There are many different types of device files. We saw one earlier when we found that the only
ext4file system on this test machine was mounted on
/and was named
sda. More precisely, the file system
ext4is located on a storage device containing the device file
/ dev / sdaand the file system on this storage device at
/ with connected to the file system..
Of course, we need to specify the name of the ISO image and tell
mountwhere to mount the file system. We have chosen
The ISO image is mounted. The terminal window displays a reminder that ISO images are always provided in read-only mode.
Browsing the ISO Image
After the image has been deployed, we can browse the directories in the ISO image in the same way as part of the file system. Let's list the files in the ISO image. It is mounted under
/ mnt.ls / mntls / mnt / cde /
Log off the ISO image
Use the command
umountto undeploy a mounted file system. Note that there is no "n" between "u" and "m" - the command is
umountand not "unmount".
You must tell
umountwhich file system you are unmounting. Specify the mount point of the file system.Command sudo umount / mnt
No message is good news. If there is nothing to report, everything is fine.
Creating a Mount Point
You can create and use your own mount points. We will create one with the name
isomntand mount our ISO image on it. A mount point is just a directory. So we can use
mkdirto create our new mount point.sudo mkdir / media / dave / isomnt
Now we can use the same command format as before to mount our ISO image. This time we will not mount it on
/ mntbut on
/ media / dave / isomnt /:sudo mount -r -t iso9660 -o loop TinyCore-current.iso / media / dave / isomnt /
We can now access the embedded file system from our new mount point.  ls / media / dave / isomnt / cde / optional
These paths, however, are very long. This gets boring quickly. Let's do something about it.
Binding a mount point
You can bind a mount point to another directory. The deployed file system can then be accessed either through the original mount point or through the directory attached to it.
Here is an example. In our home directory, we create a directory named
iso. Then we bind the mount point of the ISO image
/ media / dave / isomntto the new directory
isoin our home directory.
We can access the ISO image via the original mount point
/ media / dave / isomntand the new directory
iso. The option
-B(bind) requires the name of the mount point and the name of the directory to bind to.mkdir isosudo mount -B / media / dave / isomnt / isols isols / media / dave / isomntcd isolscd cde  Bind mount points in a terminal window " width="646" height="352"/>
Use umount with binds
For a file system whose mount point is bound to a different directory, you need to mount its mount point and cancel the bind point.
Even if you detach the file system from its original mount point, it can still access the file system from its bound directory. The file system must also be unsubscribed from this directory.sudo umount / media / dave / isomntls isosudo umount isoIs Iso
Deploying a diskette
A diskette drive (with a diskette inside) is a storage device. This means that an SD device file (for a storage device) is used to connect to the physical device. We need to determine what the next free SD device file is. We can do this by directing the output of
grepand looking for entries with "sd".df | grep / dev / sd
This computer uses a single SD device file. This is
/ dev / sda. The next SD device file output is
/ dev / sdb. In other words, when we connect the floppy drive to the computer, Linux uses
/ dev / sdbto create a connection to the floppy drive.
mountto mount the file system on the diskette in the floppy disk drive connected with
/ dev / sdbto the mount point
Insert the floppy disk into the floppy disk drive and connect the floppy disk to a USB port on the computer. Issue the following command:sudo mount / dev / sdb / mnt
File System Names
We can use the characters
-l] (label) option with
mountto find out which label is attached to a file system. Labels are no more than any name. They have no functional purpose.
We use the option
-t(type) to request
mountto report only about
vfatfile systems.  mount -l -t vfat
The label is in square brackets at the end of the listing. The name for this floppy disk drive is NORTUN.
The floppy drive is accessed via the mount point
/ mnt.cd / mntlsls -l AMATCH.C
The disk contains source code files in C language. The date stamp of a file shows that it was last modified in October 1992. She is probably older than many of our readers. (Of course, the meaning of NORTUN as a term is lost in the fog of time.)
If we repeat our command
dfpassed through the command
grepto SD device files We will see that there are now two of them.df | grep / dev / sd
Our floppy drive is displayed as bound in
/ dev / sdb. The file system on the disk in the drive is mounted at
To stop mounting the floppy disk, we use
umountand pass the device file as a parameter.  sudo umount / dev / sdb
The umount Lazy Option
What happens if you (or another user) use the file system when unmounting? it? Unpairing fails.sudo umount / dev / sdb
The user's current working directory is in the file system he is trying to provision. Linux is so smart that you do not lose sight of the branch you are sitting on.
To overcome this, use the option
-l(lazy). This causes
umountto wait until the file system can be safely unmounted.sudo umount -l / dev / sdblscd ~ls / mnt  umount -l lazy option in a terminal window " width="646" height="262"/>
Although the command
umountis issued, the file system is still mounted, and the user can list the files as usual.
Once the user changes the directory to its home directory, the floppy file system is freed and the provisioning is revoked. Attempting to list the files in
/ mntdoes not yield results.
Mounting a Samba Share
Samba is a set of software services that can be used to interchangeably share network shares between Linux and Unix-like operating systems and Windows operating systems.
Setting up Samba is beyond the scope of this article. However, if you have authorized access to a Samba share that has been made available to you, you can use it in this way on Linux.
There is a Samba share on a Raspberry Pi connected to the same network as the test computer. It's a directory called Backup that has the Samba name "share." Make an SSH connection to it and look at the contents of the shared directory. The shared directory is located on a USB flash drive on the Pi.
The username is
piand the network name of the Raspberry Pi is
marineville.local.ssh pi @ marineville.localls / media / pi / usb64 / backupquitting
The user issues the command
SSHand is prompted to enter your Raspberry Pi password.
You enter your password and are authenticated. The terminal window prompt changes to
pi @ marinevillebecause it is connected to the Raspberry Pi.
You list the contents of the shared directory at
/ media / pi / USB64 / Backup. The contents are two directories, one with the designation
Daveand one with the designation
Pat. So now we know what to expect when we activate the Samba share.
exitto disconnect from the Raspberry Pi, and the command prompt changes back to
dave @ howtogeek.  To use Samba you must install the package
apt-getto install this package on your system if you have Ubuntu or another Debian-based distribution. Instead, use the package management tool of your Linux distribution on other Linux distributions.sudo apt-get install cifs-utils
After completing the installation, hang the share with a command like the following, which specifies the IP address, the share name and adjust the deployment point (which must already exist) to your circumstances.sudo mount -t cifs -o credential = / etc / samba / creds, uid = 1000, gid = 1000 //192.168.4.13/share/media/dave/NAS
Let's break down the parts of this command.
- -t cifs ]: The file system type is cifs.
- -o credentials = / etc / samba / creds, uid = 1000, gid = 1000 : The option parameters are the path to a file named
credswhich is secured and the username and contains the password for the Raspberry Pi user; The user ID (UID) and group ID (GID) used to set the owner and group of the root directory of the file system.
- // 192.168.4.13/share: The network location of the device with the Samba share on it and the Samba name of the shared directory. The root of the share is a directory named
Backup. However, the name of the Samba share is
- / media / dave / NAS : The name of the mount point. You must create your deployment point in advance.
Accessing our mount point at
/ media / dave / NAS we access the shared directory on the Raspberry Pi through the network. We can pat the two folders on the Raspberry Pi with the names
cd / media / dave / NAS
Creating and mounting a file system
You can use the
dd command create an image file and then create a file system with
mkfs . This file system can then be mounted. This is a great way to practice and experiment with
With the option
if (inputfile), we inform
dd that the stream to be used by is nullable from
/ dev / zero as an input file.
of (output file) is a new file named
We use the option
bs (block size) to request a block size of 1 MB.
We use the option
count to include
dd 20 blocks in the output file.
dd if = / dev / zero of./geek_fs bs = 1M count = 20
That creates our image file for us. It contains only null values.
With the command
mkfs we can create a working file system in the file
geek_fs . With the option
-t (type) you can select the file system type . We create a
mkfs -t ext4 ./geek_fs[19659184lightboxesthemkfscommandinaterminalwindow"width="646"height="292"/>
That's all it takes to have a working filesystem.
Hang it up
/ media / dave / geekand then use
chownto assign the owner and group owners to access it.sudo mount ./ geek_fs / media / dave / geeksudo chown dave: user / media / dave / geek
Does this work? Let's go to the new file system and copy a file to display them.cd / media / dave / geekcp / etc / fstab.ls -l
We were able to change the directory to the new file system and have successfully created a copy of
/ etc /. fstabfile. It works!
If you use
mountto list the attached file systems, but limit the output to
ext4We will see that there are now two mounted file systems
ext4.mount -t ext4
Re-mounting a file system
Re-attaching a file system adds option
-o to re-mountused. Typically, a file system is changed from a read-only (test) state to a read-only (production) state.
Hang the floppy drive again. This time we use the
-rflag (read-only). Then we redirect
grepand look at the details of the floppy disk file system.sudo mount -r / dev / sdb / mntmount | grep / mnt
As you can see from the
rohighlighted, the file system is read-only
] -o remount With the option
rw(Read / Write) allows us to unmount and mount the file system with the new settings in a single command.sudo mount -o remount, rw / mnt
The repetition of the piping from
rwhas been replaced (highlighted). The file system is now in read / write mode.mount | grep / mnt
(Not) Moving a File System
Previously, you could unmount a file system with a single command and reattach it to another mount point.
-M(move) option in
mountis specifically designed to enable you to do this. However, it no longer works in Linux distributions that were switched to
systemd. And those are the biggest names.
If we try to move a file system from
/ geekit will fail and the error shown below will be displayed. The attempt to list the files in the files ystem to
./ geekdoes not lead to any result.sudo mount -M / mnt ./geek[19659016[19459087<movingafilesysteminaterminalwindow" width="646" height="197"/>
You can work around this problem by using the previously used
-B(bind) option bind the original mount point to the new mount point.sudo mount -B / mnt ./geek[19659016[ls/geek[19659208<AlsoiftheoriginalmountpointisnotenableditwillhavethesamepracticalresultClosing notes
- make-privateoption It was possible to force the move to
systemdversions of Linux. This technique is not presented here for two reasons.
- It can have unpredictable behavior.
- It was not consistent and had to be repeated every time it was restarted.
Devuan Linux uses
systemd. A computer was loaded and tested with the latest version of Devuan. Option
-M(move) worked as expected on this system.
Apart from the
systemdproblems with the option
-M(moving), you should uncomplicated the use of
umountFind. These are great commands to keep track of a corrupted system and reassemble the file system by hand.