Disk mounting in Linux has various ways to do it. We will go through from the commonly used to the conveniently used methods.
The commonly used version is the udisksctl
command. It is straight forward, automatic, and without the need of root privilege.
To mount, the command pattern is:
$ udisksctl mount --block-device <device partitions>
It will automatically creates a directory using the device label and mount it at /media/<username>/<device label>
There are a bunch of flags to use. Here are the list of its descriptions:
Usage:
udisksctl mount [OPTION...]
Mount a filesystem.
Options:
-p, --object-path Object to mount
-b, --block-device Block device to mount
-t, --filesystem-type Filesystem type to use
-o, --options Mount options
--no-user-interaction Do not authenticate the user if needed
Here is the example command:
$ udisksctl mount -b /dev/sdb1
Mounted /dev/sdb1 at /media/u0/usbPartitionLabel.
To unmount a device, we use the unmount function. The command pattern is:
$ udisksctl unmount --block-device <device partitions>
There are a bunch of flags to use. Here are the list of its descriptions:
Usage:
udisksctl unmount [OPTION...]
Unmount a filesystem.
Options:
-p, --object-path Object to unmount
-b, --block-device Block device to unmount
-f, --force Force/lazy unmount
--no-user-interaction Do not authenticate the user if needed
Here is an example command:
$ udisksctl unmount -b /dev/sdb1
Unmounted /dev/sdb1.
The most manual and common way is to use mount
and umount
commands. This is the most manual and used everywhere including system boot. You need root access to perform these manual steps.
To mount, you need to make or use an existing directory and the mount
commands. The pattern is as follows:
$ mkdir -p <directory_name> # optional
$ mount <device_partition> <directory_name>
Here are some examples (they are not sequenced, just to show)
# mount an existing remapped logical volume
$ mount /dev/mapper/localstore--root /mnt
# use the existing temporary mount point
$ mount /dev/sdb1 /mnt
# create your own directory
$ mkdir -p origin && mount /dev/sdb1 ./origin
To unmount, you need to use the umount
command and then manually remove the directory if your created one. The pattern is as follows:
$ umount <directory_name OR device_partition>
$ rm -r <directory_name> # optional, if you created one yourself
Here are some examples (they are not sequenced, just for show):
# unmount from device partition
$ umount /dev/mapper/localstore--root
# umount from mounted directory
$ umount /mnt
# umount and remove your own directory
$ umount ./origin && rm -r ./origin
That's all about Linux disk mounting management