1

I have created a new filesystem and mounted it :

mount /dev/sda5 /dir

Then I added the information about it to the /etc/fstab file so that the filesystem is always mounted at the boot process.

vim /etc/fstab

After saving the /etc/fstab file I've seen it is recommended to do :

mount -a

or

mount -o remount /dir

What are the differences between these commands and which one should I use after modifying the /etc/fstab file ?

2

man mount says:

   -a, --all
          Mount all filesystems (of the given types) mentioned in fstab (except for those whose line contains the noauto keyword).  The filesystems are
          mounted following their order in fstab.

and

   remount
          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 writable.  It does not change device or mount point.

          The  remount  functionality follows the standard way the mount command works with options from fstab.  This means that the mount command only
          doesn't read fstab (or mtab) when both the device and dir are specified.

          mount -o remount,rw /dev/foo /dir

          After this call all old mount options are replaced and arbitrary stuff from fstab (or mtab) is ignored, except  the  loop=  option  which  is
          internally generated and maintained by the mount command.

          mount -o remount,rw  /dir

          After  this call mount reads fstab and merges these options with the options from the command line (-o). If no mountpoint found in fstab than
          remount with unspecified source is allowed.

So, that is the difference.

Now what should you use after modifying /etc/fstab? Well, that depends. If you have a number of filesystems in /etc/fstab that are unmounted, mount -a will mount them all. That may not be what you want, but it may also be exactly what you want.

if /dir is not yet mounted, you could simply mount /dir, which will leave the rest of the filesystems mentioned in /etc/fstab alone.

| improve this answer | |
2

Taken from MAN page:

All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount command will detach it again.

moun-a(usually given in a bootscript) causes all filesystems mentioned in fstab (of the proper type and/or having or not having the proper options) to be mounted as indicated, except for those whose line contains the noauto keyword. Adding the -F option will make mount fork, so that the filesystems are mounted simultaneously. When mounting a filesystem mentioned in fstab or mtab, it suffices to give only the device, or only the mount point.

In the case of mount -o remount /dir, the full set of mount options used by an invocation of mount is determined by first extracting the mount options for the filesystem from the fstab table, then applying any options specified by the -o argument, and finally applying a -r or -w option, when present. Some of these options are only useful when they appear in the /etc/fstab file and some of these options could be enabled or disabled by default in the system kernel. To check the current setting see the options in /proc/mounts.

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. It does not change device or mount point.

The remount functionality follows the standard way how the mount command works with options from fstab. It means the mount command doesn't read fstab (or mtab) only when a device and dir are fully specified.

So, according to the MAN page the difference between them lies on reading fstab file, after modifying and if you want to mount them all you should use mount -a otherwise if you just want to mount a dir you should use the other option.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.