【学习笔记】Linux GDM

GDM

From GDM - GNOME Display Manager: "The GNOME Display Manager (GDM)是管理图形显示服务器并处理图形用户登录的程序."

显示管理器为X Window System和Wayland用户提供图形化登录提示.

目录

Installation


GDM可以与gdm软件包一起安装,并且作为gnome的一部分安装。

如果您希望使用GNOME 2中使用的旧版GDM,并拥有自己的配置实用程序,请安装gdm-oldAUR软件包。 请注意,除非另有说明,否则本文的其余部分将讨论当前的GDM,而不是旧版GDM。

您可能还希望安装以下内容:

Starting

To start GDM at boot time enable gdm.service.

自启动程序

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png
Reason: this works only with X desktop environments (Discuss in Talk:GDM#GDM with wayland does not use xprofile for autostarting)
One might want to autostart certain commands, such as xrandr for instance, on login. This can be achieved by adding a command or script to a location that is sourced by the display manager. See Display manager#Autostarting for a list of supported locations.

Note: The /etc/gdm/Init directory is no longer a supported location, see [1].

配置

登录屏幕背景图片

The factual accuracy of this article or section is disputed.

Reason: Configuration is not persistent and will be gone after gdm update. Needs to be rewritten to enable user-themes gnome-shell extension for gdm user and use custom theme and set gsetting to use that theme (Discuss in Talk:GDM#)
Note:

  • Since GNOME 3.16, GNOME Shell themes are now stored as binary files (gresource).
  • This change will be overwritten on subsequent updates of gnome-shell.
    首先,您需要将现有的GNOME Shell主题提取到主目录中的文件夹中。 您可以使用以下脚本执行此操作:
extractgst.sh
-----------------
#!/bin/sh
gst=/usr/share/gnome-shell/gnome-shell-theme.gresource
workdir=${HOME}/shell-theme

for r in `gresource list $gst`; do
	r=${r#\/org\/gnome\/shell/}
	if [ ! -d $workdir/${r%/*} ]; then
	  mkdir -p $workdir/${r%/*}
	fi
done

for r in `gresource list $gst`; do
        gresource extract $gst $r >$workdir/${r#\/org\/gnome\/shell/}
done

导航到创建的目录。 您应该发现主题文件已被提取到其中。 现在,将您喜欢的背景图像复制到该目录。

接下来,您需要在目录中创建一个包含以下内容的文件:

gnome-shell-theme.gresource.xml
--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/org/gnome/shell/theme">
    <file>calendar-today.svg</file>
    <file>checkbox-focused.svg</file>
    <file>checkbox-off-focused.svg</file>
    <file>checkbox-off.svg</file>
    <file>checkbox.svg</file>
    <file>dash-placeholder.svg</file>
    <file>gnome-shell.css</file>
    <file>gnome-shell-high-contrast.css</file>
    <file>icons/scalable/status/eye-not-looking-symbolic.svg</file>
    <file>icons/scalable/status/eye-open-negative-filled-symbolic.svg</file>
    <file>icons/scalable/status/message-indicator-symbolic.svg</file>
    <file>icons/scalable/status/keyboard-enter-symbolic.svg</file>
    <file>icons/scalable/status/keyboard-hide-symbolic.svg</file>
    <file>icons/scalable/status/keyboard-layout-filled-symbolic.svg</file>
    <file>icons/scalable/status/keyboard-shift-filled-symbolic.svg</file>
    <file>icons/scalable/status/keyboard-caps-lock-filled-symbolic.svg</file>
    <file>icons/scalable/actions/color-pick.svg</file>
    <file>icons/scalable/actions/pointer-double-click-symbolic.svg</file>
    <file>icons/scalable/actions/pointer-drag-symbolic.svg</file>
    <file>icons/scalable/actions/pointer-primary-click-symbolic.svg</file>
    <file>icons/scalable/actions/pointer-secondary-click-symbolic.svg</file>
    <file>filename</file>
    <file>no-events.svg</file>
    <file>no-notifications.svg</file>
    <file>pad-osd.css</file>
    <file>process-working.svg</file>
    <file>toggle-off-dark.svg</file>
    <file>toggle-off-hc.svg</file>
    <file>toggle-off.svg</file>
    <file>toggle-on-dark.svg</file>
    <file>toggle-on-hc.svg</file>
    <file>toggle-on.svg</file>
  </gresource>
</gresources>

将文件名替换为背景图像的文件名,或删除该行以使用十六进制颜色值代替。

现在,打开目录中的gnome-shell.css文件,并如下更改#lockDialogGroup定义:

#lockDialogGroup {
  background: url(filename);
  background-size: [WIDTH]px [HEIGHT]px;
  background-repeat: no-repeat;
}

background-size 设置为GDM使用的分辨率,这不一定是图像的分辨率。 有关显示分辨率的列表,请参阅显示分辨率。 同样,将filename设置为背景图像的名称。

如果只想更改背景颜色,请按如下所示调整#lockDialogGroup的定义:

#lockDialogGroup {
  background-color: #[COLOR];
}

其中[COLOR]是新的十六进制编码的背景色。

最后,使用以下命令编译主题:

$ glib-compile-resources gnome-shell-theme.gresource.xml

然后将生成的 gnome-shell-theme.gresource 文件复制到 /usr/share/gnome-shell 文件夹.

然后重新启动gdm.service(请注意,仅注销是不够的),您应该发现它正在使用您喜欢的背景图像。

有关更多信息,请参见以下论坛主题DimaZirix的github 中提供了可自动执行上述步骤的shell脚本。

DConf 配置

一些GDM设置存储在DConf数据库中。. They can be configured either by adding keyfiles to the /etc/dconf/db/gdm.d directory 然后以root身份运行dconf update或登录系统上的GDM用户并使用gsettings命令行工具直接更改设置来重新编译GDM数据库。

Note that for the former approach, a GDM profile file is required - this must be created manually as it is no longer shipped upstream, see below:

/etc/dconf/profile/gdm
----------------------------
user-db:user
system-db:gdm
file-db:/usr/share/gdm/greeter-dconf-defaults

对于后一种方法,您可以使用以下命令登录GDM用户:

# machinectl shell gdm@ /bin/bash

创建以下关键文件

/etc/dconf/db/gdm.d/02-logo
------------------------------
[org/gnome/login-screen]
logo='/path/to/logo.png'

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.login-screen logo '/path/to/logo.png'

更改光标主题

GDM忽略GNOME光标主题设置,并且也忽略了根据XDG规范的光标主题设置。 要更改GDM中使用的光标主题,请创建以下关键文件

/etc/dconf/db/gdm.d/10-cursor-settings
-------------------------------
[org/gnome/desktop/interface]
cursor-theme='theme-name'

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.desktop.interface cursor-theme 'theme-name'

较大字体的登录屏幕

单击屏幕右上角的辅助功能图标(白色圆圈,中间是一个人的轮廓),然后选中“大文本”选项。

要设置特定的缩放比例,可以创建以下文件:

/etc/dconf/db/gdm.d/03-scaling
----------------------------------
[org/gnome/desktop/interface]
text-scaling-factor='1.25'

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.desktop.interface text-scaling-factor '1.25'

关闭声音

此调整将禁用在登录屏幕上调整系统音量(通过键盘)时听到的声音反馈。

创建如下文件:

/etc/dconf/db/gdm.d/04-sound
-------------------------------
[org/gnome/desktop/sound]
event-sounds=false

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.desktop.sound event-sounds 'false'

配置电源按钮行为

Note:

  • The logind settings for the power button are overriden by GNOME Settings Daemon. [2]
  • As of GDM 3.18, the power button cannot be set to interactive. [3]
  • In some cases, this setting will be ignored and hardcoded defaults will be used. [4]
    Warning: Please note that the acpid daemon also handles the "power button" and "hibernate button" events. Running both systems at the same time may lead to unexpected behaviour.
    创建以下 文件:
/etc/dconf/db/gdm.d/05-power
----------------------------------
[org/gnome/settings-daemon/plugins/power]
power-button-action='action'

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.settings-daemon.plugins.power power-button-action 'action'

where action can be one of nothing, suspend or hibernate.

Enabling tap-to-click

默认情况下,GDM(和GNOME)中禁用了点按单击,但是您可以使用dconf设置轻松启用它。

Note: If you want to do this under X, you have to first set up correct X server access permissions - see #Configure X server access permission.
To enable tap-to-click, either create the following keyfile:

/etc/dconf/db/gdm.d/06-tap-to-click
-------------------------------------
[org/gnome/desktop/peripherals/touchpad]
tap-to-click=true

and then recompile the GDM database or alternatively log in to the GDM user and execute the following:

$ gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click 'true'

禁用/启用辅助功能菜单

要禁用或启用“辅助功能菜单”,请创建以下 文件:

/etc/dconf/db/gdm.d/07-accessibility
----------------------------------
[org/gnome/desktop/interface]
toolkit-accessibility='boolean'

然后重新编译GDM数据库,或者登录到GDM用户并执行以下操作:

$ gsettings set org.gnome.desktop.interface toolkit-accessibility 'boolean'

The menu is disabled when the key is false, enabled when it is true.

在GDM上启用夜间模式

要在GDM上启用夜间模式,请运行

$ sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true

Keyboard layout

系统键盘布局将应用于GDM. See Keyboard configuration in Xorg#Using X configuration files.

Tip: See Wikipedia:ISO 3166-1 for a list of keymaps.
If a system has multiple users, it is possible to specify a keyboard layout for GDM to use which is different from the system keyboard layout. Firstly, ensure the package gnome-control-center is installed. Then start gnome-control-center and navigate to Region & Language -> Input Sources. In the header bar, hit the Login Screen toggle button and then choose a keyboard layout from the list. Note that the Login Screen button will not be visible in the header bar unless multiple users are present on the system [5].

Users of GDM 2.x (legacy GDM) may need to edit ~/.dmrc as shown below:

~/.dmrc
-----------------------------
[Desktop]
Language=de_DE.UTF-8   # change to your default lang
Layout=de   nodeadkeys # change to your keyboard layout

修改语言

The system language will be applied to GDM. If a system has multiple users, it is possible to set a language for GDM different to the system language. In this case, firstly ensure that gnome-control-center is installed. Then, start gnome-control-center and choose Region & Language. In the header bar, check the Login Screen toggle button. Finally, click on Language and choose your language from the list. You will be prompted for your root password. Note that the Login Screen button will not be visible in the header bar unless multiple users are present on the system [6].

Tip: By adding 2 different input languages, logging out then selecting your default language GDM will remember your choice once the second option is removed.

用户和登录

自动登录

要启用GDM自动登录,请将以下内容添加到/etc/gdm/custom.conf中(用您自己的用户名替换):

/etc/gdm/custom.conf
-----------------------------------
# Enable automatic login for user
[daemon]
AutomaticLogin=username
AutomaticLoginEnable=True

Tip: 如果添加这些行后GDM失败,请从TTY中将其注释掉。.
或延迟自动登录:

/etc/gdm/custom.conf
-------------------------------
[daemon]

TimedLoginEnable=true
TimedLogin=username
TimedLoginDelay=1

您可以设置用于自动登录的会话 (replace gnome-xorg with desired session):

/var/lib/AccountsService/users/username
-------------------------------------
XSession=gnome-xorg

无密码登录

如果您想绕过GDM中的密码提示,则只需将以下行添加到 /etc/pam.d/gdm-password:

auth sufficient pam_succeed_if.so user ingroup nopasswdlogin

然后,将nopasswdlogin组添加到您的系统。 See User group for group descriptions and group management commands.

现在,将您的用户添加到nopasswdlogin组,您只需单击用户名即可登录。

`Warning:

  • 不要对root帐户执行此操作。
  • You won't be able to change your session type at login with GDM anymore. If you want to change your default session type, you will first need to remove your user from the nopasswdlogin group.`

多个会话的无密码关机

GDM uses polkit and logind to gain permissions for shutdown. You can shutdown the system when multiple users are logged in by setting:

/etc/polkit-1/localauthority.conf.d/org.freedesktop.logind.policy
--------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">


<policyconfig>

  <action id="org.freedesktop.login1.power-off-multiple-sessions">
    <description>Shutdown the system when multiple users are logged in</description>
    <message>System policy prevents shutting down the system when other users are logged in</message>
    <defaults>
      <allow_inactive>yes</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

</policyconfig>

You can find all available logind options (e.g. reboot-multiple-sessions) here.

在GDM中启用root登录

不建议以root用户身份登录,但如有必要,您可以进行编辑 /etc/pam.d/gdm-password并在该行之前添加以下行 auth required pam_deny.so:

/etc/pam.d/gdm-password

auth            sufficient      pam_succeed_if.so uid eq 0 quiet

文件应如下所示:

/etc/pam.d/gdm-password

...
auth            sufficient      pam_succeed_if.so uid eq 0 quiet
auth            sufficient      pam_succeed_if.so uid >= 1000 quiet
auth            required        pam_deny.so
...

You should be able to login as root after restarting GDM.

从登录列表中隐藏用户

The users for the gdm user list are gathered by AccountsService. It will automatically hide system users (UID < 1000). To hide ordinary users from the login list create or edit a file named after the user to hide in /var/lib/AccountsService/users/ to contain at least:

/var/lib/AccountsService/users/username
---------------------------------------
[User]
SystemAccount=true

设置默认显示器设置

一些桌面环境将显示设置存储在 ~/.config/monitors.xml. xrandr commands are then generated on the base of the file content. GDM has a similar file stored in /var/lib/gdm/.config/monitors.xml.

If you have your monitors setup as you like (resolution, refresh rate, orientation, scaling, primary and so on) in ~/.config/monitors.xml and want GDM to honor those settings:

# cp ~/.config/monitors.xml /var/lib/gdm/.config/
# chown gdm:gdm /var/lib/gdm/.config/monitors.xml

The relevant parts of monitors.xml for screen rotation and scaling are:

<monitors version="2">
  <configuration>
    <logicalmonitor>
      ...
      <scale>2</scale>
      ...
      <transform>
        <rotation>right</rotation>
        <flipped>no</flipped>
      </transform>
      ...
    </logicalmonitor>
  </configuration>
</monitors>

Changes will take effect on logout. This is necessary because GDM does not respect xorg.conf.

Note: If you use GDM under Wayland, you must also use a monitors.xml that was created under Wayland. See GDM bug 224 for more info. Alternatively, you can force GDM to #Use Xorg backend, and use a monitors.xml that was created under Xorg.
Note: If you use fractional scaling, you need to enable it for user gdm.

配置X server 访问权限

You can use the xhost command to configure X server access permissions.

For instance, to grant GDM the right to access the X server, use the following command:

# xhost +SI:localuser:gdm

故障排除

Wayland和专有的NVIDIA驱动程序

GDM doesn't work well in Wayland mode with the proprietary NVIDIA driver. When using this driver, GDM will use Xorg instead.[7]

To force-enable Wayland, disable the udev rule responsible for disabling Wayland in GDM:

# ln -s /dev/null /etc/udev/rules.d/61-gdm.rules

登出失败

If GDM starts up properly on boot, but fails after repeated attempts on logout, try adding this line to the daemon section of /etc/gdm/custom.conf:

GdmXserverTimeout=60

Rootless Xorg

See Xorg#Rootless Xorg.

Use Xorg backend

The Wayland backend is used by default, and the Xorg backend is used only if the Wayland backend cannot be started. You may wish to use the Xorg backend instead if, for example:

The screen flickers
GDM crashes
To use the Xorg backend by default, uncomment the following line in /etc/gdm/custom.conf:

#WaylandEnable=false

GDM显示黑屏,白色光标闪烁

引导后,GDM可能会为您显示黑屏,并且左上方的白色光标闪烁。 这可能是由于GDM在完全初始化图形驱动程序之前启动而引起的。 一种可能的解决方法是尽早启动KMS。 另一个可能的解决方法是编辑systemd服务,并将其类型设置为“ idle”或添加一个小的延迟:

 [Service]
 Type=idle

or

 [Service]
 ExecStartPre=/bin/sleep 2

If a longer delay is required, increase the delay time.

GDM没有启动,直到有输入

如果在引导后屏幕保持黑色,并且直到移动鼠标或在键盘上键入内容后GDM才启动,则可能是由于缺少生成随机数所需的熵。 要确认,请检查以下行是否出现在systemd-random-seed的日志中(可以使用读取 journalctl --unit systemd-random-seed):

Kernel entropy pool is not initialized yet, waiting until it is.

为了解决这个问题,如果您的CPU支持RDRAND指令,则可以传递random.trust_cpu = on内核参数,或者您也可以使用hadged来提供熵,尽管它的质量很低。 有关其他解决方案,请参见有关该主题的Debian文章。

gdm删除不完全

删除gdm之后,systemd可能会报告以下内容:

user 'gdm': directory '/var/lib/gdm' does not exist

要删除此警告,请以root用户身份登录并删除主要用户gdm,然后删除组gdm

# userdel gdm
# groupdel gdm

Verify that gdm is successfully removed via pwck and grpck. To round it off, you may want to double-check no unowned files for gdm remain.

GDM自动暂停(GNOME 3.28)

GDM uses a separate dconf database to control power management. To apply your user's power settings, copy them to GDM's dconf database:

$ IFS=$'\n'; for x in $(sudo -u username gsettings list-recursively org.gnome.settings-daemon.plugins.power); do eval "sudo -u gdm dbus-launch gsettings set $x"; done; unset IFS

where username is your username.

To only disable auto-suspend on AC, run:

$ sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'

(To also disable auto-suspend on battery, run the command with battery instead of ac.)

Restart GDM to activate your changes.

GDM默认使用X.Org忽略Wayland

Wayland requires Kernel Mode Setting (KMS) running in order to work, and on some machines the GDM process start earlier than KMS, resulting in GDM unable to see Wayland and working only with X.Org. This might result in messages like the following showing up in your log:

gnome-shell[569]: Failed to open gpu '/dev/dri/card0': GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Operation not permitted
gnome-shell[569]: Failed to create backend: No GPUs found
systemd[505]: gnome-shell-wayland.service: Failed with result 'protocol'.
systemd[505]: Failed to start GNOME Shell on Wayland.

Alternatively, the same issue may lead to GDM not appearing or monitor only displaying the TTY output.

You can solve this problem by starting KMS earlier.

Also, if you use a NVIDIA driver, the Wayland session might be blocked by a udev rule (see the notes under GNOME#Wayland sessions). This might result in messages like the following:

systemd[1022]: Condition check resulted in GNOME Shell on Wayland being skipped.
systemd[1022]: org.gnome.Shell@wayland.service: Skipped due to 'exec-condition'.
systemd[1022]: org.gnome.Shell@wayland.service: Control process exited, code=exited, status=2/INVALIDARGUMENT

In this case, you might see lines like this in /usr/lib/udev/rules.d/61-gdm.rules:

# disable Wayland when using the proprietary nvidia driver
DRIVER=="nvidia", RUN+="/usr/lib/gdm-disable-wayland"

To let GDM use Wayland, copy 61-gdm.rules from /usr/lib/udev/rules.d/ to /etc/udev/rules.d/ (where the latter file will override the former) and comment out the related line:

# DRIVER=="nvidia", RUN+="/usr/lib/gdm-disable-wayland"

装有NVidia(e)GPU的AMD或Intel GPU上出现黑屏

At first, without an NVidia device, GDM starts and works normally on Wayland, but stops working once an NVidia eGPU is plugged in (or the nvidia module is loaded for other reasons). A typical symptom of the problem is a black screen with a blinking cursor upon logouts and GDM restarts and the following message in GDM's logs (journalctl -u gdm -b):

Gdm: Child process -<some PID> was already dead.

The solution is the same as above: Prevent /usr/lib/gdm-disable-wayland from running upon nvidia module loading.

Notice that GDM on Wayland will no longer work once /usr/lib/gdm-disable-wayland has run. This is because WaylandEnable=false has been written into /run/gdm/custom.conf, which overrides /etc/gdm/custom.conf. To fix the situation without a reboot, remove /run/gdm/custom.conf and then restart GDM.

posted @ 2021-04-24 11:14  dozeoo  阅读(2624)  评论(0编辑  收藏  举报