Chrome OS devices/Crostini

出自 Arch Linux 中文维基

Crostini 是Google的總括術語,用於使Linux應用程序支持易於使用,並與Chrome操作系統很好地集成。

本文描述了如何在一個容器(通過Crostini)中的Chromebook上安裝Arch Linux,而不需要啟用開發模式,允許應用程序與其他Chrome/Android應用程序一起運行。

亮點:

  • 官方支持,不需要啟用開發模式- 讓ChromeOS更安全,不需要刷BIOS等。
  • 更好的電池壽命-具有Linux功能的Chrome電池壽命。
  • 支持音頻和OpenGL,但麥克風和USB設備的支持仍在進行中。

介紹[編輯 | 編輯原始碼]

啟用Linux支持[編輯 | 編輯原始碼]

在「設置」下查找Linux並啟用它。 這將安裝一個Debian Linux容器,然後將其替換為Arch Linux容器。

設置 > Linux(測試版) > 啟用

Crostini仍在向Chromebook推廣。 如果您沒有看到啟用Linux的選項,則可能需要切換到Beta或Developer頻道(如果尚未將其部署到筆記本電腦的穩定頻道中)。 這可以通過``設置>關於Chrome操作系統>頻道>開發/測試版來完成。

用Arch Linux替換默認的Debian Linux容器[編輯 | 編輯原始碼]

以下說明基於 https://www.reddit.com/r/Crostini/wiki/howto/run-arch-linux

0. 刪除Debian容器(可選)

如果您有沒有用Debian了,你可以通過停止並重新創建termina虛擬機節省一定的存儲空間(這是做的最簡單的方法,簡單地破壞與容器 lxc destroy penguin會留下未使用空間)。 請注意,這還將刪除您可能在終端下擁有的任何其他容器。

vmc destroy termina
vmc start termina

1. 安裝Arch Linux容器

在Chrome中打開一個新的終端(Ctrl + Alt + T)。 然後連接到終端並創建一個Arch Linux容器:

vmc container termina arch https://us.lxd.images.canonical.com/ archlinux/current

在大陸地區可能使用本機鏡像源速度會很慢,可以嘗試替換為清華源進行更新:

vmc container termina arch https://mirrors.tuna.tsinghua.edu.cn/lxc-images/ archlinux/current

完成後將顯示以下錯誤:

"Error: routine at frontends/vmc.rs:403 `container_setup_user(vm_name,user_id_hash,container_name,username)` failed: timeout while waiting for signal"

這是預期的行為,請繼續以下步驟。

2. 連接到termina vm並檢查是否存在arch容器(可能需要幾分鐘才能顯示在列表中):

vsh termina
lxc list

3. 在arch容器上啟動bash shell:

lxc exec arch -- bash

4. 根據您在容器上的gmail用戶名,為默認用戶設置密碼。 默認情況下,gmail用戶未設置密碼,因此我們需要進行設置:

passwd $(grep 1000:1000 /etc/passwd|cut -d':' -f1)

您可能還需要添加sudo並將用戶添加到wheel組。

pacman -S sudo
visudo
提示:因為眾所周知的原因,在中國可能需要換源才能安裝成功。 取消/etc/pacman.d/mirrorlist.pacnew文件中China源的注釋,大概在80+行

取消注釋此行:

# %wheel ALL=(ALL) ALL

將您的用戶添加到wheel組以允許sudo命令

usermod -aG wheel $(grep 1000:1000 /etc/passwd|cut -d':' -f1)

退出容器:

exit

5. 使用剛剛配置的普通用戶帳戶登錄到容器:

lxc console arch

6. 驗證容器中的網絡。 命令

ip -4 a show dev eth0

應該返回分配了IP地址的非空輸出。 如果不為空,請繼續執行步驟7,否則,您將面臨#容器中沒有網絡故障排除部分中描述的問題-請按照此處列出的說明解決該問題。

7. 安裝Crostini容器工具,用於GUI應用程序的Wayland,用於X11應用程序的XWayland。

安裝cros-container-guest-tools-gitAUR包. 另外,安裝 waylandxorg-xwayland才能使用GUI工具。

注意: 如果安裝時提示如下error可以執行 sudo pacman -S base-devel 安裝基本打包工具

==> ERROR: Cannot find the strip binary required for object file stripping.

Error downloading sources: cros-container-guest-tools-git

8. 啟用並啟動服務(針對Wayland GUI、X11 GUI、Wayland GUI低密度和X11 GUI低密度):

$ systemctl --user enable sommelier@0
$ systemctl --user enable sommelier-x@0
$ systemctl --user enable sommelier@1
$ systemctl --user enable sommelier-x@1
$ systemctl --user start sommelier@0
$ systemctl --user start sommelier-x@0
$ systemctl --user start sommelier@1
$ systemctl --user start sommelier-x@1

運行以下命令,確保這些服務運行成功:

systemctl --user status sommelier@0
systemctl --user status sommelier@1
systemctl --user status sommelier-x@0
systemctl --user status sommelier-x@1

現在,在Arch Linux中安裝應用程序後,它們會自動顯示並可以從ChromeOS啟動。

9. 將默認的Debian容器替換為Arch Linux。

Exit from the container shell back to the termina shell pressing <ctrl>+a q (or just close existing and open new termina shell as shown in step 2). The default Debian container is named penguin. Renaming the "arch" container created above to it will cause chrome to launch Linux apps from the arch container. Skip the third line if you have already removed the Debian container.

按下<ctrl>+a q(或如步驟2所示,僅關閉現有容器並打開新的termina外殼),從容器外殼退出並回到termina外殼。 默認的Debian容器名為penguin。 將上面創建的「 arch」容器重命名為它會導致chrome從arch容器啟動Linux應用。 如果您已經刪除了Debian容器,請跳過第三行。

lxc stop --force arch
lxc stop --force penguin
lxc rename penguin debian
lxc rename arch penguin
lxc start penguin

10. 重新啟動Linux子系統以應用更改。 在容器shell內重新啟動後

systemctl --failed
systemctl --user --failed

應同時報告「0已加載的單位列表」和

ip -4 a show dev eth0

應該報告分配給容器的IP地址

疑難解答[編輯 | 編輯原始碼]

容器中沒有網絡[編輯 | 編輯原始碼]

As was reported by multiple sources, systemd-networkd and systemd-resolved services in systemd-244.1 are not working properly for unprivileged LXC containers, which ends up in missing network connectivity inside the Crostini container. Proposed solution is completely disable systemd-networkd/systemd-resolved and perform network configuration by dhclient service instead:

正如多個消息來源所報告的那樣,systemd-244.1中的systemd networkd和systemd解析服務對於沒有特權的LXC容器不能正常工作,最終導致Crostini容器中缺少網絡連接。建議的解決方案是完全禁用systemd networkd/systemd resolved,改為通過dhclient服務執行網絡配置:

注意: 這段中文翻譯的不太好。。。
sudo dhcpcd eth0
sudo pacman -S dhclient
sudo systemctl disable systemd-networkd
sudo systemctl disable systemd-resolved
sudo unlink /etc/resolv.conf
sudo touch /etc/resolv.conf
sudo systemctl enable dhclient@eth0
sudo systemctl start dhclient@eth0

如果您相比建議的解決方案更喜歡NetworkManagerdhcpcd,也可以用來解決該問題。

應用無法在Chrome OS(無限轉圈)中打開[編輯 | 編輯原始碼]

我發現啟動控制台(lxc console penguin)會話會阻止應用程序在Chrome操作系統中啟動。啟動將導致無限轉圈。在這種情況下,我必須停止再啟動容器以使Chrome操作系統啟動程序工作

lxc stop penguin
lxc start penguin

我沒有使用lxc控制台會話,而是使用從ChromeOS啟動的常規Linux終端GUI來防止這個問題。

音頻播放[編輯 | 編輯原始碼]

Crostini從Chrome OS 74開始支持音頻播放。安裝了 cros-container-guest-tools-gitAUR後,ALSA和PulseAudio播放均應立即可用。 截至2019年8月21日,不支持音頻輸入。

視頻播放[編輯 | 編輯原始碼]

mpv可以使用軟件渲染播放視頻,而無需任何附加配置,但這對於像H265這樣的現代視頻編解碼器來說,是一種CPU消耗和滯後的體驗。對於硬件加速播放,需要GPU加速。考慮到Crostini的GPU加速是基於3D GPU project的,因此沒有執行真正的GPU設備傳遞,並且沒有VA-API或VPDAU之類的硬件特定API。但是,可以使用OpenGL加速,即這是[mpv]媒體播放器的mpv.conf配置示例,它啟用了從Chrome OS 77開始的Google Pixelbook上的加速視頻和音頻播放:

vo=gpu
ao=alsa

GPU加速[編輯 | 編輯原始碼]

在谷歌Pixelbook上,GPU加速與Arch開箱即用的Chrome OS 77協同工作。最近發布的ChromeOS也不需要啟用任何標誌:

$ glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Red Hat (0x1af4)
    Device: virgl (0x1010)
    Version: 19.1.4
--> Accelerated: yes <--
    Video memory: 0MB
    Unified memory: no
    Preferred profile: core (0x1)
    Max core profile version: 4.3
    Max compat profile version: 3.1
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
OpenGL vendor string: Red Hat
OpenGL renderer string: virgl
OpenGL core profile version string: 4.3 (Core Profile) Mesa 19.1.4
OpenGL core profile shading language version string: 4.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile

OpenGL version string: 3.1 Mesa 19.1.4
OpenGL shading language version string: 1.40
OpenGL context flags: (none)

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 19.1.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

全屏視頻、遊戲和鼠標捕捉[編輯 | 編輯原始碼]

目前,Crostini從Chrome OS 79(當前在開發人員通道中)開始對鼠標捕獲開始了有限的支持。 您必須啟用標記chrome://flags/#exo-pointer-lock 才能捕獲鼠標。 與鼠標捕獲有關的已關閉問題是https://bugs.chromium.org/p/chromium/issues/detail?id=927521

有用的鏈接[編輯 | 編輯原始碼]

  1. Running Custom Containers Under Chrome OS
  2. /r/Crostini
  3. Powerline Web Fonts for Chromebook