---
# System prepended metadata

title: Chromium OS
tags: [linux, chromium]

---

# Chromium OS

###### tags: `chromium` `linux`

## 前置準備

在 Ubuntu 16.04 或更新的版本上安裝`git`、`subversion`、`curl`、`lvm`等：

```
$ sudo apt-get install \
git-core gitk git-gui subversion curl lvm2 thin-provisioning-tools python-pkg-resources python-virtualenv python-oauth2client
```

安裝`depot_tools`：

```
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
```

把`depot_tools`的安裝路徑加到`$PATH`：

```
$ export PATH=/path/to/depot_tools:$PATH
```

而我的`depot_tools`安裝路徑為`/usr/bin/depot_tools`所以：

```
$ chown -R 0:0 depot_tools/ ; sudo mv depot_tools/ /usr/bin/
```

我慣用的 text editor 不是 nano，故將預設的 text editor 改一下：

```
$ sudo update-alternatives --config editor
```

讓`sudo`指令放鬆一點：

```
$ sudo visudo
```

在`Defaults`那幾行下方加入：

```
Defaults	!tty_tickets
Defaults	timestamp_type=ppid
Defaults	timestamp_timeout=180
```

其中`timestamp_timeout=180`的`180`可能要視執行環境的效能去做調整。

> 注意：若執行環境為平時日常使用，基於資安考量，所有步驟完成後建議移除這幾行。

## 取得源代碼

若尚未設定`git`的用戶資訊：
```
$ git config --global user.email "you@example.com" ; git config --global user.name "Your Name"
```

建立並進入工作目錄：

```
$ export SOURCE_REPO=chromiumos ; mkdir $SOURCE_REPO ; cd $SOURCE_REPO
```

下載：

```
$ repo init -u https://chromium.googlesource.com/chromiumos/manifest.git ; repo sync
```

> 注意：本文付梓之際，所需空間約33Gb，請預留大於這個容量的空間。

## 版本3.6以上的 Python

```
$ sudo add-apt-repository ppa:deadsnakes/ppa ; sudo apt update ; sudo apt install python3.9
```

確認一下版本：

```
$ python3 -V
Python 3.5.2
```

若還是原來的舊版本：

```
Python 3.5.2
```

就把連結更新一下：

```
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
```

## 編譯

```
$ export BOARD=amd64-generic ; cros_sdk -- ./build_packages --board=$BOARD
```

首次執行以上指令會等很久，非&#126;常&#126;久，這就是為什麼上面要放寬`sudo`指令。

建立映像檔：

```
$ cros_sdk -- ./build_image --board=$BOARD
```

將映像檔寫到 USB 隨身碟：

```
$ cros flash --board=$BOARD usb://
```

## 錯誤

```
 * ERROR: chromeos-base/crosvm-0.1.0-r1104::chromiumos failed (compile phase):
 *   (no error message)
 *
 * Call stack:
 *               ebuild.sh, line  125:  Called src_compile
 *             environment, line 4207:  Called ecargo_build '-v' '--features=gpu virtio-gpu-next video-decoder video-encoder wl-dmabuf tpm gdb chromeos' '-p' 'crosvm'
 *             environment, line 2287:  Called ecargo 'build' '--target=x86_64-cros-linux-gnu' '--release' '-v' '--features=gpu virtio-gpu-next video-decoder video-encoder wl-dmabuf tpm gdb chromeos' '-p' 'crosvm'
 *             environment, line 2282:  Called die
 * The specific snippet of code:
 *       flock --shared "$(cros-rust_get_reg_lock)" cargo -v "$@" || die;
 *
 * Build log: /build/amd64-generic/tmp/portage/logs/chromeos-base:crosvm-0.1.0-r1104:20201201-111330.log
 * Stable log symlink: /build/amd64-generic/tmp/portage/chromeos-base/crosvm-0.1.0-r1104/temp/build.log
 * CWD: /build/amd64-generic/tmp/portage/chromeos-base/crosvm-0.1.0-r1104/work/crosvm-0.1.0
 * S:   /build/amd64-generic/tmp/portage/chromeos-base/crosvm-0.1.0-r1104/work/crosvm-0.1.0
19:40:34 ERROR   : Tue Dec  1 19:40:34 CST 2020
19:40:34 ERROR   :  PGID  PPID   PID     ELAPSED     TIME %CPU COMMAND
19:40:34 ERROR   :     4     4  5210    08:46:06 00:00:00  0.0 /bin/bash ./build_packages --board=amd64-generic
19:40:34 ERROR   :     4  5210 12778       00:00 00:00:00  0.0  \_ /bin/bash ./build_packages --board=amd64-generic
19:40:34 ERROR   :     4 12778 12779       00:00 00:00:00  0.0      \_ ps f -o pgid,ppid,pid,etime,cputime,%cpu,command
19:40:34 ERROR   : Arguments of 5210: ./build_packages '--board=amd64-generic'
19:40:34 ERROR   : Backtrace:  (most recent call is last)
19:40:34 ERROR   :  build_packages:465:main(), called: die_err_trap
19:40:34 ERROR   :
19:40:34 ERROR   : Command failed:
19:40:34 ERROR   :   Command '( if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
19:40:34 ERROR   :     info "Starting goma compiler_proxy."; goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"; "${goma_ctl}" restart; trap "'${goma_ctl}' stop" EXIT;
19:40:34 ERROR   : fi; sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" --useoldpkg-atoms="${CRITICAL_SDK_PACKAGES[*]}" --rebuild-exclude="${CRITICAL_SDK_PACKAGES[*]}" )' exited with nonzero code: 1
```

https://chromium.googlesource.com/chromiumos/platform/crosvm/

