A few weeks ago I picked up an inexpensive Chromebook. I’m typing this on it now, in fact. This was my first experience with Chromebook, and my first experience thinking about porting McLaren Labs’ tools onto a Chromebook. At first, I was thinking about wiping ChromeOS and putting Debian11 directly on it. But then I learned about native Linux support on Chrome in a VM.
Crostini is the name given to the Linux-on-Chromebook virtual machine support. To enable it on my chromebook, I needed to open
chrome://flags and enable Linux. Then I rebooted, and in Settings>>Advanced there was a new section called “Linux”. Voila.
Applications that need the Linux environment cause the Linux VM to start. One application is “Terminal” in the main applications menu. Start it up, and there is a full Debian 11 environment there. You can use “apt-get” and install whatever you desire.
What Crostini does really well is the following. The Linux environment is a fairly open container where you can do what you want. The Chromebook environment is well protected and Google has taken great precautions in making sure that the Linux environment cannot corrupt the Chromebook environment.
The VM is well integrated into the Chromebook user experience. Linux Applications are managed on the Chromebook desktop just like any application. Cut and paste between Linux and Chromebook applications is seamless. Audio in Linux is passed through with no problem. External keyboards and mouses work just fine across the whole system.
The Chrome “Files” app can move files between the Chromebook environment and the Linux environment, and there is support for making a shared files area.
Examining the environment some more
Crosh is a terminal-like environment on the Chromebook side where you can perform certain hardware administrator tasks. You can check connectivity and storage, use commands like “uname” and “vmstat”. Open up Crosh on the Chromebook side with CTRL-ALT-T.
One of the most intriguing commands is “vmc” where you can start, stop and manage virtual machines … including the Linux VM. I came back to this command when I was examining USB device support. Vmc has commands “usb-list” and “usb-attach” and I was hoping to use these to attach MIDI devices to the Linux container.
Another interesting command is “CRAS”. This command allows you to alter or manage properties of the “CrOS Audio Server.” I didn’t investigate this.
Some other useful places to look for information are in the “chrome://” options.
and for a list of all of them,
Examining the Crostini (Debian 11) MIDI environment
ALSA is installed (or can be) and I started by installing alsa-utils, and some ALSA /usr/share/ files (like test audio files).
- sudo apt-get install alsa-utils
- sudo apt-get install libasound2-doc
From there I could use some basic ALSA utilities to examine the MIDI router and the audio player.
- aplay /usr/share/sounds/alsa/Front_Left.wav
- aplay /usr/share/sounds/alsa/Front_Center.wav
These both worked just fine, and audio played out of the Chromebook from Linux.
I also wanted to test MIDI routing with an onscreen virtual piano keyboard.
- sudo apt-get install vkeybd
And then used commands
- aconnect -i -o -l (to see devices)
- aseqdump -P 130:0 (to watch MIDI events from vkeybd)
These worked fine, and pressing keys on vkeybd created MIDI events viewable on the output of aseqdump. In fact, since this Chromebook is a touchscreen, vkeybd easily responded to touch events for playing. That is kinda neat: the touches on ChromeOS are being passed through transparently to the Linux app on the ChromeOS screen. Nicely done.
Next, I ported McLaren Labs
rtpmidi program to the Debian 11 environment. It compiled and ran just fine. I was able to connect to a Mac with an attached MIDI keyboard and send and receive MIDI events over
rtpmidi to the Linux Debian 11 VM on the Chromebook. I did not need to set up any special UDP ports or configure any networking. It “just worked” and connected the outside world of UDP packets on the network to the inside world of the ALSA MIDI router.
Even more impressive (to me at least) was the way it picked up the Google “Material Design” styling of the Chromebook. McLaren Labs
rtpmidi running from the Linux sandbox looked just like a Chrome application. Very nice! The Touchscreen behavior of
rtpmidi (a GTK3-based interface) was about the best I have seen, by the way.
Plugging in external MIDI devices
Alas, there does not seem to be a way (currently) to plug an external MIDI device into the USB of the Chromebook and have it pass through events to the Linux environment. (I tried many things).
There is a flag concerning enabling web midi. My understanding is that this determines whether or not external MIDI is passed through to ChromeOS. I tried disabiling this to see if that enabled Linux MIDI. It does not.
It seems that there are a number of people interested in passing hardware MIDI through to the Crostini Linux container. The issue is tracked here, and has a number of subscribers.
If you are also interested in this feature, that might be a good place to express your interest.
Other USB devices
Some serial USB devices are supported and get passed though to Linux. I plugged an ESP8266 Thing Dev into the USB and it was passed through to Linux. When the device is plugged in, ChromeOS Presents a dialog asking if you want to connect it to Linux. This all worked great. Good news for Arduino development on the Chromebook in Linux.
For good measure, I investigated whether a Bluetooth MIDI keyboard would pair with the Chromebook. I didn’t have any success with that.
I am really enjoying my experience with my Chromebook and my Linux container. The ChromeOS side gives me security for email, and secrets. Google docs work great too. The Linux side gives me an open environment with sudo access for me to do as I please. However, the limitation of not being able to connect USB MIDI devices is a problem.
If your target is the development of Linux applications that need networking and cloud connectivity, you’re probably alright in this environment. But if your interests involve Physical Computing and you have a need to connect to external devices (like MIDI keyboards or GPIO pins) then this sort of Linux running in a VM is not for you.
How is MIDI currently implemented on the Chromebook? There is a service, called “midis” (https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/midis) that uses the ALSA Seq interface to get notified about new devices added to the system. For each device added, a listener is created that shuttles events from ALSA Seq in the Chrome OS to various environments. (These include an Android execution environment and the browser-based Web-MIDI environment.)
This is pretty smart: the existing ALSA support for USB MIDI devices is well utilized. The question, then, is how MIDI support should be enabled for the Debian VM.
One way to do it would be to extend the above architecture and send MIDI events into the user-space of the Debian VM. A small daemon could re-emit MIDI events received by the external devices without a change to the kernel.
When devices are plugged into the Chromebook, the events could appear as ALSA Seq devices in the Debian environment by implementing something akin to “midis” there.
A different approach would be to allow the user to specify which USB devices get connected to the Debian Environment directly. Once a USB device is detected, the user could be presented with a dialog asking if they wanted it to be connected to Linux … the same way that USB serial devices are.
I’m not sure I have a strong preference right now. The first alternative would suffice for getting NoteOn/NoteOff and Control messages, but might suffer by not having accurate timing. The second alternative might be more true to the Linux architecture, but wouldn’t provide a mechanism for sharing MIDI devices across the environments.
Interesting to think about.