Introduction
In Unix-type systems, the kernel treats disks and partitions as special files that must be made visible within the directory tree before being able to read or write on them. This process is known asmontajeand its inverse, the elimination of that bond, is calleddesmontaje. The commandsmountandumountare the most used command line interface for these Linux operations. Knowing its operation allows you to manage USB drives, external hard drives, network partitions and temporary file systems safely and efficiently.
What does the mount command do?
The commandmounttakes a block device (e.g.,/dev/sdb1) or a remote location and associated to a assembly point, which is an existing directory in the file system. Once mounted, the content of the device appears under that directory and can be accessed as any other file or folder. In addition,mountallows you to specify the type of file system, access options and permissions by changing your behavior.
Basic mountain syntax
The simplest way is:
mountdevice point _ of _ assembly
If one of the arguments is omitted,mountcheck the file/etc/fstabto obtain the missing information. When you need to explicitly indicate the type of file system, you use the option-tfollowed by name (e.g.,ext4, ntfsorvfat).
-t tipo: specifies the file system.-o opciones: allows to pass a list of options separated by commas (such asrofor reading only orrwfor reading and writing).-a: mount all file systems listed in/etc/fstabthat have the optionauto.
Common examples of mount
Some cases of common use are shown below:
- Mounting an ext4 partition in
/mnt/data:mount / dev / sda1 / mnt / data
- Mounting a USB drive with vfat file system in
/media/usb:mount -t vfat / dev / sdb1 / media / usb
- Mounting an NFS resource in
/mnt/nfs:mount -t nfs server: / route / shared / mnt / nfs
- Mounting an ISO image as read only in
/mnt/iso:mount -o loop -t iso9660 imagen.iso / mnt / iso
Useful mount options
Some options that are particularly practical on a daily basis:
ro: mount the file system in read-only mode, ideal for media that are not intended to be modified.rw: allows reading and writing (default value in most cases).nosuid: blocks the execution of programs with SUID or SGID bits from the assembly point, increasing security.noexec: prevents the execution of any binary located in the mounted file system.nodev: prevents special device files, useful for user assembly.sync: perform writing operations in a synchronous way, ensuring that the data is written immediately on the device.async: asynchronous operation (by default in many systems), improves performance but may risk data loss if the medium is removed without dismantling.
What does the umount command do?
The commandumountremoves the association between a assembly point and its underlying device or resource. Before removing a removable medium or shutting down a system, it is necessary to dismount to ensure that all R / O operations are completed and the data are consistent. If you try to dismount a file system that is still in use,umountIt will return an error indicating that the appeal is occupied.
Syntax and umount examples
The basic form is:
umountpoint _ of _ assembly
The device can also be specified directly:
umountdevice
Some useful options:
-f: forces disassembly, useful in cases of blocked file systems (should be used with caution).-l: performs a lazy disassembly, releasing the assembly point immediately and cleaning the reference when it is no longer in use.-a: dismount all file systems listed in/etc/fstabother than those marked asnodevornoauto.
Examples:
- Dismount a USB drive mounted on
/media/usb:umount / media / usb
- Forging the disassembly of a partition that appears to be hanging:
umount -f / dev / sdc1
- Dismount all automatic file systems:
umount -a
Good practices and troubleshooting
To avoid problems when working withmountandumount, follows these recommendations:
- Always check that the assembly point exists before trying to mount; believe it with
mkdir -pif necessary. - Check the file
/etc/fstabfor permanent configurations and prevents manual assemblies that may conflict. - After riding, use
df -hormountno arguments to confirm that the device appeared correctly. - Before removing a removable medium, run
syncto empty the writing buffers and thenumount. - If you receive the message 'device is search', use
lsoforfuserto identify processes that are accessing the assembly point and finalise them or change their work directory. - In systems with SELinux or AppArmor, make sure that policies allow access to the assembly point; otherwise, you can see permission errors even with the right flags.
- For network assemblies (NFS, CIFS), test connectivity with
pingand verifies version and security options to avoid authentication errors.
With this knowledge you can safely manage any storage drive in your Linux environment, be it a local disk, a USB drive or a network resource.


