How to configure Linux, Steam In-Home Streaming and PS4 Controller on Chromebook

It has been a long while since the last time I update my blog. I guarantee that I don’t just waste my time on watching videos and playing video games lol.

Why another post on this topic?

There is a bunch of guides on the web about setting up Linux on Chromebook, Installing Steam and using PS4 Controller on Linux, but no single article covers these topics together. And it turns out a little tricky to get all the thing done right. Also, some of these journals are outdated so far. And this one should provide you enough information to configure all these stuff without a headache. I’ve done all these on Asus CBE-431, it should also work on other models.

Install Linux with Crouton

It is also possible to make a dual-boot Linux-ChromeOS on your device, but Crouton really provides a safe and efficient enough system to get things done. You can switch between two OS swiftly and the loss of performance is negligible.

To do this, you should first get into Developer Mode. This will wipe out all the local data on your device. Be sure to backup all the files you need before any further actions. And then follow these steps:

  • Turn off your laptop, using the combination of Esc, Refresh and Power buttons to reboot your Chromebook into Recovery Mode.
  • After seeing the Recovery Mode screen with the yellow exclamation, press Ctrl+D. And then press Enter to confirm entering Developer Mode. Wait a little while (about 10 minutes) until it return to the screen with the yellow exclamation. Leave it alone until it reboots into Chrome OS.
  • Some old models have a physical switch that you’ll have to flip in order to turn on Developer Mode. Check your instruction if you are not sure.

After login to the system, download the crouton script from here or click this to download the latest version.

Open a shell (Ctrl+Alt+T, type shell and hit enter), and run the following command:

1
sudo sh ~/Downloads/crouton -r trusty -t xfce

# or add other targets if you like
# sudo sh ~/Downloads/crouton -r trusty -t xfce,keyboard,audio,cli-extra

You can also change xfce to other desktops you want, for example unity which has a better look but requires more performance. And you can also add other targets such as keyboard,audio,cli-extra after xfce if you need.

Ubuntu 14.04 Trusty is used, because the default 12.04 Precise could cause some trouble while installing steam.

In the end of the installation, you will be asked the user and password for your linux system, choose anything you want. Remember the password, it will be used a lot later on.

Install Steam on Ubuntu

First login to ubuntu by entering enter-chroot in the shell and startxfce4 to start the xfce desktop (use other command for other desktops). Notice you can switch between Ubuntu and ChromeOS with Crtl+Alt+Shift+Left/Right(at the top of the keyboard) in any time.

And then, download the latest version of Steam for Linux from the Steam website. Start the terminal in linux, and install Ubuntu Software Center with the following command:

1
# You need to enter your password using sudo
sudo apt-get install softeware-center

After that, find and click the Steam .deb package and install steam following the instructions. You should be able to login and launch Steam after this.

In-Home Streaming

Brismuth has a very good post on this topic. I just followed his steps. The ports used by Steam In-Home Streaming is by default blocked by ChromeOS. To unblock them, using the iptables command is the simplest way. First, install this command with sudo apt-get install iptables in the shell.

And then create a new alias command to unblock all the ports needed:

1
echo "alias steamStream='
sudo iptables -A INPUT -p udp --dport 27036 -j ACCEPT; 
sudo iptables -A INPUT -p udp --dport 37804 -j ACCEPT; 
sudo iptables -A INPUT -p tcp --dport 37804 -j ACCEPT; 
sudo iptables -A INPUT -p tcp --dport 27036 -j ACCEPT; 
sudo iptables -I INPUT -p udp --dport 27031 -j ACCEPT; 
sudo iptables -I INPUT -p udp --dport 27036 -j ACCEPT; 
sudo iptables -I INPUT -p tcp --dport 27036 -j ACCEPT; 
sudo iptables -I INPUT -p tcp --dport 27037 -j ACCEPT;'" >> ~/.bash_aliases

Restart the terminal, you will be able to unblock the network with steamStream command. And make sure your host device and your chromebook are on the same network. You should be able to stream from your PC to your chromebook right now.

Setup Sony Dualshock 4 Wireless Controller

I really like the PS4 controllers, you can now use them on almost every devices - your PS4, PC, Mac and Linux. To use them in Linux on Chromebook, I think the best way is to use the ds4drv package.

To install this package, we must first install all the dependencies:

1
sudo apt-get install python2.7-dev
sudo apt-get install python-setuptools
sudo apt-get install bluez-utils

And then install ds4drv by sudo pip install ds4drv.

After this, you can pair your controllers. First, turn on the bluetooth on your chromebook in chromeOS, and then switch back to Linux, entering sudo ds4drv in the terminal. Pair the controller by press the share button and PS button together, the light in front of the controller should start blinking, and turn bright blue after successfully paired.

You can also check how to pair multiple controllers and set the light on the controller on ds4drv website.

I’m having trouble with using the the PS4 controller in Big Picture Mode this way. I will update if I managed fix it.

Enjoy!

Every time you want to use this setup, you should

  • open up Ubuntu in the shell and start desktop
  • Unblock the ports with steamStream in the Linux terminal
  • Launch Steam on both chromebook and host machine
  • Make sure your bluetooth on the chromebook is enabled and pair the controller after sudo ds4drv commmand
  • Start streaming!

Simple Proxy by SSH Tunneling

It is unbelievable that some friends with their own VPS don’t know about SSH tunneling. This is a far more easy way to set up a proxy.

1
ssh -D port username@server

This command will open up a ssh tunneling service and listen to the local port. So you can just set proxy adress in your browser to localhost:port and everything is done!

Have fun!

sudo brew - Do not Try and How to Recover

If someone tries to use brew with sudo, a warning will show up:

1
Error: Cowardly refusing to `sudo brew [option]`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

Well, you may continue to run it after use sudo -i, but you will laterly have many problems. While brew is running under root, it will change the ownership of folders like /usr/local/include to root. And later if you want to run commands like brew link, you will fail:
1
Error: Could not symlink include/gdbm.h
/usr/local/include is not writable.

To recover this, you must change the ownership back:
1
sudo chown -R $(whoami) /usr/local/include
sudo chown -R $(whoami) /usr/local/lib

And remember: Do not try sudo brew the next time.

Static Server in Node.js

From time to time, I need to host some static files to do some local jobs. One possible solution is to set up the config file of the server engine (eg. apache, nginx). However, you need to restart the engine or reload the config file, and you may encounter really annoying some errors. Recently, I found node.js server function is quite useful in doing such things. You can easily set up servers on different ports and easily change the path. Here is the simple code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//server.js
var http = require('http');
var parse = require('url').parse;
var join = require('path').join;
var fs = require('fs');

var root = __dirname + '/public';

var server = http.createServer(function(req, res){
var url = parse(req.url);
var path = join(root, url.pathname);
var stream = fs.createReadStream(path);
stream.on('error', function(err){
res.statusCode = 500;
res.end('Internal Server Error');
});
stream.on('data', function(chunk){
res.write(chunk);
});
stream.on('end', function(){
res.end();
});
});

server.listen(3000);

Just put your files in the \public folder and run node server.js. All things are done! You can check them out on localhost:3000.
A more elegant way is to utilize the pipe() mechanism:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//server.js
var http = require('http');
var parse = require('url').parse;
var join = require('path').join;
var fs = require('fs');

var root = __dirname + '/public';

var server = http.createServer(function(req, res){
var url = parse(req.url);
var path = join(root, url.pathname);
var stream = fs.createReadStream(path);
stream.pipe(res);
stream.on('error', function(err){
res.statusCode = 500;
res.end('Internal Server Error');
});
});

server.listen(3000);

Very easy isn’t it?

Convert Anki Flashcards into Gitbook

Anki is a great flashcard tool for memorizing new words, and here how to convert the flashcard desk in anki to wordlists in pdf, epub and html. This procedure is done on Mac OSX 10.10, and probably work similarly on other Unix system.

Recently I’ve been working on GRE vocabulary, and Anki is a well-known multi-platform app for this. There are many great sets of cards and sometimes you just want to use them else where such as creating some wordlist. And this time, I need some wordlists from GRE3000, a popular book in China. I bought the printed version, but it is in alphabetical order. Luckily someone has made an Anki desk for it!

The vocabulary desks .apkg files are just .zip packages, you can just unzip it with command line:

1
unzip the_desk_name.apkg

There are several files there, what we need is the .anki2 file which is basically a sqlite database. Change the extension to sqlite and you can do anything with it! I just open it up with the Firefox extension - SQLite Manager.

img SQLite Manager

Run the following SQL query to get the data we need, and then save it as csv(with or without header).

1
SELECT sfld, flds FROM notes

Then we need to set up the gitbook engine. Firstly, nodejs and npm is needed, following the guide on the website. And then install gitbook-cli and initialize a project.

1
npm install gitbook-cli -g
cd your_workspace
mkdir book
cd book
gitbook init
cp list.csv .

And then, I wrote a ruby script to generate the markdown files needed to create the book.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'csv'

#size of the wordlists
list_size = 20.0
words = CSV.read('list.csv')
words.delete_at(0) #if there is a header line
words = words.shuffle



summary = File.new('SUMMARY.md', 'w')
summary.puts "#Content\n"

for i in 1..(words.length/list_size).ceil
file = File.new('./src/List'+i.to_s+'.md', 'w')
file.puts "#List#{i}"
summary.puts "* [List#{i}](src/List#{i}.md) "

#you might need to change this part to fit different desks
for i in 1..list_size
file.puts "\n\n---\n\n" unless i == 1
content = words.shift()
if content.nil?
break
end
file.puts content[1]
end
file.close
end

summary.close

Save this script and execute it at the folder. And don’t forget to write something in the README.md. Now you can use gitbook serve to see the web version of the book.

To make a file version, we need to download and install Calibre and use the ebook-convert tool inside. For Mac OSX, we need to add the tool to the $PATH.

1
export PATH=$PATH:/Applications/calibre.app/Contents/MacOS

Finally, we shall compile the book!

1
cd ..
gitbook epub /book

And then you’ll see the book inside your work folder.

Have fun!