Skip to content

Commit 75ebc42

Browse files
Merge pull request #2217 from jasonrandrews/review2
New running LXD containers on ChromeOS Learning Path
2 parents 0232b76 + 3a792b0 commit 75ebc42

File tree

9 files changed

+562
-0
lines changed

9 files changed

+562
-0
lines changed
33 KB
Loading
25.9 KB
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Install Ubuntu on ChromeOS Crostini as an LXC Container
3+
4+
draft: true
5+
cascade:
6+
draft: true
7+
8+
minutes_to_complete: 60
9+
10+
who_is_this_for: This Learning Path is for software developers who want to install Ubuntu and other Linux distributions on their Arm-based Chromebook with ChromeOS file sharing and GUI support.
11+
12+
learning_objectives:
13+
- Create an Ubuntu 24.04 container on ChromeOS Crostini using the Termina shell and LXC.
14+
- Set up ChromeOS integration for file sharing and GUI applications.
15+
- Manage LXC containers on ChromeOS.
16+
17+
prerequisites:
18+
- A ChromeOS device with the Linux development environment enabled. The Lenovo Chromebook Plus 14 is recommended.
19+
- Basic knowledge of the Linux command line.
20+
21+
author: Jason Andrews
22+
23+
### Tags
24+
skilllevels: Introductory
25+
subjects: Containers and Virtualization
26+
armips:
27+
- Cortex-A
28+
operatingsystems:
29+
- ChromeOS
30+
tools_software_languages:
31+
- Ubuntu
32+
33+
further_reading:
34+
- resource:
35+
title: Official ChromeOS Linux Support
36+
link: https://chromeos.dev/en/linux
37+
type: documentation
38+
- resource:
39+
title: Linux Containers
40+
link: https://linuxcontainers.org/
41+
type: website
42+
43+
### FIXED, DO NOT MODIFY
44+
# ================================================================================
45+
weight: 1 # _index.md always has weight of 1 to order correctly
46+
layout: "learningpathall" # All files under learning paths have this same wrapper
47+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
48+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
weight: 21
3+
title: "Next Steps"
4+
layout: "learningpathall"
5+
---
6+
33 KB
Loading
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: "Create an Ubuntu container"
3+
weight: 2
4+
layout: "learningpathall"
5+
---
6+
7+
The [Lenovo Chromebook Plus 14](https://www.bestbuy.com/site/lenovo-chromebook-plus-14-oled-2k-touchscreen-laptop-mediatek-kompanio-ultra-16gb-memory-256gb-ufs-seashell/6630493.p?skuId=6630493&intl=nosplash) is is powered by the MediaTek Kompanio Ultra processor, featuring an Arm-based MediaTek Kompanio Ultra processor, offers software developers a powerful and energy-efficient platform for Linux development. Its compatibility with containerized environments and support for ChromeOS Linux (Crostini) make it an excellent choice for coding, testing, and running modern development workflows on the go.
8+
9+
This Learning Path will walk you through setting up an Ubuntu 24.04 container on your Arm-based Chromebook using ChromeOS's built-in Linux development environment. You'll learn how to create and manage containers, install essential development tools, and integrate your Ubuntu environment with ChromeOS features like file sharing and GUI application support. By the end, you'll have a flexible and powerful Arm Linux development environment.
10+
11+
## Access the ChromeOS terminal
12+
13+
The first step to creating an Ubuntu container on ChromeOS is to open the ChromeOS shell.
14+
15+
Open the Chrome browser and press **Ctrl + Alt + T** to open crosh, the ChromeOS shell, crosh.
16+
17+
![ChromeOS shell #center](_images/chromeos-shell.png)
18+
19+
Run the command below to start the Termina shell.
20+
21+
```console
22+
vsh termina
23+
```
24+
25+
You are now in the Termina environment where you can manage containers.
26+
27+
The `lxc` command is used to manage containers on ChromeOS.
28+
29+
You can list the running containers.
30+
31+
```console
32+
lxc list
33+
```
34+
35+
If you have the default Debian container running you see output similar to:
36+
37+
```output
38+
+---------+---------+-----------------------+------+-----------+-----------+
39+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
40+
+---------+---------+-----------------------+------+-----------+-----------+
41+
| penguin | RUNNING | 100.115.92.204 (eth0) | | CONTAINER | 0 |
42+
+---------+---------+-----------------------+------+-----------+-----------+
43+
```
44+
45+
The name of the Debian container is penguin. When you enable the Linux subsystem on ChromeOS the Debian container named penguin is created, but you can create additional containers with different Linux distributions and different names.
46+
47+
## Create a Ubuntu 24.04 container
48+
49+
This command creates and starts a new Ubuntu 24.04 container named `u1`.
50+
51+
```bash
52+
lxc launch ubuntu:24.04 u1
53+
```
54+
55+
The output is:
56+
57+
```output
58+
Creating u1
59+
Starting u1
60+
```
61+
62+
Check the status of the new container and confirm the status is RUNNING.
63+
64+
```bash
65+
lxc list
66+
```
67+
68+
Now there are 2 containers running.
69+
70+
```output
71+
+---------+---------+-----------------------+------+-----------+-----------+
72+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
73+
+---------+---------+-----------------------+------+-----------+-----------+
74+
| penguin | RUNNING | 100.115.92.204 (eth0) | | CONTAINER | 0 |
75+
+---------+---------+-----------------------+------+-----------+-----------+
76+
| u1 | RUNNING | 100.115.92.206 (eth0) | | CONTAINER | 0 |
77+
+---------+---------+-----------------------+------+-----------+-----------+
78+
```
79+
80+
Create a new shell in the Ubuntu container.
81+
82+
```bash
83+
lxc exec u1 -- bash
84+
```
85+
86+
## Complete the Ubuntu setup
87+
88+
Once inside the Ubuntu container, you need to perform some initial setup tasks.
89+
90+
Update the package lists and upgrade installed packages to the latest versions.
91+
92+
```bash
93+
apt update && apt upgrade -y
94+
```
95+
96+
Install essential packages for development and system management. You can select your favorite software packages, these are examples.
97+
98+
```bash
99+
apt install -y net-tools gcc
100+
```
101+
102+
Creating a non-root user is a crucial security best practice and ensures that applications don't have unnecessary administrative privileges. The username `ubuntu` is already available in the container. You are free to use `ubuntu` as your non-root user or create a new user.
103+
104+
{{% notice Note %}}
105+
The following commands use `user1` as a new username. You can replace it with your actual desired username in all subsequent steps.
106+
{{% /notice %}}
107+
108+
Create a new user account. Skip if you want to use the `ubuntu` user.
109+
110+
```bash
111+
adduser user1
112+
```
113+
114+
Add the new user to the sudo group to grant administrative privileges. Skip if you want to use the `ubuntu` user.
115+
116+
```bash
117+
usermod -aG sudo user1
118+
```
119+
120+
Switch to your new user account to continue the setup.
121+
122+
```bash
123+
su - user1
124+
```
125+
126+
If you didn't creat a new user switch to `ubuntu` as the non-root user.
127+
128+
```bash
129+
su - ubuntu
130+
```
131+
132+
Continue to learn how to integrate the new Ubuntu container with ChromeOS features like file sharing.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: ChromeOS integration
3+
weight: 3
4+
layout: "learningpathall"
5+
---
6+
7+
## File sharing between ChromeOS and Linux
8+
9+
Chromebooks with Linux offer convenient file sharing capabilities between the main ChromeOS environment and the Linux subsystem.
10+
11+
Key Features:
12+
13+
- Selective Folder Sharing: ChromeOS allows you to share specific folders (not individual files) from the native files app with the Linux container. This is done by right-clicking a folder and selecting "Share with Linux." Once shared, these directories become accessible to Linux apps and the command line within the Linux environment.
14+
15+
- Two-Way Access: Files and folders created within the Linux container appear in the "Linux files" section of the ChromeOS Files app, enabling seamless movement of data between environments.
16+
17+
- Sandboxed Security: The Linux environment is sandboxed for security, meaning it doesn't have access to the full ChromeOS file system by default. Only the folders explicitly shared by the you are visible in Linux, ensuring protected data separation.
18+
19+
- Easy Integration: Shared folders can be navigated from Linux at paths such as /mnt/chromeos/MyFiles/. Applications and command-line tools within Linux can read and write to these shared folders.
20+
21+
- Management Tools: You can manage and revoke shared folder access through the ChromeOS Files app, allowing for flexible control over what is accessible to Linux.
22+
23+
These features make it simple to move files between ChromeOS and Linux applications while maintaining security and user control.
24+
25+
## Configure File System Integration
26+
27+
### Share ChromeOS directories
28+
29+
To access your ChromeOS files from within the Ubuntu container, you need to configure shared directories.
30+
31+
You can share directories using the ChromeOS File application. Right click on any directory and select **Share with Linux**.
32+
33+
If you share a ChromeOS directory it appears in `/mnt/chromeos/MyFiles/` in your Ubuntu container. For example, share your Downloads directory in ChromeOS and it is visible in Ubuntu.
34+
35+
```bash
36+
ls /mnt/chromeos/MyFiles/Downloads/
37+
```
38+
39+
### Share Google Drive directories
40+
41+
You can also share Google Drive directories using the ChromeOS Files application. Use the same right click and select **Share with Linux**.
42+
43+
If you share a Google Drive folder it appears in `/mnt/chromeos/GoogleDrive/MyDrive/` in your Ubuntu container. For example, share your `AndroidAssets` directory in Google Drive it is visible in Ubuntu.
44+
45+
```bash
46+
ls /mnt/chromeos/GoogleDrive/MyDrive/AndroidAssets
47+
```
48+
49+
Your shared folders appear in the **Linux Settings** under **Manage shared folders** as shown below:
50+
51+
![Shared folders #center](_images/shared-folders.png)
52+
53+
### Share a folder using the command line
54+
55+
You can use the commands below from the Termina shell.
56+
57+
Mount the entire ChromeOS file system to /mnt/chromeos in the container.
58+
59+
```bash
60+
lxc config device add ubuntu-main shared-chromeos disk source=/mnt/chromeos path=/mnt/chromeos
61+
```
62+
63+
Share your ChromeOS Downloads folder with the container
64+
65+
```bash
66+
lxc config device add ubuntu-main downloads disk source=/mnt/chromeos/MyFiles/Downloads path=/home/username/Downloads
67+
```
68+
69+
Share your ChromeOS Documents folder with the container.
70+
71+
```bash
72+
lxc config device add ubuntu-main documents disk source=/mnt/chromeos/MyFiles/Documents path=/home/username/Documents
73+
```
74+
75+
## File Operations
76+
77+
You can use the `lxc file` command to copy files to and from a container from the Termina shell.
78+
79+
As an example create a file named file1
80+
81+
```bash
82+
echo "test file 1" >> /mnt/shared/MyFiles/Downloads/file1
83+
```
84+
85+
Copy the file from your ChromeOS Downloads folder to the tmp directory in the container.
86+
87+
```bash
88+
lxc file push file1 u1/tmp/file1
89+
```
90+
91+
Copy the same file back to the Downloads directory with a new name.
92+
93+
```bash
94+
lxc file pull u1/tmp/file1 file2
95+
```
96+
97+
You now have the file in your Downloads directory with a new name.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Enable desktop applications
3+
weight: 4
4+
layout: "learningpathall"
5+
---
6+
7+
To use desktop applications like browsers in the Ubuntu container you need to enable the connection to the ChromeOS desktop using Sommelier.
8+
9+
Sommelier acts as a bridge, enabling seamless integration and smooth operation of Linux apps within the ChromeOS environment.
10+
11+
## Enable GUI Application Support
12+
13+
Install a minimal desktop environment to provide the necessary libraries for graphical applications.
14+
15+
```bash
16+
sudo apt install -y xubuntu-desktop-minimal
17+
```
18+
19+
Install a test application.
20+
21+
```bash
22+
sudo apt install -y terminator
23+
```
24+
25+
Configure the display environment variables to ensure GUI applications know where to render their windows
26+
27+
```console
28+
echo 'export DISPLAY=:0' >> ~/.bashrc
29+
```
30+
31+
Install the necessary tools to build Sommelier.
32+
33+
```bash
34+
sudo apt install -y clang meson libwayland-dev cmake pkg-config libgbm-dev libdrm-dev libxpm-dev libpixman-1-dev libx11-xcb-dev libxcb-composite0-dev libxkbcommon-dev libgtest-dev python3-jinja2
35+
```
36+
37+
You need to build Sommelier from source code because it is not available in Ubuntu repositories.
38+
39+
```bash
40+
git clone https://chromium.googlesource.com/chromiumos/platform2
41+
cd platform2/vm_tools/sommelier
42+
meson build
43+
cd build
44+
ninja
45+
sudo ninja install
46+
```
47+
48+
Sommelier is now installed in `/usr/local/bin/`
49+
50+
Create a systemd user unit file for X11 support.
51+
52+
```bash
53+
mkdir -p ~/.config/systemd/user
54+
```
55+
56+
Use a text editor to create the file `~/.config/systemd/user/[email protected]` with the contents below.
57+
58+
```ini
59+
[Unit]
60+
Description=Sommelier X11 bridge instance %i
61+
62+
[Service]
63+
Environment=DISPLAY=:0
64+
ExecStart=/usr/local/bin/sommelier -X --scale=1 --no-exit-with-child -- /bin/true
65+
Restart=on-failure
66+
67+
[Install]
68+
WantedBy=default.target
69+
```
70+
71+
Reload the Systemd user manager and start the Sommelier service.
72+
73+
```bash
74+
systemctl --user daemon-reload
75+
systemctl --user enable --now [email protected]
76+
```
77+
78+
Confirm the Sommelier service is running.
79+
80+
```bash
81+
systemctl --user status [email protected]
82+
```
83+
84+
Test a graphical application works. You can pick other applications to try.
85+
86+
```bash
87+
terminator &
88+
```
89+
90+
You should see a new terminal open on your ChromeOS desktop.
91+
92+
If needed, you can restart Sommelier.
93+
94+
```bash
95+
sudo systemctl restart sommelier@0
96+
```

0 commit comments

Comments
 (0)