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:


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

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

crosh> vsh wpvm stretch


Walk the line…endings

Have a file where you want to add a comma to the end of each line?

$ sed 's/$/,/' ip_addresses.txt | head -n2

This should work…but, wait, it didn’t. Instead, it replaced the first character of each line with a comma. Why?


Aha, it is because the file is dos encoded. See the “\r \n”?

$ head -n1 ip_addresses.txt | od -c
0000000 9 6 . 1 2 7 . 0 . 0 / 1 7 \r \n

Ok, so dos2unix comes to the rescue.

$ dos2unix ip_addresses.txt
dos2unix: converting file ip_addresses.txt to Unix format...

And, finally, we have…

$ sed 's/$/,/' ip_addresses.txt | head -n2,,

Wait, not so fast. We actually wanted commas on all BUT the last line and observing the last two lines, we’ve got an extra comma.

$ sed 's/$/,/' ip_addresses.txt | tail -n2,,

So, use “$!” in sed which matches lines which are NOT the last line.

$ sed '$!s/$/,/' ip_addresses.txt | tail -n2,