How to mount and mount storage devices on Linux Terminal

In the previous article TipsMake showed you how to use the Yes command on Linux. The next article below TipsMake will guide you on how to mount and mount storage devices on Linux Terminal.

File systems on Linux and Unix-based operating systems such as macOS can also be mounted, unmounted, . via Terminal. In the article below TipsMake will guide you how to mount and mount storage devices on Linux Terminal.

How to mount and mount storage devices on Linux Terminal Picture 1How to mount and mount storage devices on Linux Terminal Picture 1

1. File system on Linux

File systems on Linux, macOS, and other Unix-based operating systems do not use separate drive identifiers for storage devices like they do on Windows. Windows assigns each drive a letter, such as C: or D:, and the file system for each drive is the directory below that drive letter.

On Linux, the filesystem is an all-in-one directory tree. A mounted storage device has its filesystem appended to the directory tree to indicate it is an integral part of the mounted filesystem.

The newly mounted filesystem is accessible through the directory it is mounted to. This directory is called the mount point (empty directory) for the file system.

Many file systems are mounted automatically during the boot process or when the drive is connected to the computer while the device is running. If system administrators want, they can disable or turn off the auto-mount feature to control connections to the system.

This means that storage devices connected while the computer is running will not mount automatically and require manual mounting. Mounting the file system manually allows users to select the mount point directory location and set the file system to read-only mode or read-write mode.

2. List the file systems mounted using the mount command

To list all file systems mounted on your computer, simply enter the mount command and press Enter.

How to mount and mount storage devices on Linux Terminal Picture 2How to mount and mount storage devices on Linux Terminal Picture 2

mount will list all connected file systems on the Terminal window.

How to mount and mount storage devices on Linux Terminal Picture 3How to mount and mount storage devices on Linux Terminal Picture 3

If you want you can tweak the output by telling mount to list only the filesystems you're interested in. The -t (type) option indicates what type of filesystem to mount.

mount -t tmpfs
mount -t ext4

How to mount and mount storage devices on Linux Terminal Picture 4How to mount and mount storage devices on Linux Terminal Picture 4

For example, let's say the mount request only lists tmpfs filesystems , so you can more easily manage the output.

The tmpfs filesystem will appear as if it is a mounted filesystem, but it is actually stored in volatile memory, where tmp stands for temporary, instead of being stored. on persistent storage devices.

If you want, you can replace the tmpfs parameter with the file type you are interested in.

In this example TipsMake uses the command to list all ext4 file systems. On the test computer there is only a single ext4 filesystem located on the sda ​​device - the first storage device mounted, usually the main drive and mounted on /, which is the root of the filesystem tree.

Meaning of other indicators:

- rw: Readable and writable file system.

- relatime : the kernel is using an optimization scheme to log file access and meta data modifications.

- errors=remount -o: if fatal errors are detected, the filesystem will be remounted in read-only mode to allow diagnostics.

3. List mounted file systems using df command

In addition to the mount command, we can also use the df command to display mounted file systems and mount point directory locations.

The df command without parameters gives us the same information overload problems as the mount command. For example, on Ubuntu Linux, a pseudo squashfs filesystem is created for applications created with the snap command . We don't need to pay attention to this information at all.

To force df to ignore this or other types of system information, we use the -x (exclude: exclude) option:

df -x squashfs

How to mount and mount storage devices on Linux Terminal Picture 5How to mount and mount storage devices on Linux Terminal Picture 5

Now you can easily see the file system names, sizes, free and used space as well as the mount point directory.

4. Remount all file systems using the fstab command

All file systems mounted during boot have a file called fstab , which is a file system table located in /etc.

We can use mount to force a "refresh" and remount all filesystems listed in fstab. This is useful in case you encounter problems with multiple file systems.

Use sudo and you will receive a message asking for your password:

sudo mount -a

How to mount and mount storage devices on Linux Terminal Picture 6How to mount and mount storage devices on Linux Terminal Picture 6

On computers with file system problems, remounting helps fix the problems. If not, you will at least receive diagnostic messages and system logs that will guide you to the cause of the problem.

5. Mount ISO image

The steps to mount an ISO image and access its contents as part of the file system are quite simple. In the example below TipsMake uses the Tiny Core Linux ISO because of its small size and quick download.

In the same directory containing the ISO image, run the command below. Note: Remember to rename the ISO file you want to mount:

sudo mount -t iso9660 -o loop TinyCore-current.iso /mnt

How to mount and mount storage devices on Linux Terminal Picture 7How to mount and mount storage devices on Linux Terminal Picture 7

Because you use sudo, you will be asked to enter your password.

The -t (type) option indicates the type of filesystem being mounted. This is an ISO file so you provide the iso9660 type identifier.

The -o (options) flag is used to pass additional parameters to mount. The parameter in this example is loop.

Use loop to force mount to use a loop device file connected to the ISO image. A repeater file allows a file (such as an ISO image) to be mounted and processed as if it were a storage device.

Device files are special files used as interfaces for connected devices to display as if they were normal file system files.

There are many different types of device files, in this example only the ext4 file system is mounted and is called sda .

To be more precise, the ext4 filesystem resides on a storage device connected to the filesystem via the device file /dev/sda and the filesystem on the storage device is located at /.

Of course we will have to provide the ISO image name and tell mount the location of the mounted file system. In this example TipsMake chooses /mnt .

The ISO image is mounted, a message will appear on the screen saying that the ISO image is mounted in read-only mode in the Terminal window.

6. Search for the ISO Image

Once mounted, we can navigate to the folders in the ISO image as part of the file system. Note that the ISO image file is mounted at /mnt.

ls /mnt
ls /mnt/cde/

How to mount and mount storage devices on Linux Terminal Picture 8How to mount and mount storage devices on Linux Terminal Picture 8

Unmount ISO image

To unmount a previously mounted file system, we use the unmount command.

First, tell unmount which file system we want to unmount. To do this we just need to provide the mount point of the file system.

sudo umount /mnt

How to mount and mount storage devices on Linux Terminal Picture 9How to mount and mount storage devices on Linux Terminal Picture 9

If there aren't any notifications on the screen, everything is fine.

Create Mount Point

If you want, you can create and use your own mount point. We will call an isomnt and mount the ISO image into it. Basically a mount point is just a directory, so we can use mkdir to create a new mount point.

sudo mkdir /media/dave/isomnt

How to mount and mount storage devices on Linux Terminal Picture 10How to mount and mount storage devices on Linux Terminal Picture 10

In the next step we use the same command format as before to mount the ISO image. However, this time we do not mount the file to /mnt but mount it to /media/dave/isomnt/:

sudo mount -r -t iso9660 -o loop TinyCore-current.iso /media/dave/isomnt/

How to mount and mount storage devices on Linux Terminal Picture 11How to mount and mount storage devices on Linux Terminal Picture 11

You can now access the mounted file system from the new mount point directory.

ls /media/dave/isomnt/cde/optional

How to mount and mount storage devices on Linux Terminal Picture 12How to mount and mount storage devices on Linux Terminal Picture 12

7. Mount Point Link

We can link the mount point to another directory. The mounted filesystem can then be accessed either through the original mount point or through the directory associated with it.

For example, suppose we create a new folder called iso in the home directory, then link the mount point ISO image /media/dave/isomnt to the iso folder in the home directory.

We can access the ISO image through the original mount point /media/dave/isomnt and through the new iso folder. The -B (bind) option requires the name of the mount point and the name of the directory to bind.

mkdir iso
sudo mount -B /media/dave/isomnt/ iso
ls iso
ls /media/dave/isomnt
cd iso
ls
cd cde

How to mount and mount storage devices on Linux Terminal Picture 13How to mount and mount storage devices on Linux Terminal Picture 13

8. Use umount to link Mount Point

File systems with mount points linked to other directories require unmounting from the original mount point and bind point directories.

Even if we unmount the file system from the original mount point directory, we can still access the file system from the linked directory. Additionally the file system must also be unmounted from that directory.

sudo umount /media/dave/isomnt
ls iso
sudo umount iso
ls iso

How to mount and mount storage devices on Linux Terminal Picture 14How to mount and mount storage devices on Linux Terminal Picture 14

Mount the floppy disk

A floppy disk is also a storage device. This means that an sd device file (short for storage device) will be used to connect to the physical device.

We have to set up the sd device file next. To do this, we pipe df 's output through greb and search for entries with " sd ".

df | grep /dev/sd

How to mount and mount storage devices on Linux Terminal Picture 15How to mount and mount storage devices on Linux Terminal Picture 15

In the example in this article, there is a single sd device file used which is /dev/sda . The next sd device file will be /dev/sdb . This means that when we connect the floppy drive to the computer, Linux will use /dev/sdb to connect to the floppy drive.

We will tell mount to mount the file system to the floppy disk connected to the mount point /dev/sdb to the /mnt.

Connect the floppy drive through the USB port on the computer, then run the command below:

sudo mount /dev/sdb /mnt

How to mount and mount storage devices on Linux Terminal Picture 16How to mount and mount storage devices on Linux Terminal Picture 16

9. File system label

We can use the -l (label) option with mount to find the label attached to the filesystem (if any).

Use the -t (type) option to tell mount to report only on vfat file systems .

mount -l -t vfat

How to mount and mount storage devices on Linux Terminal Picture 17How to mount and mount storage devices on Linux Terminal Picture 17

Labels are enclosed in square brackets at the bottom of the list. The label of the floppy drive is NORTUN.

We can access the floppy drive via mount point /mnt:

cd /mnt

ls

ls -l AMATCH.C

How to mount and mount storage devices on Linux Terminal Picture 18How to mount and mount storage devices on Linux Terminal Picture 18

The floppy disk contains C language source code files. The date stamp shows that the file was last modified in October 1992.

If we repeat df through the greb command to list the sd device files, we will see there are 2 floppy drives.

df | grep /dev/sd

How to mount and mount storage devices on Linux Terminal Picture 19How to mount and mount storage devices on Linux Terminal Picture 19

The floppy drive shown is mounted on /dev/sdb. The file system on the floppy drive is mounted at /mnt .

To unmount the floppy drive, we use umount and use the device file as a parameter.

sudo umount /dev/sdb

How to mount and mount storage devices on Linux Terminal Picture 20How to mount and mount storage devices on Linux Terminal Picture 20

10. Umount Lazy option

In case if using the file system that is being unmounted, the process will fail.

sudo umount /dev/sdb

How to mount and mount storage devices on Linux Terminal Picture 21How to mount and mount storage devices on Linux Terminal Picture 21

The process failed because the user's current working directory is in the file system you are trying to unmount. Linux is smart enough to not allow users to see which branch you are on.

To fix this problem, we use the -l (lazy) option. This option makes umount wait until the filesystem can be safely unmounted.

sudo umount -l /dev/sdb

ls

cd -

ls /mnt

How to mount and mount storage devices on Linux Terminal Picture 22How to mount and mount storage devices on Linux Terminal Picture 22

Even though the umount command is being run, the file system is still mounted and the user can list files normally.

As soon as the user changes the directory to the home directory, the soft file system will be released and unmounted. Trying to list files in /mnt will not return any results.

11. Mount Samba Share

Samba is a collection of software services that enable interchangeable network shares between Linux and Unix operating systems and Windows operating systems.

To mount Samba Share on Linux, follow the steps below:

The Raspberry Pi is connected to the same network as the test device with Samba Share integrated. On Samba there is a copy folder named "share". Your task is to create an SSH connection to it and view the contents of the shared folder. This folder is located on the USB drive mounted on the Pi.

The username is pi and the Raspberry Pi's network name is marineville.local:

ssh [email protected]

ls /media/pi/USB64/Backup

exit. exit

How to mount and mount storage devices on Linux Terminal Picture 23How to mount and mount storage devices on Linux Terminal Picture 23

When running the SSH command you will be prompted to enter the Raspberry Pi password.

After entering the password and being authenticated, the command prompt on the Terminal window changes to pi@marineville because it is connected to the Raspberry Pi.

The contents of the shared folder are listed at /media/pi/USB64/Backup. The contents include two folders, one called and dave and one called pat .

Type Exit to disconnect from the Raspberry Pi and the command prompt will change to dave@howtogeek.

To use Samba, we must install the cifs-utils package:

If using Ubuntu or other Debian-based distributions, use apt-get to install this package to your system. On other Linux distributions, use the Linux distribution package management tool instead.

sudo apt-get install cifs-utils

How to mount and mount storage devices on Linux Terminal Picture 24How to mount and mount storage devices on Linux Terminal Picture 24

After the installation process is complete, use the command below to mount the share folder, change the IP address, share name and mount point accordingly:

sudo mount -t cifs -o credentials=/etc/samba/creds,uid=1000,gid=1000 //192.168.4.13/share /media/dave/NAS

How to mount and mount storage devices on Linux Terminal Picture 25How to mount and mount storage devices on Linux Terminal Picture 25

In the command above:

-t cifs : File system type is cifs.

-o credentials=/etc/samba/creds,uid=1000,gid=1000 : optional parameters are the path to a file called creds that is secured and contains the Raspberry Pi user name, password, ID User (UID) and Group ID (GID) are used to establish the root filesystem owner and group.

//192.168.4.13/share: the network location of the device with Samba Share integrated and the Samba name of the shared folder. The root folder of the Share folder is named Backup, but the Samba name of the shared folder is set to Share.

/media/dave/NAS: name of mount point. Note that you must create a mount point first.

By accessing the mount point at /media/dave/NAS we can access the shared folder on the Raspberry Pi on the network. You will see there are 2 Raspberry Pi folders called dave and pat.

cd /media/dave/NAS

How to mount and mount storage devices on Linux Terminal Picture 26How to mount and mount storage devices on Linux Terminal Picture 26

12. Create and mount the file system

We can use the dd command to create the image file, then use mkfs to create the file system and mount.

Use the if (input file) option to tell dd to use the zero value stream from /dev/zero as the input file.

The new output file (of - output file) is called geek_fs.

We use the bs (block size) option to request a block size of 1MB.

Use the count option to tell dd to include 22 blocks in the output file.

dd if=/dev/zero of./geek_fs bs=1M count=20

How to mount and mount storage devices on Linux Terminal Picture 27How to mount and mount storage devices on Linux Terminal Picture 27

The created image file contains nothing but a value of 0.

Next use the mkfs command to create the file system inside the geek_fs file. The -t (type) option allows selection of the file system type. In this example TipsMake creates the ext4 filesystem .

mkfs -t ext4 ./geek_fs

How to mount and mount storage devices on Linux Terminal Picture 28How to mount and mount storage devices on Linux Terminal Picture 28

To mount the image file into /media/dave/geek , then use chown to set the owner and group to allow access to the file:

sudo mount ./geek_fs /media/dave/geek

sudo chown dave:users /media/dave/geek

How to mount and mount storage devices on Linux Terminal Picture 29How to mount and mount storage devices on Linux Terminal Picture 29

To change to the new file system and copy in a file for viewing:

cd /media/dave/geek

cp /etc/fstab .

ls -l

How to mount and mount storage devices on Linux Terminal Picture 30How to mount and mount storage devices on Linux Terminal Picture 30

If we use mount to list mounted filesystems but restrict the output to ext4 filesystems using the -t (type) option, the output shows that there are 2 filesystems. ext4 file is mounted.

mount -t ext4

How to mount and mount storage devices on Linux Terminal Picture 31How to mount and mount storage devices on Linux Terminal Picture 31

13. Remount the file system

To remount the file system, we use the -o remount option. This process is performed to change the file system from read-only state to read-write state.

Suppose to remount the floppy drive, we will use the -r (read-only) flag, then mount via grep and look for the floppy drive filesystem details:

sudo mount -r /dev/sdb /mnt

mount | grep /mnt

How to mount and mount storage devices on Linux Terminal Picture 32How to mount and mount storage devices on Linux Terminal Picture 32

As you can see ro is marked to indicate the filesystem is mounted read-only.

Use the -o remount option with the rw (read-write) flag to unmount and remount the filesystem with the new settings:

sudo mount -o remount,rw /mnt

Repeating the mount process via grep, you can see that ro is replaced by rw , meaning the file system is now in read-write mode.

mount | grep /mnt

14. Move file system

If you want, you can unmount and remount the file system on another mount point with just a single command.

The -M (move) option in mount allows you to do this. However, the option is no longer active in Linux distributions, we use systemd instead.

If you try to move system files from /mnt to ./geek , the process will fail and an error message will be displayed on the screen as shown in the image below.

sudo mount -M /mnt ./geek

ls ./geek

How to mount and mount storage devices on Linux Terminal Picture 33How to mount and mount storage devices on Linux Terminal Picture 33

To solve this problem, we use the previous -B (bind) option to bind the original mount point to the new mount point.

sudo mount -B /mnt ./geek

ls ./geek


The above article TipsMake has just shown you how to mount and mount a storage device on the Linux Terminal. In addition, if you have any questions or concerns like how to compare text files on Linux Terminal , readers can leave their comments in the comments section below the article.

4.5 ★ | 2 Vote