Featured

How I use ChromeOS’s linux containers

When you enable “Linux” on ChromeOS, a default Virtual Machine is created (and a default linux container). VM’s are the layer above containers- each VM can house multiple containers. The default VM is named “termina” and once it exists, you can interact with it from crosh (The Chromium OS Shell) using the vmc command. The default container is named “penguin”.

Note, for my purposes, I create a second VM named wpvm and then create containers within that VM. This makes it fast and easy to spin up Debian environments (I’ll try to cover other container types in a later post) for whatever your needs may be. The --enable-gpu is optional. YMMV.

First, open a crosh window (ctrl-alt-t). Then, to create and start a new VM named “wpvm”:

crosh> vmc start --enable-gpu wpvm

After the above VM is created, you’ll end up at a shell prompt within the VM. A potential point of confusion, the prompt below shows “(termina)” when we’re actually in a VM named “wpvm”. The “(termina)” here refers to the VM image ChromeOS uses for all VM’s. Keep calm and keyboard on.

(termina) chronos@localhost

From here, exit the VM using ctrl-d

Now let’s create a container within the new “wpvm” VM. We’ll use Google/ChromeOS’s standard Crostini container, “stretch”:

crosh> vmc container wpvm stretch

If everything worked, you’ll find yourself signed into the new Debian Stretch container with a bash prompt:

mark.drovdahl@stretch:~$

If you want to verify the VM and the container were created and running, you can open a new crosh window (ctrl-alt-t), list the available VM’s, shell into the “wpvm” VM using the vsh command (reminder, this puts you into the VM, not the container) and then check the status of any running containers with:

crosh> vmc list
 wpvm
 termina
 Total Size (bytes): xxxxxxxxx
crosh> vsh wpvm
 (termina) chronos@localhost ~ $ lxc list
 +---------+---------+-----------------------+------+------------+-----------+
 |  NAME   |  STATE  |         IPV4          | IPV6 |    TYPE    | SNAPSHOTS |
 +---------+---------+-----------------------+------+------------+-----------+
 | stretch | RUNNING | 100.115.92.233 (eth0) |      | PERSISTENT | 0         |
 +---------+---------+-----------------------+------+------------+-----------+

To shell into a running container (obviously, the associated VM must also be running):

crosh> vsh wpvm stretch
mark.drovdahl@stretch:~$

References:

https://chromium.googlesource.com/chromiumos/docs/+/master/containers_and_vms.md