Linux在睡眠(or休眠)唤醒之后触摸板失灵的解决方法

ChenHacker

2020-02-08 21:31:51

Personal

在我的笔记本上,所有的linux发行版都存在一个bug:睡眠(or休眠)唤醒之后触摸板失灵 ### 注:此篇blog是互联网上第一个提到该解决方法的一篇blog,本机为Arch linux linux界很久以前就有这样一个问题,arch wiki上给的方法是禁用休眠,这固然可以解决,但是不能根治,这个问题已经困扰了我半年之久,今天摸爬滚打终于解决了!! ## 问题原因: linux的触摸板驱动是启动内核是作为一个模块加载的,睡眠的时候可能由于linux内核的bug这个模块坏掉了,所以需要重新加载,而我们知道linux系统中重新加载内核模块的方法是: ```bash sudo modprobe -r *** #移除模块 sudo modprobe *** #加载模块 ``` 经过我几个小时的摸索,得知我的笔记本触摸板驱动的模块是i2c_hid(部分笔记本是psmouse) 所以当唤醒睡眠之后执行一下命令我的触摸板就可以工作了 ```bash sudo modprobe -r i2c_hid && sudo modprobe i2c_mid ``` 但是每次睡眠之后都要打开终端执行这个命令,在Linux下怎么可以这么繁琐???? 所以我们通过修改/usr/lib/systemd/system/systemd-suspend.service文件来解决 这个文件是有关休眠服务的文件,也就是当你按下睡眠键时,系统就会执行这个文件 我们先写好自己的睡眠文件/usr/lib/systemd/system/mysleep ```bash #!/bin/bash /usr/lib/systemd/systemd-sleep suspend && modprobe -r i2c_hid && modprobe i2c_hid ``` 添加可执行权限: ``` sudo chmod +x /usr/lib/systemd/system/mysleep ``` 然后修改/usr/lib/systemd/system/systemd-suspend.service为 ```bash # SPDX-License-Identifier: LGPL-2.1+ # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Suspend Documentation=man:systemd-suspend.service(8) DefaultDependencies=no Requires=sleep.target After=sleep.target [Service] Type=oneshot #ExecStart=/usr/lib/systemd/systemd-sleep suspend ExecStart=/usr/lib/systemd/system/mysleep ``` 刷新系统服务: ```bash sudo systemctl daemon-reload ``` 然后这个问题就被根治了! 我们的deepin UOS 技术交流群:19346666