Mount-Unmount-Remount (The GNU C Library) (2024)

Previous: Mount Information, Up: Controlling and Querying Mounts [Contents][Index]

31.3.2 Mount, Unmount, Remount

This section describes the functions for mounting, unmounting, andremounting filesystems.

Only the superuser can mount, unmount, or remount a filesystem.

These functions do not access the fstab and mtab files. Youshould maintain and use these separately. See Mount Information.

The symbols in this section are declared in sys/mount.h.

Function: int mount (const char *special_file, const char *dir, const char *fstype, unsigned long int options, const void *data)

Preliminary:| MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

mount mounts or remounts a filesystem. The two operations arequite different and are merged rather unnaturally into this one function.The MS_REMOUNT option, explained below, determines whethermount mounts or remounts.

For a mount, the filesystem on the block device represented by thedevice special file named special_file gets mounted over the mountpoint dir. This means that the directory dir (along with anyfiles in it) is no longer visible; in its place (and still with the namedir) is the root directory of the filesystem on the device.

As an exception, if the filesystem type (see below) is one which is notbased on a device (e.g. “proc”), mount instantiates afilesystem and mounts it over dir and ignores special_file.

For a remount, dir specifies the mount point where the filesystemto be remounted is (and remains) mounted and special_file isignored. Remounting a filesystem means changing the options that controloperations on the filesystem while it is mounted. It does not meanunmounting and mounting again.

For a mount, you must identify the type of the filesystem withfstype. This type tells the kernel how to access the filesystemand can be thought of as the name of a filesystem driver. Theacceptable values are system dependent. On a system with a Linux kerneland the proc filesystem, the list of possible values is in thefile filesystems in the proc filesystem (e.g. typecat /proc/filesystems to see the list). With a Linux kernel, thetypes of filesystems that mount can mount, and their type names,depends on what filesystem drivers are configured into the kernel orloaded as loadable kernel modules. An example of a common value forfstype is ext2.

For a remount, mount ignores fstype.

options specifies a variety of options that apply until thefilesystem is unmounted or remounted. The precise meaning of an optiondepends on the filesystem and with some filesystems, an option may haveno effect at all. Furthermore, for some filesystems, some of theseoptions (but never MS_RDONLY) can be overridden for individualfile accesses via ioctl.

options is a bit string with bit fields defined using thefollowing mask and masked value macros:

MS_MGC_MASK

This multibit field contains a magic number. If it does not have the valueMS_MGC_VAL, mount assumes all the following bits are zero andthe data argument is a null string, regardless of their actual values.

MS_REMOUNT

This bit on means to remount the filesystem. Off means to mount it.

MS_RDONLY

This bit on specifies that no writing to the filesystem shall be allowedwhile it is mounted. This cannot be overridden by ioctl. Thisoption is available on nearly all filesystems.

MS_NOSUID

This bit on specifies that Setuid and Setgid permissions on files in thefilesystem shall be ignored while it is mounted.

MS_NOEXEC

This bit on specifies that no files in the filesystem shall be executedwhile the filesystem is mounted.

MS_NODEV

This bit on specifies that no device special files in the filesystemshall be accessible while the filesystem is mounted.

MS_SYNCHRONOUS

This bit on specifies that all writes to the filesystem while it ismounted shall be synchronous; i.e., data shall be synced before eachwrite completes rather than held in the buffer cache.

MS_MANDLOCK

This bit on specifies that mandatory locks on files shall be permitted whilethe filesystem is mounted.

MS_NOATIME

This bit on specifies that access times of files shall not be updated whenthe files are accessed while the filesystem is mounted.

MS_NODIRATIME

This bit on specifies that access times of directories shall not be updatedwhen the directories are accessed while the filesystem in mounted.

Any bits not covered by the above masks should be set off; otherwise,results are undefined.

The meaning of data depends on the filesystem type and is controlledentirely by the filesystem driver in the kernel.

Example:

#include <sys/mount.h>mount("/dev/hdb", "/cdrom", "iso9660", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, "");mount("/dev/hda2", "/mnt", "", MS_MGC_VAL | MS_REMOUNT, "");

Appropriate arguments for mount are conventionally recorded inthe fstab table. See Mount Information.

The return value is zero if the mount or remount is successful. Otherwise,it is -1 and errno is set appropriately. The values oferrno are filesystem dependent, but here is a general list:

EPERM

The process is not superuser.

ENODEV

The file system type fstype is not known to the kernel.

ENOTBLK

The file dev is not a block device special file.

EBUSY
  • The device is already mounted.
  • The mount point is busy. (E.g. it is some process’ working directory orhas a filesystem mounted on it already).
  • The request is to remount read-only, but there are files open for writing.
EINVAL
  • A remount was attempted, but there is no filesystem mounted over thespecified mount point.
  • The supposed filesystem has an invalid superblock.
EACCES
  • The filesystem is inherently read-only (possibly due to a switch on thedevice) and the process attempted to mount it read/write (by setting theMS_RDONLY bit off).
  • special_file or dir is not accessible due to file permissions.
  • special_file is not accessible because it is in a filesystem that ismounted with the MS_NODEV option.
EM_FILE

The table of dummy devices is full. mount needs to create adummy device (aka “unnamed” device) if the filesystem being mounted isnot one that uses a device.

Function: int umount2 (const char *file, int flags)

Preliminary:| MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

umount2 unmounts a filesystem.

You can identify the filesystem to unmount either by the device specialfile that contains the filesystem or by the mount point. The effect isthe same. Specify either as the string file.

flags contains the one-bit field identified by the followingmask macro:

MNT_FORCE

This bit on means to force the unmounting even if the filesystem isbusy, by making it unbusy first. If the bit is off and the filesystem isbusy, umount2 fails with errno = EBUSY. Dependingon the filesystem, this may override all, some, or no busy conditions.

All other bits in flags should be set to zero; otherwise, the resultis undefined.

Example:

#include <sys/mount.h>umount2("/mnt", MNT_FORCE);umount2("/dev/hdd1", 0);

After the filesystem is unmounted, the directory that was the mount pointis visible, as are any files in it.

As part of unmounting, umount2 syncs the filesystem.

If the unmounting is successful, the return value is zero. Otherwise, itis -1 and errno is set accordingly:

EPERM

The process is not superuser.

EBUSY

The filesystem cannot be unmounted because it is busy. E.g. it containsa directory that is some process’s working directory or a file that someprocess has open. With some filesystems in some cases, you can avoidthis failure with the MNT_FORCE option.

EINVAL

file validly refers to a file, but that file is neither a mountpoint nor a device special file of a currently mounted filesystem.

This function is not available on all systems.

Function: int umount (const char *file)

Preliminary:| MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.

umount does the same thing as umount2 with flags setto zeroes. It is more widely available than umount2 but since itlacks the possibility to forcefully unmount a filesystem is deprecatedwhen umount2 is also available.

Mount-Unmount-Remount (The GNU C Library) (2024)

FAQs

What does mount o remount do? ›

1 Answer. Mounting or remounting a filesystem is done using the mount(2) syscall. When remounting, this takes the target location (the mountpoint), the flags to be used in the mount operation, and any extra data used for the specific filesystem involved.

How do I unmount and remount in Linux? ›

Mounting and unmounting media using Linux
  1. Type cd and then press Enter.
  2. Type one of the following commands: If the medium to be unmounted is a CD, type umount /mnt/cdrom. and then press Enter. If the medium to be unmounted is a diskette, type umount /mnt/floppy. and then press Enter.

What is the difference between mount and unmount in Linux? ›

mount command is used to mount the filesystem found on a device to big tree structure(Linux filesystem) rooted at '/'. Conversely, another command umount can be used to detach these devices from the Tree.

Which mount option will remount a currently mounted filesystem? ›

The remount option attempt to remount an already-mounted filesystem. This is commonly used to change the mount flags for a filesystem, especially to make a readonly filesystem writeable.

How do I unmount and remount a drive? ›

Do the following:
  1. Press the Windows key + R to open the Run menu.
  2. Type diskmgmt. msc and press Enter.
  3. Right-click the drive.
  4. Click Change Drive Letter and Paths.
  5. Click Remove.
  6. Click Yes.
  7. Close Disk Management.
Jul 26, 2024

What are the 2 types of mounting? ›

There are two main types of mounting media: water-based and solvent-based.

What does unmount command do? ›

The umount command unmounts a previously mounted device, directory, file, or file system. Processing on the file system, directory, or file completes and it is unmounted.

What is Remounting in Linux? ›

Remounting a filesystem means changing the options that control operations on the filesystem while it is mounted. It does not mean unmounting and mounting again.

How to mount a disk in Linux permanently? ›

Mount the drive permanently (optional).
  1. Open /etc/fstab in a text editor like Vim or Nano.
  2. Add a line to the file using this syntax: /dev/sdc1 /media/myflashdrive ext4 defaults 0 0. Replace "ext4" with the file system type you found with lsblk -lf earlier. Save and exit the file.
Jul 31, 2024

What does mounting and unmounting do? ›

Mounted parts are assembled, while unmounted are separated from any machine or installation. When talking about mounted or unmounted parts, we refer to whether they're assembled to the machine they belong to (mounted) when the part search takes place.

What is the purpose of mount in Linux? ›

The "mount" command in Linux is used to attach and make accessible external storage devices, network shares, and other file systems to the operating system. It is essential for integrating additional storage, ensuring data accessibility, and expanding storage capacity.

What happens if you unmount a partition Linux? ›

Unmounting a disk in Linux is necessary to safely remove removable devices or to perform maintenance on the disk without the risk of data loss. When a disk is unmounted, the operating system releases all resources associated with that disk, such as file structures, cache buffers, and file descriptors.

What is the default mount option in Linux? ›

By default, the mount command comes with the defaults option. The defaults option specifies the following default mount options: rw , atime , suid , dev , exec , async , auto , nouser , delalloc , data=ordered , barrier , and nodiscard . You do not need to specify additional mount options.

How to unmount in Linux terminal? ›

To unmount a file system in Linux, you use the 'umount' command followed by the directory where it has been mounted. The basic syntax would be, umount /path/to/file_system . In this example, we've used the 'umount' command to unmount the file system that was previously mounted at the directory '/mnt/my_usb'.

How to remount from fstab? ›

Remount all filesystems in fstab with command mount -o remount -a. Should re-mount with the changed mount-options of your fstab.

What does mounting a device do? ›

Mounting is a process by which a computer's operating system makes files and directories on a storage device (such as hard drive, CD-ROM, or network share) available for users to access via the computer's file system.

What does mounting do under the hood? ›

The engine mounts keep the engine aligned and positioned in the vehicle hood compartment. It also stabilizes the movement of the engine. So a broken or damaged mount can cause an engine to be out of alignment and create unwanted glitches in the entire engine operation.

What does a mounting bracket do? ›

A bracket is any type of support hardware, usually metal and attached to a wall, used to hold, attach, mount, or secure. This makes bracket hardware especially useful in awning and shade applications. Hardware brackets can be used for home or commercial use.

What does a rear transmission mount do? ›

The transmission mount is designed to hold the transmission in place, to keep it from jostling or moving around when you accelerate. If the transmission mount is bad, you'll hear a banging noise as the transmission bangs against the mount, and the bad mount will place stress on other components.

Top Articles
AXSUSDT Charts and Quotes — TradingView
Top 100 Goals for Your Vision Board: Money and Finance
Davita Internet
Ffxiv Palm Chippings
Research Tome Neltharus
Valley Fair Tickets Costco
Mohawkind Docagent
Emmalangevin Fanhouse Leak
Mndot Road Closures
Erskine Plus Portal
13 The Musical Common Sense Media
World Cup Soccer Wiki
Craigslist Heavy Equipment Knoxville Tennessee
Edible Arrangements Keller
Slag bij Plataeae tussen de Grieken en de Perzen
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Love In The Air Ep 9 Eng Sub Dailymotion
Leader Times Obituaries Liberal Ks
Committees Of Correspondence | Encyclopedia.com
Huntersville Town Billboards
Timeforce Choctaw
Ford F-350 Models Trim Levels and Packages
Routing Number For Radiant Credit Union
Bn9 Weather Radar
City Of Durham Recycling Schedule
Urbfsdreamgirl
Truvy Back Office Login
Table To Formula Calculator
Sandals Travel Agent Login
Orange Park Dog Racing Results
Neteller Kasiinod
Maths Open Ref
DIY Building Plans for a Picnic Table
Have you seen this child? Caroline Victoria Teague
Steven Batash Md Pc Photos
Tamil Play.com
Atlantic Broadband Email Login Pronto
Spinning Gold Showtimes Near Emagine Birch Run
Oreillys Federal And Evans
Asian Grocery Williamsburg Va
Afspraak inzien
Directions To 401 East Chestnut Street Louisville Kentucky
Academic important dates - University of Victoria
Gpa Calculator Georgia Tech
Housing Intranet Unt
T&Cs | Hollywood Bowl
St Vrain Schoology
Online College Scholarships | Strayer University
Nurses May Be Entitled to Overtime Despite Yearly Salary
Understanding & Applying Carroll's Pyramid of Corporate Social Responsibility
Unpleasant Realities Nyt
Tyrone Unblocked Games Bitlife
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6083

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.