為什麼我的命令沒有將我的分割區重新掛載為唯讀?

為什麼我的命令沒有將我的分割區重新掛載為唯讀?

透過終端,我使用mount命令找到了我想要重新掛載為唯讀的磁碟分割區。我正在合作的具體對像是/dev/sdb2.

我嘗試使用此命令將磁碟重新安裝為唯讀,並期望將磁碟重新安裝為唯讀:

mount -o remount,r /dev/sdb2

沒有錯誤輸出。

但是,當我進入該磁碟時,我能夠在其上建立文件,這表明該磁碟未以唯讀方式掛載。為什麼會這樣呢?

答案1

-o在或 Mount Options的上下文中,r不等於「唯讀」;事實上,它根本不存在。你需要使用ro- 完整的命令變成這樣:mount -o remount,ro /dev/sdb2

唯一r作為選項存在的地方mount是作為參數,而不是掛載選項。


從線上說明頁開始mount,我為您提取了一些資訊部分。前面的評論#是我自己的,而不是來自線上幫助頁。

# 'mount' command arguments (NOT mount options, which are passed via `-o`!)

   -r, --read-only
          Mount the filesystem read-only. A synonym is -o ro.

   -o, --options opts
          Options are specified with a -o flag followed by a  comma  sepa‐
          rated string of options. For example:

                 mount LABEL=mydisk -o noatime,nouser


# FILESYSTEM INDEPENDENT MOUNT OPTIONS

   remount
          Attempt to remount an already-mounted filesystem.  This is  com‐
          monly  used  to  change  the mount flags for a filesystem, espe‐
          cially to make a  readonly  filesystem  writable.  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  com‐
          mand doesn't read fstab (or mtab) only when a device and dir are
          fully specified.

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

          After this call all old mount options are replaced and arbitrary
          stuff  from  fstab  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 (or  mtab)  and  merges  these
          options with options from command line ( -o ).

   ro     Mount the filesystem read-only.

   rw     Mount the filesystem read-write.

相關內容