19.3. 锁定重新分区

polkit 可让您为单个操作设置权限。对于磁盘管理服务工具 udisks2,配置位于 /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy。此文件包含一组操作和默认值,它们可被系统管理员覆盖。

重要

存储在 /etc 中的 polkit 配置会覆盖 /usr/share/ 中软件包所提供的配置。

流程

  1. 创建一个与 /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy 中内容相同的文件:

    cp /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy /etc/share/polkit-1/actions/org.freedesktop.udisks2.policy

    不要更改 /usr/share/polkit-1/actions/org.freedesktop.udisks2.policy 文件,您的更改会被下一次软件包更新所覆盖。

  2. 删除您不需要的操作,并将以下行添加到 /etc/polkit-1/actions/org.freedesktop.udisks2.policy 文件中:

    <action id="org.freedesktop.udisks2.modify-device">
      <message>Authentication is required to modify the disks settings</message>
         <defaults>
            <allow_any>no</allow_any>
            <allow_inactive>no</allow_inactive>
            <allow_active>yes</allow_active>
          </defaults>
     </action>

    如果要确保只有 root 用户才能执行此操作,请用 auth_admin 替换 no

  3. 保存更改。

当用户尝试更改磁盘设置时,会返回以下信息:

Authentication is required to modify the disks settings.