<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Linux on LGiki&#39;s Blog</title>
    <link>https://lgiki.net/tags/linux/</link>
    <description>Recent content in Linux on LGiki&#39;s Blog</description>
    <generator>Hugo -- 0.148.2</generator>
    <language>en</language>
    <lastBuildDate>Mon, 18 Jan 2021 13:20:49 +0800</lastBuildDate>
    <atom:link href="https://lgiki.net/tags/linux/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>为联想 R7000 安装 ArchLinux</title>
      <link>https://lgiki.net/post/lenovo-r7000-2020-unboxing-and-archlinux-installation/</link>
      <pubDate>Fri, 03 Jul 2020 13:20:49 +0800</pubDate>
      <guid>https://lgiki.net/post/lenovo-r7000-2020-unboxing-and-archlinux-installation/</guid>
      <description>&lt;p&gt;开始之前，先贴上我这台联想R7000的配置：&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CPU: AMD Ryzen 7 4800H with Radeon Graphics (16) @ 2.900GHz
Memory: 2 * 8G DDR4 3200MHz
GPU: NVIDIA GeForce GTX 1650
SSD: Samsung PM981a 512G
SSD: Intel 760P 512G
Wireless LAN Card: Intel Wi-Fi 6 AX200
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;其中512G的Intel 760P是我自己加上的，机子原厂只带了512G的Samsung PM981a。&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>开始之前，先贴上我这台联想R7000的配置：</p>
<pre tabindex="0"><code>CPU: AMD Ryzen 7 4800H with Radeon Graphics (16) @ 2.900GHz
Memory: 2 * 8G DDR4 3200MHz
GPU: NVIDIA GeForce GTX 1650
SSD: Samsung PM981a 512G
SSD: Intel 760P 512G
Wireless LAN Card: Intel Wi-Fi 6 AX200
</code></pre><p>其中512G的Intel 760P是我自己加上的，机子原厂只带了512G的Samsung PM981a。</p>
<p>这里简单放上一张<code>neofetch</code>截图：</p>
<p><img alt="neofetch" loading="lazy" src="/lenovo-R7000-2020-unboxing-and-ArchLinux-installation/neofetch.png"></p>
<p>PS：Linux之父Linus Torvalds也<a href="http://lkml.iu.edu/hypermail/linux/kernel/2005.3/00406.html">更换到了AMD平台</a>，相信未来Linux内核对AMD平台的支持情况会越来越好。</p>
<h1 id="archlinux安装">ArchLinux安装</h1>
<p>新机器到手，除了赶紧把预装了联想全家桶的Windows 10家庭中文版换成专业版之外，最重要的就是装上ArchLinux了！</p>
<p>平时写代码还是更习惯用Linux，不仅仅是字体渲染看着比Windows清晰舒服，更重要的是很多事情都可以通过命令行搞定，还不容易有各种各样奇奇怪怪的毛病（例如在开始菜单加入广告推荐使用Edge浏览器等）。</p>
<p>ArchLinux的安装只需要按照官方Archwiki上的<a href="https://wiki.archlinux.org/index.php/Installation_guide">Installation guide</a>一步步操作就行了。</p>
<p>不过安装过程中如果是选择通过WiFi来接入互联网那马上就会遇到第一个问题：通过<code>wifi-menu</code>或者其他相关命令无法正常连接WiFi。</p>
<h2 id="wifi连接">WiFi连接</h2>
<p>第一次启动ArchLinux的安装镜像，习惯性使用<code>wifi-menu</code>连接WiFi，直接就报错了。难道是AX200这张无线网卡太新了，安装镜像还不支持？检查了一下驱动发现是没问题的。</p>
<p>翻了翻Google才发现，原来是机子所有的无线电接口都被bloacked了，解决方法也很简单，通过rfkill命令就能直接把所有的无线电接口都unblock：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rfkill unblock all
</span></span></code></pre></div><p>执行完这条命令之后再执行<code>rfkill list</code>应该就能看到如下结果，所有的无线电接口的blocked状态都是no。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">➜  ~ rfkill list
</span></span><span class="line"><span class="cl">0: ideapad_wlan: Wireless LAN
</span></span><span class="line"><span class="cl">        Soft blocked: no
</span></span><span class="line"><span class="cl">        Hard blocked: no
</span></span><span class="line"><span class="cl">1: ideapad_bluetooth: Bluetooth
</span></span><span class="line"><span class="cl">        Soft blocked: no
</span></span><span class="line"><span class="cl">        Hard blocked: no
</span></span><span class="line"><span class="cl">2: phy0: Wireless LAN
</span></span><span class="line"><span class="cl">        Soft blocked: no
</span></span><span class="line"><span class="cl">        Hard blocked: no
</span></span><span class="line"><span class="cl">3: hci0: Bluetooth
</span></span><span class="line"><span class="cl">        Soft blocked: no
</span></span><span class="line"><span class="cl">        Hard blocked: no
</span></span></code></pre></div><p>这时候就能正常使用<code>wifi-menu</code>或其他相关的命令行连接WiFi，继续进行后续的安装操作了。</p>
<h2 id="屏蔽nouveau">屏蔽nouveau</h2>
<p>不知道是不是因为GTX 1650这张显卡比较新，nouveau用起来总是会有一些奇奇怪怪的问题，偶尔还会导致系统关机的时候卡住，内核日志里也总会有很多关于nouveau的报错。</p>
<p>因为打算装NVIDIA的闭源驱动，所以我直接屏蔽了nouveau，省得再出现一些奇奇怪怪的问题，具体的屏蔽方法就是在<code>/etc/modprobe.d</code>目录下新建一个<code>disable-nouveau.conf</code>文件并写入以下内容：</p>
<pre tabindex="0"><code>blacklist nouveau
</code></pre><p>这样下次开机进系统就不会加载nouveau驱动了，内核日志中也不会再出现一大堆关于nouveau的报错。</p>
<h2 id="屏幕亮度调节">屏幕亮度调节</h2>
<p>这是我刚装上ArchLinux时遇到的第一个问题，屏幕亮度无法调节，开机直接就是最高亮度。</p>
<p>当时翻遍了ArchWiki和Google，尝试了很多解决方法，包括在Kernel启动参数后加上各种奇奇怪怪的启动参数（<code>acpi_osi=! acpi_osi=&quot;Windows 2009&quot;</code>、<code>acpi_backlight=vendor</code>等），直接向<code>/sys/class/backlight/amdgpu_bl0/brightness</code>中写入亮度数值都不行，然后就彻底放弃了，最高亮度凑活着用吧。</p>
<p>后来有一次从Windows重启到Linux的时候意外发现：先启动到Windows，然后在Windows上面选择重启，之后再进Linux就能正常调节亮度了。当时没有其他解决方法，所以只能每次用Linux都先启动到Windows，然后再重启进ArchLinux。</p>
<p>后面滚到5.7.6内核之后就能正常调节屏幕亮度了，但是随之而来又带来了新的问题，系统在播放音频或者是视频的时候，有一定的概率会卡死，就跟这个帖子描述的类似：<a href="https://bbs.archlinux.org/viewtopic.php?id=256929">https://bbs.archlinux.org/viewtopic.php?id=256929</a>，kernel的日志也是一样的，初步怀疑是kernel某个patch有问题，又懒得自己编译内核，所以就先滚回5.7.5内核，最高亮度先用着，坐等内核更新。</p>
<p>终于，昨天更新了5.7.7内核之后，亮度调节正常，播放音/视频也不会再导致系统卡死了。R7000装Linux遇到屏幕亮度无法调节的可以将内核升级到5.7.7试试，应该就能正常调节了。</p>
<h2 id="amdnvidia双显卡切换">AMD/NVIDIA双显卡切换</h2>
<p>R7000是支持在BIOS中设置成独显直连的，但是我并不想让Linux直接在独显上跑，不仅费电，还容易发热，日常写代码感觉也不需要用上独显，所以我还是更喜欢双显卡切换，毕竟集成显卡也是花了钱买的嘛，怎么能就这么放着不用呢。</p>
<p>之前暗影精灵2上面是使用bumblebee的方案来管理双显卡的，但是bumblebee似乎只支持Intel+NVIDIA双显卡，不支持AMD+NVIDIA双显卡。那就只能寻找新的解决方案了。</p>
<p>所以就去爬了爬ArchWiki上的<a href="https://wiki.archlinux.org/index.php/NVIDIA_Optimus">NVIDIA Optimus</a>，最终决定采用<a href="https://github.com/Askannz/optimus-manager/">optimus-manager</a>来管理双显卡。</p>
<h3 id="安装显卡驱动">安装显卡驱动</h3>
<p>AMD集成显卡的驱动使用<code>xf86-video-amdgpu</code>，NVIDIA独立显卡的驱动使用NVIDIA闭源驱动：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo pacman -S xf86-video-amdgpu
</span></span><span class="line"><span class="cl">sudo pacman -S nvidia nvidia-settings nvidia-utils lib32-nvidia-utils
</span></span></code></pre></div><h3 id="安装optimus-manager">安装Optimus Manager</h3>
<p>首先需要安装optimus-manager， 因为是AMD平台，所以不能直接安装原版的optimus-manager，必须安装AMD分支版本<a href="https://aur.archlinux.org/packages/optimus-manager-amd-git/">optimus-manager-amd-git</a><!-- raw HTML omitted -->AUR<!-- raw HTML omitted -->：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">yay -S optimus-manager-amd-git
</span></span></code></pre></div><p>同时bbswitch也得替换成<a href="https://aur.archlinux.org/packages/bbswitch-ati-git/">bbswitch-ati-git</a><!-- raw HTML omitted -->AUR<!-- raw HTML omitted -->：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">yay -S bbswitch-ati-git
</span></span></code></pre></div><p>都安装好了之后开启服务：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo systemctl <span class="nb">enable</span> optimus-manager.service
</span></span></code></pre></div><p>同时需要确保<code>/etc/X11/xorg.conf</code> 和 <code>/etc/X11/xorg.conf.d</code> 下面没有显示相关的配置文件</p>
<h3 id="配置optimus-manager">配置Optimus Manager</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo mkdir -p /etc/optimus-manager
</span></span><span class="line"><span class="cl">sudo cp /usr/share/optimus-manager.conf /etc/optimus-manager/optimus-manager.conf
</span></span></code></pre></div><p>然后编辑<code>/etc/optimus-manager/optimus-manager.conf</code>文件，根据文件内的注释说明进行optimus-manager的配置。</p>
<p>这里贴一下我自己用的配置：</p>
<pre tabindex="0"><code>[optimus]

# This parameter defines the method used to power switch the Nvidia card. See the documentation
# for a complete description of what each value does. Possible values :
#
# - nouveau : load the nouveau module on the Nvidia card.
# - bbswitch : power off the card using the bbswitch module (requires the bbswitch dependency).
# - acpi_call : try various ACPI method calls to power the card on and off (requires the acpi_call dependency)
# - none : do not use an external module for power management. For some laptop models it&#39;s preferable to
#           use this option in combination with pci_power_control (see below).
#           With that option set, you can also use the scripts nvidia-enable.sh and nvidia-disable.sh to
#           execute custom commands for power management.
switching=none

# Enable PCI power management in Intel mode.
# This option is incompatible with acpi_call and bbswitch, so it will be ignored in those cases.
pci_power_control=yes

# Remove the Nvidia card from the PCI bus.
# May prevent crashes caused by power switching.
# Ignored if switching=nouveau or switching=bbswitch.
pci_remove=no

# Reset the Nvidia card at the PCI level before reloading the nvidia module.
# Ensures the card is in a fresh state before reloading the nvidia module.
# May fix some switching issues. Possible values :
#
# - no : does not perform any reset
# - function_level : perform a light &#34;function-level&#34; reset
# - hot_reset : perform a &#34;hot reset&#34; of the PCI bridge. ATTENTION : this method messes with the hardware
#         directly, please read the online documentation of optimus-manager before using it.
#         Also, it will perform a PCI remove even if pci_remove=no.
#
pci_reset=no

# Automatically log out the current desktop session when switching GPUs.
# This feature is currently supported for the following DE/WM :
# KDE Plasma, GNOME, XFCE, Deepin, i3, Openbox, AwesomeWM, bspwm
# If this option is disabled or you use a different desktop environment,
# GPU switching only becomes effective at the next graphical session login.
auto_logout=yes

# The mode used with startup mode ac_auto when not connected to AC.
# Possible values : amd, intel, hybrid-amd, hybrid-intel
ac_auto_battery_mode=amd


# The mode used with startup mode ac_auto when connected to AC.
# Possible values : hybrid, nvidia
ac_auto_extpower_mode=nvidia

[intel]

# Driver to use for the Intel GPU. Possible values : modesetting, intel
# To use the intel driver, you need to install the package &#34;xf86-video-intel&#34;.
driver=modesetting

# Acceleration method (corresponds to AccelMethod in the Xorg configuration).
# Only applies to the intel driver.
# Possible values : sna, xna
# Leave blank for the default (no option specified)
accel=

# Enable TearFree option in the Xorg configuration.
# Only applies to the intel driver.
# Possible values : yes, no
# Leave blank for the default (no option specified)
tearfree=

# DRI version. Possible values : 2, 3
DRI=3

# Whether or not to enable modesetting for the nouveau driver.
# Does not affect modesetting for the Intel GPU driver !
# This option only matters if you use nouveau as the switching backend.
modeset=yes


[amd]

# Driver to use for the AMD GPU. Possible values : modesetting, amdgpu
# To use the amdgpu driver, you need to install the package &#34;xf86-video-amdgpu&#34;.
driver=amdgpu

# Enable TearFree option in the Xorg configuration.
# Only applies to the amdgpu driver.
# Possible values : yes, no
# Leave blank for the default (no option specified)
tearfree=

# DRI version. Possible values : 2, 3
DRI=3

# Whether or not to enable modesetting for the nouveau driver.
# Does not affect modesetting for the AMD GPU driver !
# This option only matters if you use nouveau as the switching backend.
modeset=yes


[nvidia]

# Whether or not to enable modesetting. Required for PRIME Synchronization (which prevents tearing).
modeset=yes

# Whether or not to enable the NVreg_UsePageAttributeTable option in the Nvidia driver.
# Recommended, can cause poor CPU performance otherwise.
PAT=yes

# DPI value. This will be set using the Xsetup script passed to your login manager.
# It will run the command
# xrandr --dpi &lt;DPI&gt;
# Leave blank for the default (the above command will not be run).
DPI=96

# If you&#39;re running an updated version of xorg-server (let&#39;s say to get PRIME Render offload enabled),
# the nvidia driver may not load because of an ABI version mismatch. Setting this flag to &#34;yes&#34;
# will allow the loading of the nvidia driver.
ignore_abi=no

# Set to yes if you want to use optimus-manager with external Nvidia GPUs (experimental)
allow_external_gpus=no

# Comma-separated list of Nvidia-specific options to apply.
# Available options :
# - overclocking : enable CoolBits in the Xorg configuration, which unlocks clocking options
#   in the Nvidia control panel. Note: does not work in hybrid mode.
# - triple_buffer : enable triple buffering.
options=
</code></pre><p>关于我的这份配置文件：</p>
<ul>
<li>switching method不使用bbswitch是因为使用集成显卡的时候通过bbswitch关闭独立显卡会导致电脑的风扇以最高转速狂转，可能是因为关闭了独立显卡电源之后，系统无法正常读取独显温度导致将风扇调至最高转速，暂时没有找到一个比较靠谱的解决方法，所以就先用none，也许未来BIOS升级之后能解决这个问题</li>
<li>正是因为switching method选择了none，所以把pci_power_control启用了，让PCI power management管理独显的电源</li>
<li>AMD的driver使用amdgpu</li>
<li>其余配置基本都是默认配置</li>
</ul>
<p>一些都配置好了就重启电脑吧，如果没有什么意外的话，Optimus Manager已经正常工作了。</p>
<h3 id="optimus-manager用法">Optimus Manager用法</h3>
<ul>
<li>
<p>切换到NVIDIA：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --switch nvidia
</span></span></code></pre></div></li>
<li>
<p>切换到AMD：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --switch amd
</span></span></code></pre></div></li>
<li>
<p>设置开机使用AMD：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --set-startup<span class="o">=</span>amd
</span></span></code></pre></div></li>
<li>
<p>显示当前模式：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --print-mode
</span></span></code></pre></div></li>
<li>
<p>显示开机使用的模式：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --print-startup
</span></span></code></pre></div></li>
<li>
<p>更多用法：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">optimus-manager --help
</span></span></code></pre></div></li>
</ul>
<h3 id="optimus-manager-gui">Optimus Manager GUI</h3>
<ul>
<li>
<p><a href="https://github.com/Shatur95/optimus-manager-qt">Optimus Manager Qt</a></p>
<p><img alt="optimus-manager-qt" loading="lazy" src="/lenovo-R7000-2020-unboxing-and-ArchLinux-installation/optimus-manager-qt.png"></p>
</li>
<li>
<p>Argos Script For Optimus-Manager</p>
<p><img alt="argos-optimus-manager" loading="lazy" src="/lenovo-R7000-2020-unboxing-and-ArchLinux-installation/argos-optimus-manager.png"></p>
<p>由于<a href="https://github.com/inzar98/optimus-manager-argos">原版的optimus-manager-argos</a>不支持AMD显卡的切换，同时也停止维护了，所以我Fork了一份，加上了AMD的支持：<a href="https://github.com/LGiki/optimus-manager-argos">https://github.com/LGiki/optimus-manager-argos</a></p>
</li>
</ul>
<h2 id="触摸板">触摸板</h2>
<p>是的，这台机器的触摸板在Linux下无法正常使用，触摸跟按键都没有任何反应。</p>
<p>在内核日志上可以找到关于触摸板的报错内容：</p>
<pre tabindex="0"><code>[    1.981868] i2c_hid i2c-MSFT0001:00: supply vdd not found, using dummy regulator
[    1.981883] i2c_hid i2c-MSFT0001:00: supply vddl not found, using dummy regulator
[    7.064976] i2c_hid i2c-MSFT0001:00: failed to reset device.
[   13.251401] i2c_hid i2c-MSFT0001:00: failed to reset device.
[   19.438327] i2c_hid i2c-MSFT0001:00: failed to reset device.
[   25.624986] i2c_hid i2c-MSFT0001:00: failed to reset device.
[   26.638144] i2c_hid i2c-MSFT0001:00: can&#39;t add hid device: -61
[   26.638591] i2c_hid: probe of i2c-MSFT0001:00 failed with error -61
</code></pre><p>找到了一个相关的讨论：<a href="https://bugzilla.kernel.org/show_bug.cgi?id=207759">https://bugzilla.kernel.org/show_bug.cgi?id=207759</a></p>
<p>由于我平时都是用鼠标，几乎用不到笔记本的触摸板，所以也懒得去研究这个问题了，说不定随着内核的更新，触摸板突然就能用了呢（想peach）。</p>
<h3 id="更新-20210118">更新 (2021.01.18)</h3>
<p>针对触摸板无法正常使用的相关讨论可以看：<a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1887190">https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1887190</a></p>
<p>5.11及之后的内核应该就修复这个问题了，只需要等5.11内核release之后及时更新即可。</p>
<h2 id="xorg无法启动">Xorg无法启动</h2>
<p>如果你遇到了Xorg无法启动的问题，查看日志找到了如下字样：</p>
<pre tabindex="0"><code>/dev/dri/card0: No such file or directory
</code></pre><p>检查<a href="https://archlinux.org/packages/extra/x86_64/xf86-video-amdgpu/">xf86-video-amdgpu</a>等相关包均安装正常的情况下，需要根据<a href="https://wiki.archlinux.org/index.php/Kernel_mode_setting">https://wiki.archlinux.org/index.php/Kernel_mode_setting</a>中的描述，编辑<code>/etc/mkinitcpio.conf</code>文件，在其中的<code>MODULES</code>部分加入<code>amdgpu</code>：</p>
<pre tabindex="0"><code>MODULES=(amdgpu)
</code></pre><p>保存之后需要执行下面指令，重新生成initramfs images：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo mkinitcpio -P
</span></span></code></pre></div><p>重启系统之后Xorg应该就能正常启动了</p>]]></content:encoded>
    </item>
  </channel>
</rss>
