mount/umount

The mount and umount commands are used to attach (mount) or detach (unmount) filesystems to/from the system's directory tree, respectively.

mount command

The mount command can be used to attach a filesystem (such as from a storage device, like a hard drive or USB) to a specific directory on the system's directory tree. This allows the attached filesystem to be accessible from the mount point.

Basic command:

$ mount <storage_device> <mount_point> 

<storage_device>: The storage device or partition to mount (eg. /dev/sda1, /dev/sdb1, etc.)

<mount_point>: The directory to mount the filesystem defined by the <storage_device> value, to allow it be accessible from (eg. /mnt, /media, etc.)

Example

To mount the device /dev/sda1 to the /mnt/test-mount directory.

$ mount /dev/sda1 /mnt/test-mount

This allows the contents of the filesystem on /dev/sda1 to be accessible from /mnt/test-mount. The chroot command can be used to change the root directory to /mnt/test-mount, to be able to work directly from there. (https://jarrettgxz-sec.gitbook.io/linux/filesystem-and-directories/chroot)

umount command

The umount command can be used to detach a filesystem. It ensures that the filesystem is properly unmounted before it can be physically removed or shut down.

Basic command:

$ umount <storage_device or mount_point> 

<storage_device or mount_point>: Either the storage device that was mounted, or mount point. (eg. /dev/sda1, /dev/sdb1, /mnt, /media, etc.)

Example

To unmount the device /dev/sda1 (/mnt/test-mount directory).

$ umount /dev/sda1 
# OR
$ umount /mnt/test-mount

This command unmounts the filesystem, making it no longer accessible from the mount point location.

Last updated