- How To Unmount Disk in Linux, Ubuntu, CentOS with umount Command
- Before Unmount
- List Mounted File Systems
- Umount Specified Partition
- Unmount All Partitions
- Force To Unmount
- Verbose
- How to mount and umount a file system in Linux
- Unmount a File System
- Force Umount the file systems
- View Currently Mounted File Systems
- How to Mount and Unmount Filesystem / Partition in Linux (Mount/Umount Command Examples)
- 1. Mount a CD-ROM
- 2. View All Mounts
- 3. Mount all the filesystem mentioned in /etc/fstab
- 4. Mount only a specific filesystem from /etc/fstab
- 5. View all mounted partitions of specific type
- 6. Mount a Floppy Disk
- 7. Bind mount points to a new directory
- 8. Access contents from new mount point
- 9. Mount without writing entry into /etc/mtab
- 10. Mount filesystem with read or read/write access
- 11. Remount the mounted filesystem
- 12. Mount an iso image into a directory
- 13. Unmount more than one mount points
- 14. Lazy unmount of a filesystem
- 15. Forcefully unmount a filesystem
- If you enjoyed this article, you might also like..
How To Unmount Disk in Linux, Ubuntu, CentOS with umount Command
Linux distributions like Ubuntu, Debian, CentOS, RHEL, and others use disks by mounting them to the file system. We have already examined mount command in the following tutorial. In this tutorial we will learn how to umount the disk in a Linux system.
Before Unmount
Before unmount we should be sure that all changes are written to the file system and disk. So we need to close open files that reside in the file system we want to unmount.
umount command help information can be listed with —help like below. We can see some different help options in a brief way like unmount all filesystems, verbose etc.
List Mounted File Systems
Before unmounting filesystems and partitions we may need to list currently mounted filesystems and partitions.We can use the command mount in order to list currently mounted file systems and partitions with some information.
Alternatively lsblk command can be used already mounted file systems which provides more hierarchical list and eliminate unnecassary information.
Umount Specified Partition
We will start by unmounting specified partition. We can unmount just providing the partition path. In this example, we will unmount /dev/hda1 . We need root privileges in order to complete this job which is gained with the sudo command.
When the unmount is completed succesfully there will be no message about the process which simply sign the succesfull unmount. If there are some messages which are generally related with the error this means some error which prevents the unmount operation.
Unmount All Partitions
If we need to unmount all partitions of file systems currently mounted to the Linux system. We will use -a option which means all.
Force To Unmount
In some cases write operations can be resume for a long time and we need to unmount the file system. So we can force umount command with -f option like below. The following command will unmount the file system located in /dev/hda1 in a forceful way which may create some minor file system related errors in the next mount. Alternatively, the —force option can be used to force unmount. We can see the error like ” umount:/mnt devices is busy” error like below.
Alternatively we can list already opened file descriptor with the lsof command like below. We will just provide the mount path where the opened files will be list.
Verbose
If umount failed we can find detailed information about the reason. We can use -v option which will list detailed information while trying to unmount.
Источник
How to mount and umount a file system in Linux
A file system residing on a SATA/PATA or SCSI device needs to be mounted manually to access it. The mount command allows the root user to manually mount a file system. The first argument of the mount command specifies the file system to mount. The second argument specifies the target directory where the file system is made available after mounting it. The target directory is referred to as a mount point.
The general syntax for mounting a file system with mount is:
By using mount, you can override the default settings in /etc/fstab. For example, entering the following mounts the partition /dev/sdd1 to the directory /data:
You do not usually specify the file system type because it is recognized automatically (using magic numbers in the superblock, or simply by trying different file system types; see man mount for details).
The following are some of the options you can use when mounting a file system with the command mount or by entering them in /etc/fstab.
- remount. This option causes file systems that are already mounted to be mounted again. When you make a change to the options in /etc/fstab, you can use remount to incorporate the changes.
- rw, ro. These options indicate whether a file system should be writable (rw) or only readable (ro).
- sync, async. These options set synchronous (sync) or asynchronous (async) input and output in a file system. The default setting is async.
- atime, noatime. These options set whether the access time of a file is updated in the inode (atime) or not (noatime). The option noatime should improve the performance.
- nodev, dev. The nodev option prevents device files from being interpreted as such in the file system.
- noexec, exec. You can prohibit the execution of programs on a file system with the option noexec.
- nosuid, suid. The nosuid option ensures that the suid and sgid bits in the file system are ignored.
Some options only make sense in the file /etc/fstab. These options include the following:
- auto, noauto. File systems set with the option noauto in the file /etc/fstab are not mounted automatically when the system is booted.
- user, nouser. This option lets users mount the file system. Normally, this is a privilege of the user root.
- defaults. This option causes the default options rw, suid, dev, exec, auto, nouser, and async to be used.
The options noauto and user are usually combined for removable media such as floppy disk or CD-ROM drives.
Unmount a File System
Once a file system is mounted, you can use the umount command (without an “n”) to unmount the file system. You can unmount the file system by using umount with the device or the mount point.
For example to unmount a file system (dev/sdd1) mounted at /data, you could enter one of the following:
In order to unmount the file system, no application or user may use the file system. If it is being used, Linux sees the file system as being “busy” and will refuse to unmount the file system and will produce the below error.
Unmounting is not possible if the mount point is accessed by a process. For umount to be successful, the process needs to stop accessing the mount point.
The lsof command lists all open file and processes accessing them in the provided directory. It is useful to identify which processes currently prevent the file system from successful umounting.
You can also use the fuser command to get the process IDs of the processes currently running on the mpunt point you want to umount.
You can also kill all the processes on the mount point using the fuser command.
Once the processes are identified, an action can be taken, such as waiting for the process to complete or sending a SIGTERM or SIGKILL signal to the process. In this case, it is sufficient to umount the mount point.
Force Umount the file systems
There might be times when the system (kernel) sees the file system as busy, no matter what you try to do. In these cases, you can enter umount -f to force the file system to unmount. However, we recommend using this only as a last resort, as there is probably a reason why the kernel thinks the file system is still mounted.
View Currently Mounted File Systems
You can view the file systems currently mounted by entering the command mount. Information similar to the following appears:
You can also view this information in the file /proc/mounts.
Источник
How to Mount and Unmount Filesystem / Partition in Linux (Mount/Umount Command Examples)
Once you insert new hard disks into your system, you’ll typically use utilities like fdisk or parted to create partitions. Once you create a partition, you’ll use mkfs command to create ext2, ext3, or ext4 partition.
Once you create a partition, you should use mount command to mount the partition into a mount point (a directory), to start using the filesystem.
This tutorial explains everything you need to know about both mount and umount command with 15 practical examples.
The general mount command syntax to mount a device:
1. Mount a CD-ROM
The device file for CD would exist under /dev directory. For example, a CD-ROM device will be mounted as shown below.
In the above example, the option “-o ro” indicates that the cdrom should be mounted with read-only access. Also, make sure that the destination directory (in the above example, /mnt) exist before you execute the mount command.
2. View All Mounts
After you execute mount a partition or filesystem, execute the mount command without any arguments to view all the mounts.
In the example below, after mounting the USB drive on a system, the output of mount looks like the below. As seen below, the USB device (i.e:/dev/sdb) is mounted on /media/myusb, which is displayed as the last line in the mount command.
You can also use df command to view all the mount points.
3. Mount all the filesystem mentioned in /etc/fstab
The filesystems listed in /etc/fstab gets mounted during booting process. After booting, system administrator may unmount some of the partitions for various reasons. If you want all the filesystems to be mounted as specified in /etc/fstab, use -a option with mount as shown below:
Example /etc/fstab file entries:
Execute mount command with -a option to mount all the /etc/fstab entries.
The same -a option can be used with umount to unmount all the filesystems mentioned in /etc/mtab
Some filesystem are not unmounted as its busy or currently in use. Note that the files /etc/mtab and /proc/mounts contents would be similar.
4. Mount only a specific filesystem from /etc/fstab
When you pass only the directory name to mount, it looks for mount point entries, if not found, then search continuous for a device in /etc/fstab and gets mounted.
As seen above, /mydata directory is not a mountpoint, but it is present in /etc/fstab.
If you execute the same again, you would get the error message as follows:
Here you may also pass the device name instead of directory name (to be picked up from /etc/fstab file).
Note that the files /etc/mtab and /proc/mounts contents would be similar.
5. View all mounted partitions of specific type
It is possible to list only the specific type of filesystem mounted using the option -l with -t as shown below:
As seen above, /dev/sda6 is the only ext2 partition and /dev/sda5 is the only ext4 partition accordingly.
6. Mount a Floppy Disk
The device file for floppy disk would exist under /dev directory. For example, a floppy disk will be mounted as shown below.
After the successful mount, you would be able to access the contents of the floppy disk. Once you are done with it, use umount before you physically remove the floppy disk from the system.
7. Bind mount points to a new directory
The mountpoint can be binded to a new directory. So that you would be able to access the contents of a filesystem via more than one mountpoints at the same time.
Use -B option with olddir and newdir to be binded as follows,
Now the bind is done and you might verify it as follows,
As seen above the bind is done properly. So when you do modification in filesystem in one place, you can see those reflection of it in other mount point as shown below:
8. Access contents from new mount point
Mount allows you to access the contents of a mount point from a new mount point. Its nothing but move a mounted tree to another place.
In the example below, the mount point /mydata will be accessed from /mnt using the option -M as shown below:
Once its done, you cant use the old mount point as its moved to a new mount point and this can be verified as shown below:
9. Mount without writing entry into /etc/mtab
During read only mount of /etc/, the /etc/mtab file entries cannot be modified by mount command. However, mount can be done without writing into /etc/mtab by using the option -n as follows,
You cannot see any entry for this /mydata in mount command output and as well from /etc/mtab file as follows:
Access the contents of a mounted directory /mydata:
10. Mount filesystem with read or read/write access
To mount partition as read only, use -r option which is synonym to -o ro.
ext3 and ext4 filesystem would still allow you to do write operation when the filesystem is dirty. So, you may have to use “ro,noload” to prevent these kind of write operation.
To mount a partition with read/write access, use -w option which is same as “-o rw” (i.e : default).
11. Remount the mounted filesystem
In order to mount the already mounted filesystem, use remount option and its normally used to remount the filesystem with read/write access when its previously mounted with read access.
The /mydata mount point is going to be remounted with read/write access from read access as shown below:
12. Mount an iso image into a directory
The iso image can be mounted as shown below:
13. Unmount more than one mount points
Umount allows you to unmount more than mount point in a single execution of umount of command as follows:
14. Lazy unmount of a filesystem
This is a special option in umount, in case you want to unmount a partition after disk operations are done. You can issue command umount -l with that partition and the unmount will be done after the disk operations gets finished.
For instance, consider a scenario that a task (i.e: script or any other command) is doing a copy operation on a disk and at the same time you are allowed to issue a unmount with -l, so that unmount would be done once the copy is over (i.e: the disk operation).
15. Forcefully unmount a filesystem
umount provides the option to forcefully unmount a filesystem with option -f when the device is busy as shown below:
If this doesn’t work for you, then you can go for lazy unmount.
Meanwhile, you can also have a look at ps command output that which process is presently using the mountpoint as shown below:
You can also execute fuser command to find out which process is holding the directory for operations.
It gives you the process id with username (nothing but the owner of the process). If you know what that process is, you may want to stop that process and then try the umount again.
If you enjoyed this article, you might also like..
|
|
Thank you for this stuff….. But i have an another doubt is it possible to mount the NTFS filesystem in the system……………….?
Quote”after mounting the USB drive on a system”…….
Maybe you should tell us about HOW to mount an USB 🙂
At one time, the way I did it involved figuring-out which device in the hub it was attached to. I would plug the device in, wait 5 seconds then issue a dmsg command and filter it on SCSI devices (#dmsg | grep sd). Now, it is automatically mounted under /media/usb.
Thanks, very useful article
you can mount NTFS disks,
Use ntfs-3g for this
or mount -t ntfs /dev/foo /mnt/point
Usage: ntfs-3g [-o option[,…]]
Options: ro (read-only mount), remove_hiberfile, uid=, gid=,
umask=, fmask=, dmask=, streams_interface=, syncio.
Please see the details in the manual (type: man ntfs-3g).
Example: ntfs-3g /dev/sda1 /mnt/windows
Further Info: Ntfs-3g news, support and information: http://ntfs-3g.org
helpfull suggestion!
much thanks.
Hi, It was very good. Thanks a lot.
I am adding one thing which is missing is SAN share nfs & cifs volumes mounting.
# mount IPAddress:/vol/vol_nfs_01_10/qtree_01 /opt/myshare
SAN volume share given by SAN Team.
Install ntfs-3g pkg to mount NTFS FS.
Hope this thread is still active! I’ve setup Cygwin on a windows box for a subversion solution and trying to map SVN repository which is on a network share. I am able to do it by net use command but I need a permanent mount which works regardless of whether the server is being RDPed or otherwise.
I’ve update FSTAB with the following:
//NTSHARE/SVNREP /home/mnt user,rw,auto,errors=remount-ro 0 0
But it doesn’t seem to mount the share as I’d hoped. What am I missing? Any help on this would be greatly appreciated. Thanks.
Sir, I have a question regarding the mounting of the nfs ??
I had given the command
“wolf00:/mnt/wolf /mnt/wolf nfs rw,hard,intr 0 0”
will it work fine?becoz its not working in my system . I am currently trying to work on RHEL-4
Very useful..
Thanks.
Your all suggetions are really helpful ..
Keep This Good Work On…
Hello, I have a question. What command I need to mount the “var” folder on a magento install. Server is running on centOS.
I have a simple question that I am just missing. How can I tell what type a drive is to mount it. You use several examples above but there is not an explanation to fine the type. Any help would be greatly appreciated.
Thanks your article!
Your example is very useful to me!
Write the useful article like this for linux beginner!
Wish your help!
In Cent Os7, on booting, which script file is the first executed?
I want install C++ software in ubuntu 14.04, so can anyone help me?
Should this be an issue. Linux is still work in progress. I just need to access my drives and that’s all. why the hell should i go through all these troubles just to access my files on another drive?
I am running Trisquel GNU/Linux 7.0 Mini, booting from a USB flash drive. The files I want to access are on the hard drive of the laptop.
I think I am clear on this… I need to know the name of the file system on the hard drive and the type of extension in order to mount it and get at my files? I think this is right. It has to be, because Trisquel does not mount the file systems on the hard drive at bootup. It simply shows they exist by labeling them, “500 GB Volume”, and so on down the line. And when I try to mount them by clicking on them, Trisquel tells me that I do not have permission to mount these file systems, nor does it tell me the names or type of the file systems. I am sure I need to know what they are already. I do know what they are, but I do not want to try these mounting commands until I am clear on what I am doing. I don’t want to screw up any of my drives or files, don’t want to rename them, etc. I only want to leave them as they are, access them from Trisquel, and get to work on them.
Источник