- How to Mount and Unmount Filesystem in Linux
- 1. Introduction
- 2. Use mount Command
- 3. Unmount Filesystem
- 4. Mount Disk on System Boot
- Linux mount command to access filesystems, iso image, usb, network drives
- Linux Mount Command Scenarios and Examples
- Mount File System (ext3, ext4, xfs and so on..)
- How to get UUID and file system type?
- What are the different fstab options?
- Mount ISO File
- Virtual Media ISO Image
- ISO DVD Image
- Mount USB Drive
- 6 commands to list USB devices and check USB ports
- 1. Journalctl or /var/log/messages
- 2. lsusb
- 3. lsscsi
- 4. lsblk
- 5. blkid
- 6. fdisk
- USB Drive with NTFS File System
- USB Drive with FAT32 or vFAT File System
- Mount Network Drive
- How to unmount file system and other removable devices?
- Related Posts
- 19 thoughts on “Linux mount command to access filesystems, iso image, usb, network drives”
How to Mount and Unmount Filesystem in Linux
1. Introduction
Mount is to access a filesystem in Linux. You can mount a filesystem on any directory and access content by entering to that directory. In Linux terms, these directories are called mount points. This tutorial will help you to mount and unmount filesystem in Linux system.
2. Use mount Command
Mostly, each Linux/Unix operating systems provides mount command. This command is used to mounting any file system on any directory. After that you can access the filesystem content.
For example, you have added a disk /dev/sdb on on your system. Now you want to mount this on /data directory. Use following command to mount it.
Mount command automatically detects the file system on disk. But in some cases, you need specify the file system type with command.
3. Unmount Filesystem
Use umount command to unmount any mounted filesystem on your system. Run umount command with disk name or mount point name to unmount currently mounted disk.
4. Mount Disk on System Boot
You also required to mount disk on system boot. So that partitions will be available on system boot. /etc/fstab file is used to mount disks. You need to edit /etc/fstab and make new entry to mount the partitions automatically.
Edit /etc/fstab and append below line at end of file. Change /dev/sdb with your disk name.
Now run mount -a command to immediate mount all disk defined in /etc/fstab file.
Источник
Linux mount command to access filesystems, iso image, usb, network drives
Table of Contents
In this article I will cover various topics using Linux mount command to perform temporary and permanent mount. We will try to access file system, USB drives, ISO images, network drives using Linux mount command and unmount them using umount command with examples. before you mount USB drive using Linux mount command, you must know how to list USB drives and check USB ports in Linux so you know the connected USB drives in Linux. I will also share some fstab example, explain fstab options and syntax to mount permanently using Linux mount command.
I have used RHEL/CentOS 7/8 to demonstrate the examples from this article on Linux mount command and it’s usage.
Linux Mount Command Scenarios and Examples
Below I will cover various scenarios to access file systems temporarily and permanent using Linux mount command with examples.
Mount File System (ext3, ext4, xfs and so on..)
Using Linux mount command you can mount various types of system file system. But this will be active only for the current session (not reboot persistent). For such requirement you can use /mnt mount point along with Linux mount command.
Syntax to mount file system
So we can mount /dev/sdb1 without specifying file system type
or with -t option
To permanently mount file system, you must add device and mount point entry in /etc/fstab
I will create a new mount point directory
Now we can mount our xfs file system /dev/sdb1 on /mydata mount point.
But this is again temporary, to mount file system permanently we have to update /etc/fstab in the below fstab format. fstab example from my setup:
How to get UUID and file system type?
To get UUID of a file system using blkid
In the same output you can see the file system type as XFS
What are the different fstab options?
In /etc/fstab we have 6 different section per column with different possible options. Each row is broken into six fields of data, separated by whitespace. Below are the different fstab options
- The device to mount (Here we have used UUID or you can also use /dev/sdb1).
- The mount point (/mydata).
- The filesystem type (xfs).
- The mount options (defaults).
- Dump level (0). This field is related to the dump command and is rarely used.
- The fsck pass field (0). A value of 0 means “do not run fsck on this filesystem during system boot,” whereas a value of 1 or higher means “run fsck on this filesystem during system boot.”
Mount ISO File
There are two possible scenarios to mount ISO files:
- Mount ISO File from Virtual Media
- Mount ISO File DVD
In either scenario to mount ISO file you have to use iso9660 as the file system type along with Linux mount command.
Virtual Media ISO Image
On RHEL/CentOS 7 any ISO File on Virtual media is available under /dev/srX file system. For example my ISO File is available under /dev/sr0 and /dev/sr1
To mount ISO file from virtual media on /media using Linux mount command:
To permanently mount ISO file using /etc/fstab we use similar syntax with below fstab format as we used to mount file system. fstab example from my setup
ISO DVD Image
If you have an ISO DVD Image File available on your Linux system, you can mount ISO file DVD using again iso9660 as the file system type with Linux mount command:
Again to permanently mount ISO DVD File use /etc/fstab we use similar fstab format. Below is fstab example from my setup to mount iso image
Mount USB Drive
Before I share the steps to mount USB drive, you must be familiar to check and list USB devices connected to your Linux host and check USB ports. There are various methods and commands available to list USB devices and check USB ports, I will try to share some of them here:
6 commands to list USB devices and check USB ports
Below I will share various commands you can use in Linux to view and list connected USB devices to your Linux host and check USB ports.
1. Journalctl or /var/log/messages
You can use journalctl or /var/log/messages to check usb ports and list usb devices which were connected to your Linux machine. below is a snippet of my /var/log/messages on RHEL/CentOS 7/8 node. Observe the highlighted section to list USB devices connected.
2. lsusb
You can check usb ports in linux using lsusb . lsusb tool is part of usbutils rpm. So install usbutils to check USB ports in Linux. For example I have a single USB connected on Port 1:
3. lsscsi
You can list all the devices connected to Linux using lsscsi . So to list USB devices also you can use lsscsi command in Linux. Here my USB drive is mounted on /dev/sdc
4. lsblk
Use lsblk to show and list usb devices and partition which are connected to your linux machine.
5. blkid
Use blkid to list usb devices and all the required details. As you can see my USB drive is NTFS file system. If you execute blkid without any arguments, it will list all the connected devices to Linux host.
6. fdisk
Using fdisk you can list all the connected storage devices. We will use fdisk to list usb devices. If you have multiple drives connected to your Linux machine then the list can be long, you can look towards the end of fdisk -l output, for example
As you see this is dos disk with size of 14.6 GB and type as HPFS/NTFS/exFAT so this is most likely our USb drive, you can again confirm this by using lsscsi or any other commands from above list.
USB Drive with NTFS File System
Now that you can list USB devices and check USB ports, to mount USB drive with NTFS file system type using Linux mount command we need ntfs-3g driver in Linux. If you attempt to mount USB drive without ntfs-3g driver then mount will fail
ntfs-3g is an NTFS driver, NTFS supports several filename namespaces: DOS, Win32 and POSIX. While the ntfs-3g driver handles all of them, it always creates new files in the POSIX namespace for maximum portability and interoperability reasons
Create a mount point
Now try to mount USB drive using Linux mount command
Mount is successful
Use similar fstab format as used in above examples to permanently mount usb drive with ntfs file system type. Below is fstab example to mount usb drive with ntfs file system.
USB Drive with FAT32 or vFAT File System
You will list USB devices, check USB ports and use blkid to check the file system type, as you see the file system type of this USB drive is vFAT. To mount USB drive with vfat file system type using Linux mount command we need vfat module.
Check if vfat module is loaded on the system:
If the vfat is not loaded, load it by running:
Next to mount USB drive with FAT32 or vFAT file system using Linux mount command:
Similar to NTFS file system type use same fstab format, use below fstab example to mount usb drive permanently using /etc/fstab
Mount Network Drive
I have a NFS server available at 192.168.0.121 and have shared /mydata directory on this server. To mount network drive from NFS
Mount NFS Network Drive using NFSv4
Mount NFS Network Drive using NFSv3
To mount network drive permanently use /etc/fstab the fstab format will remain the same, except the first column you have to give NFS server details and the source path. Below is fstab example from my NFS share ( /mydata ) on 192.168.0.121
How to unmount file system and other removable devices?
Use umount command to unmount any type of file system, usb drives, network drives or iso images.
So if my file system is mounted on /mnt
You may face error » umount: /mnt/usb: target is busy » some times while truing to umount file system. This means that the file system is in use, this error is similar to the error we see in Windows while trying to eject a USB drive » The device is currently in use «
In such case you can use lazy umount using » -l «
which means as soon as /mnt/usb is not used by any other process, it will unmount itself
Or alternatively you can look for processes which is using /usb/mnt using lsof
Then you can decide to kill those process (kill -9
) but remember by doing so any ongoing task or operation will be killed.
Lastly I hope the steps from this article on Linux mount command to mount ISO file, USB drive, network drive and file systems, list USB devices, check USB ports, understanding fstab options, fstab format and examples were helpful. So, let me know your suggestions and feedback using the comment section.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
19 thoughts on “Linux mount command to access filesystems, iso image, usb, network drives”
Hello,
Thank you for this article, very helpfull. I mounted an external DD with USB and put this in FSTAB
UUID=09B1-F7B2 /firewire vfat rw,user,exec,umask=000,iocharset=utf8 0 0
The disk is mounted, work fine, but I can’t change the owner of the folders (Operation not permitted
).
It is always Root:root the owners, and I want to change, because when I make backup from system files I want to preserve the owner from the source.
I have tried to format the disk in ext4 but it seems that it is not possible ? How can I know if the disk is copatible to ext4 ?
In advance thanks for any help
Eric from France
1. If the external Disk is mounted as read write then I don’t think you should get that error. Which folder permission are you trying to change? The folder where the disk is mounted or any other folders inside the mounted path
2. What error you get while trying to format the disk with ext4?
Hi admin,
Thank you for trying helping me.
Here my last /etc/fstab for the external DD (maxtor old 20 years):
As you see I mounted directly the disk on the root like this : /firewire (but it is usb link). I have tried under /mnt/firewire but it is the same. Do you think this point is important ?
Here the mistake I have when I want to change the owner :
I am under opensuse Leap 15.2.
So I tried first to format with yast to ext4 and it said that an error was raised, but I don’t remember exactly the details. If you think it is important I can try to format again and give you the exact error. I’ve tried also under command line, but gave the same : some error I don’t remember exactly
Thank again for any idea / clue,
eric
Thanks for sharing these details.
Unfortunately we cannot change permissions of existing files and folders on an external driver with NTFS and vFAT file system so you can mount these drives using uid=XXX and gid=XXX options where you can add the UID and UID of the respective user to which you wanted to change the ownership.
Regarding the formatting an vfat with ext4, it worked for me properly using fdisk. If you can share any error snippet then I can try to reproduce and help you recover.
Here would be the brief steps. For example your external drive is on /dev/sdb
WARNING: This step would delete all your DATA
Hello admin,
Thank you! UID and GID options do the job.
Now I am owner of the folders/files, but I am not sur that it will be suficient for the backup script to preserve credentails because I have understand that now I will be the owner of all the files (old and news ) even the source is different and the user is under the GID . right ?
Here are the results of fdisk
As you can guess my pb is that I want to preserve credentials from a backup and 2° pb I can’t save More 4GB on this disk, that why I tri to pass it under ext4, to save some VMachines.
Thank for any help,
Eric
I am not sure if I understand your requirement. Can you please help me understand the question and the issue.
Hi admin,
I have a backup script that is intended to preserve rights/credentials ( I want to say owner/permission of uid,gid), like this :
The -p option should preserve attributs of the owner from the source to the target, but when it is executed :
In English it means that it doesn’t support to keep the owner permissions to the target, because the target is Fat32 and you explain me I can’t change these permissions after FSTAB.
So now, I will try to pass the disk under ext4. I will give you if you agree the exact error and what I do.
Thank you again,
Regards
Eric
If you are taking a backup then it should not fail unless you are trying to overwrite a file with the same name in which case you will get the permission issue.
So to overcome this you can create a new directory every time you take a backup and it should work
Hi admin,
Again me, below the result of format to ext4 :
there is no UUID, it is normal ?
Thank a lot for advice,
Here is the problem:
If you read my previous comments, you cannot directly assign a file system on NTFS/vFAT device. So you must delete the partition first and then create a new partition.
Hi admin,
Thank you for information and advices. I have followed your instructions. Here the result:
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
If I go back to Fat32 (gparted) it should be ok for format the sdc1, so I don’t really understand what happen,
thank you for any help
This is really weird but I see there are a number of users who seem to face similar issues reported on multiple forums. Can you try wiping the filesystem from your pen drive using
Replace sdx with your USB device. Run this command carefully as this can destroy your Linux FS
and then try to use fdisk /dev/sdc, delete the partition and save the changes using “w” (Do not create a new partition here)
Next remove the external disk and replug it. Now you can create new partition using fdisk /dev/sdc
and then try to use mkfs.ext4 /dev/sdc1
Hi admin,
After severals attemps, it is impossible to format this disk to ext4. I tried what you propose, I tried severals things without succes, pb is with super-blocks.
Anyway, I have bought a new disk size of 4To, and everything are ok now for ext4.
I format back to Fat32 for the ‘firewire’ with uid/gid and it is ok.
Thanks for sharing the result. This mostly tells that your disk was corrupted, I am glad you bought a new hardware. May be time to retire the old one.
Hi admin,
Again me, I have a pb that I can’t solve. Perhaps it is easy for you with one magic correct command ?
I have my network drive on the box that I mount whithout problem with the following terminal command:
But in FSTAB I don’t find the correct sentence.
I tried this without success.
I have googled but no more success ?
Do you know the correct command in FSTAB for this disk ?
Again, Admin thank you
Can you try to use following line in /etc/fstab :
Here 040 is the ASCII code for space in octal numeral system. But mount.cifs will not support 040 code so you will have to use backslash or double quotes for the whitespace in your PATH NAME.
alternatively you can use double quotes to ignore the whitespace in your PATH
I would suggest to remove the whitespace and use Disque_dur instead which should be more appropriate. These spaces in names and paths can be really hectic when working with shares at times and should be avoided.
Thank you Admin !
give ==> parse error at line 8 — ignored
I will look how to rename the ‘ Disque Dur ‘ to avoid space, but it come with the provider (free), so I am not sure we can rename it. Anyways, it is ok with the magic ‘ 040 ‘ ASCII code, until a test after reboot to validate completely,
Thank again Admin, have a good week,
Regards
Eric
You can test without rebooting the node by manually unmounting /mnt/freebox then add the entry in /etc/fstab and execute
from the terminal as root user (or with sudo)
This should mount all the filesystems from /etc/fstab
Hi admin,
It is, ok, with mount -a and reboot too…
Thank you very much,
have a nice week,
Eric
Источник