Sunday, September 28, 2014

Chromebooks Ain't Fer Grandmas!

Earlier this year, sometime around February, my laptop had some sort of existential crisis and fell apart at the hinges!  The screen hinges literally broke separating the screen from the body of the laptop.  To make matters worse I was on a business trip in London.  Thankfully, the cabling didn't break and I was able to prop the screen up and get through the trip.  Though I did look pretty ridiculous and a tad ghetto-fab to boot.
Left hinge gone, right hinge broken and bezel de-bezeled!


Unfortunately, it was my one and only lovable laptop.  An awesome bulky, heavy, hot runnin' Dell Latitude E5500 with a screamin' install of Ubuntu.  It was my work, dev and play deck and it was a goner!

While I waited on replacement hinges, a screen frame and a spare screen (just in case I screwed up the original screen doing the repairs...yeah I repair my own hardware...the OG scrooge mcduck here...), I couldn't help but wonder what might be out on the market in terms of new linux laptops.  To my utter dismay nothing very good.  Mostly big, bulky, black behemoths and all of them were quite costly.

Having heard a lot of online chatter about Chromebooks, I decided to go take a look.  They all looked pretty bad ass.  The only problem, Chromebooks run Chrome OS which is a pretty limited cloud based operating system.  Or so I thought!


After a little research I had determined that Chrome OS is just Gentoo linux locked down for GrandmaLand.  For those that don't know, GrandmaLand is kinda like Userland and Candyland mashed up.  It is very limited but chock full of all kind of sweet goodness!  I saw a few articles about putting a Chromebook into developer mode and some articles that went even further about putting a Chromebook into the full Gentoo image via dev_install.

These articles had me hook line and sinker!  I love a good challenge and I love a good adventure even more!  So, in March 23, 2014, I purchased an HP Chromebook 14 for $349.

Check out the specs here.  My fav bits are...

  1. Beautiful 14" display.
  2. Sleek .81 thin and 4.08.lbs design that is routinely mistaken for an Apple device.
  3. 9.5 hours of battery life!
  4. < 7 second boot but you rarely have to turn these things off or reboot them.
  5. Wifi and 4G LTE.  The baked in 4G LTE is rad!  I can develop, deploy, work and play ANYWHERE!  Hello beach! Hello skate park!  Hello anywhere!
Things I was worried about...but then realized...
  1. 16 GB SSD 
    1. If you need more than 16 GB locally get an SD Card OR use a USB thumb drive.
    2. Hardware hack and put in a larger SSD if you don't mind voiding your warranty!  Future blog post!
  2. 4 GB RAM
    1. Should suffice for most uses.
    2. Hardware hack and put in more RAM if you don't mind voiding your warranty!  Future blog post!
Since March 23, 2014 I have used this HP 14 Chromebook as my primary work, play and development machine.  

YES, DEVELOPMENT MACHINE!

Chromebooks actually make a nice affordable development machine.  There are some interesting advantages like:
  1. Cheap.  If you lose it you aren't out a couple or a few thousand dollars.
  2. Thin and light and don't run hot.
  3. Once in developer mode, if you lose the Chromebook and someone boots it they will likely press the space bar on boot which will wipe the drive.  Kind of like built in IP protection!  More on this later.
Which brings me to my point.  Chromebooks are not the student, grandma, casual user computers everyone is being led to believe.  Nope, in fact they can make wonderful and powerful development machines.

In fact, I am going to show you how to put your Chromebook in developer mode and setup your development environment for Python, Ruby, Node, Meteor, MongoDB and Java.  In another blog post I will explore putting a Chromebook into the full Gentoo image via dev_install and all the goodness that comes from having the Gentoo portage package manager at your disposal!

Step 1 - Make A Recovery Image

The first thing you will want to do is make a recovery image on a USB thumb drive.  Make sure the thumb drive is greater than 4 GB.  There are a few ways to do this.

Easiest - chrome://imageburner

Before you mess with your Chromebook use the image burner.  Open up Chrome and go to chrome://imageburner/

Medium Difficulty - Chrome Recovery Utility

This works from any Chromebook.  So, if you totally hose your Chromebook you can do this from any other Chromebook around.  Yep, even the ones at Best Buy...trust me!  Just go to Use the Chromebook Recovery Utility

Expert Level - Mac or Linux Restore

I have done it this way a couple of times successfully and a few times it didn't work.  I have only used the linux instructions because I don't use Crapples.  Just check out the Mac or Linux instructions here Restore your Chromebook

Ok, so now if you hose your Chromebook you can always recover it!  Hopefully.

CAUTION

Going any further could damage your Chromebook or void your warranty.  

They are only a couple hundred to a few hundred dollars so WHO CARES RIGHT?!?!

Step 2 - Putting Your Chromebook Into Developer Mode

First, read Poking around your Chrome OS Device.  Device?  Yes, device.  You can put the beautiful new LG  Chromebase (got 2 of these for point of sale systems for my stores) into developer mode or any of the host of the Chrome Boxes (using these are media devices in my home and as primary computers in my store).

Second, read Developer Information for Chrome OS Devices to find specific instructions on how to put your device into developer mode.  I have the HP 14 Chromebook and used these instructions which actually lead you to the Acer instructions.

Most Chromebooks can be put into developer mode by pressing ESC-F3 (refresh) and the power button.

So, tempted to press SPACE.  So tempted!
You will be prompted to turn off Chrome OS verification and might see a screen that looks like this.  On most systems you just press CTRL-D to put the device into developer mode.  You may see some ASCII notifications about the process at the top of your screen with a percentage or progress type indicator about the process.  Every time you reboot you will see this screen.  


You have to press CTRL-D to get into the computer.  If you press SPACE your device will be power washed and your data wiped clean.  Which I think is a nice security feature actually.

Step 3 - Making the Chromebook Useful in Developer Mode

Ok, so now you are in developer mode.  Big deal.  

First, there are two terminals.  

There is VT-2 or virtual terminal.  You can get to it through CTRL-ALT- -> (above the #3 on most keyboards).  Personally, I don't find this terminal very useful on a day to day basis.
Then there is a terminal command prompt through CROSH (Chrome Shell).  Press CTRL-ATL-T to get to CROSH.  I don't find CROSH all that useful on a day to day basis but it is the only way to get to a standard terminal interface and BASH. Anyway CROSH looks like this.  If you are curious about what commands are available just type help.

Moving on, in CROSH just type shell and you will be greeted with a familiar GNU bash shell with all kinds of goodies.  Just type help and take a gander!  
GNU to you too!

But the Chromebook still isn't that useful.  Why?  Because the file system is still locked down.

The easiest way to make the file system writable is to use the following command.

sudo /usr/share/vboot/bin/make_dev_ssd.sh --force --remove_rootfs_verification

You will see something semi-terrifying like...

chronos@localhost / $ sudo /usr/share/vboot/bin/make_dev_ssd.sh --force --remove_rootfs_verification

      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      ! INFO: ALL SANITY CHECKS WERE BYPASSED. YOU ARE ON YOUR OWN. !
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      
Start in 1 second(s) (^C to abort)...  
Kernel A: Disabled rootfs verification.
Backup of Kernel A is stored in: /mnt/stateful_partition/backups/kernel_A_20140928_152145.bin
Kernel A: Re-signed with developer keys successfully.
Kernel B: Disabled rootfs verification.
Backup of Kernel B is stored in: /mnt/stateful_partition/backups/kernel_B_20140928_152150.bin
Kernel B: Re-signed with developer keys successfully.
Successfully re-signed 2 of 2 kernel(s)  on device /dev/mmcblk0.

WE DON'T NEED NO STINKY SANITY CHECKS!!!  

BTW, I have no idea what happens if you press ^C during this process.  It says it aborts but who knows what the outcome is.

NOW RE BOOT!!!

PRO TIPS
  1. Sometimes you have to use this command after rebooting or applying a chrome update.  Chrome updates are not automatic.
  2. Delete these backups from /mnt/stateful_partition/backups/  otherwise they will eat up drive space.  A Chromebook that runs out of drive space is a painful experience.
Finally, it would be nice to easily make all mounts writable.  So, do the following.
  1. Go to CROSH CTRL-ALT-T
  2. Go to GNU Bash shell by typing shell and type
    1. sudo su -
    2. mount -o remount,rw /
    3. mount -o remount,exec /mnt/stateful_partition
    4. sudo vi /sbin/rw
Here is the rw script

#!/bin/bash
echo "Making FS Read/Write"
sudo mount -o remount,rw /
sudo mount -o remount,exec /mnt/stateful_partition
sudo mount -i -o remount,exec /home/chronos/user
echo "You should now have full Read/Write access"
exit

Make sure you make the script executable.

sudo chmod a+x /sbin/rw

Now on most reboots and most Chrome OS updates you can just type sudo rw to make your system read write!

Now you can really do ANYTHING!

Step 4 - Setting Up Your Development Environment

Chromebrew aka crew

Chromebrew is to Chrome what Homebrew is to Crapples!  Well not exactly, it doesn't quite build packages locally but it does help you do some heavy lifting.  

So, if you want a fast way to get things like binutils, buildessentials, curl, gcc, git, glibc, linuxheaders, libssh2, make, perl, python, ruby, vim and zlibpkg among a host of other important linux packages then install Chromebrew.

Here is how you can install it.
  1. Chromebrew the missing package manager for Chrome OS page 
  2. or wget -q -O - https://raw.github.com/skycocker/chromebrew/master/install.sh | bash.
  3. From there you can search and install packages or update crew itself!
  4. Or view the packages on github
Crew alone gets you perl, python, ruby and even node.  

Though many times I install node on my own so that I can control the version and there are instructions below.

Ruby

See Chromebrew above duh!

Node & npm

So simple...
  1. Get whatever version of node you want at http://nodejs.org/dist/
    1. For example: wget http://nodejs.org/dist/v0.10.31/node-v0.10.31-linux-x64.tar.gz
  2. Untar it to ~/ and then rename the directory if you want to.  I rename mine to ~/node
  3. Link up your binaries like so
    1. sudo ln -sf /home/chronos/user/nodejs/bin/node /usr/bin/node
    2. sudo ln -sf /home/chronos/user/nodejs/bin/npm /usr/bin/npm

PRO TIP

Change npm prefix config so npm installs packages outside of root.  Otherwise it will install them to /dev/root and you will run out of drive space really quickly.  

I called mine npmprefix and located it at ~/.  

npm will then install things in npmprefix/lib/node_modules and npmprefix/bin

Edit and change the npm prefix location in your npmrc

vi ~/.npmrc 
prefix = /home/chronos/user/npmprefix

Now you have node and npm and you can update it whenever you need to or install different versions alongside each other.

MongoDB

I use MongoDB quite a bit.  Installing it on ChromeOS is a breeze.  
  1. Download the tar from here.  I use the 64-bit version.
    1. It will download to your ~/Downloads directory
  2. Untar it to ~/ and then rename the directory if you want to.  I rename mine to ~/mongodb
  3. Then just link up the binaries like so.  ls bin to see all the binaries.  These are the ones I use most often.
    1. sudo ln -sf /home/chronos/user/mongodb/bin/mongorestore /usr/bin/mongorestore
    2. sudo ln -sf /home/chronos/user/mongodb/bin/mongodump /usr/bin/mongodump
    3. sudo ln -sf /home/chronos/user/mongodb/bin/mongo /usr/bin/mongo
Not only do I work with MongoDB locally, but I routinely dump and restore production databases from and to my Chromebook!

Java JDK

Ok, this should be pretty familiar to everyone.  
  1. Download the JDK you want at http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html
    1. Personally I use the 64 bit one.
  2. Many people run more than one version of Java.  If you do then create a ~/java directory and move and untar the jdk there.
    1. mv ~/Downloads/jdk<version>tar.gz ~/java
  3. If you are only running one version you could just untar the jdk to ~/ and rename the directory to ~/java to make the rest easier.
  4. Add the JDK to your PATH and set your JAVA_HOME  Here is mine as an example.
vi ~/.bashrc 
export PATH=$PATH:$HOME/npmprefix/bin:$HOME/java/jdk1.8.0_20/bin
export JAVA_HOME=$HOME/java/jdk1.8.0_20/bin/java

Meteor

Say what?  

You mean the pure javascript, live page updating, real-time synchronizing, latency compensating, hot code pushing, interoperable pimpin framework can run on a Chromebook?

Yep.  With one line.

Make sure you are at ~/

In fact, type cd ~/ just to be sure because many times when you CROSH to shell you are dumped into / rather than ~/.  

Meteor MUST be installed in your home directory.

Type...wait...you ready for it....

sudo curl https://install.meteor.com | /bin/sh

Want to make sure it worked?  Type the following commands in shell.
  1. meteor create ~/my_cool_app
  2. cd ~/my_cool_app
  3. meteor

PRO TIP

I suggest you put your projects in ~/Downloads.  Probably something like ~/Downloads/projects or something.  

Why?  

Well, because most Chrome apps cannot reach the file system outside of the ~/Downloads directory.  That means Chrome based editors and IDEs.  

What else?

What else do you need?  

You now have perl, python, ruby, node, java and Meteor and MongoDB as a database.

I haven't tried installing other database systems like postgres or mysql but I suspect it is possible.  

For example, I installed Apache Ant the other day without a hitch.

Oh yeah, this of course leads to the question, "What do I use as an IDE?"

Duh vi or vim!  

Just kidding.  Though they work great combined with shell commands because in ChromeOS each terminal is just an open tab in the Chrome browser!  I use them quite often for quick stuff or when grepping around.

Though, I know you want a REAL editor or IDE, so lets move on.

Step 5 - IDE & Editors

Personally I haven't tried running Eclipse or something similar because I am not a big fan of full fledged IDEs but I suspect you could get it to work.

There are plenty of cloud ones like Code Envy, Espruino, CoffeeScript IDE, JetBrains, Shift Edit and dozens of other web based or cloud based IDEs.  

Personally, I don't want to be forced to edit in the cloud.  Quite often I find myself working on a plane and quite often they don't have WIFI.  With built in 4G LTE in some Chromebooks you don't really worry about WIFI otherwise.  

First, almost all of the editors are based on ACE.

On a daily basis I tend to use Caret.  It is very similar to Sublime Text.

I also use Zed from time to time.  It is a powerful distraction free full screen editing.  Unfortunately, I am the kid of person that needs to see my directory and file structure to remember where things are or how they work!

Tailor is a very lean editor.  Though I don't find myself using it often.

Tedit is an interesting one because it focuses on projects being git repositories locally with remote support and supports symlinking from the editor.  Personally, I haven't gotten used to this editor yet.

Finally, Google even has an editor called Chrome Dev Editor is a developer tool for building apps on the Chrome platform - Chrome Apps and Web Apps, in JavaScript or Dart. CDE is built as a Chrome App written in Dart and uses Polymer. CDE runs on Windows, Mac, Linux, and Chrome OS! CDE supports Git, Polymer, and mobile development.   A few weeks ago I tried Chrome Dev Editor and it sucked.  The most recent version is very similar to Ace, Caret, Sublime Text and definitely deserves another look. 

Step 6 - What About Image Editing?

First, most of the time you don't need photocrap or any bloated application.

Second, use CSS as much as you can.  Images are so 1990's.

Though, ultimately you will probably have to edit photos or make icons or something.

If you want to use Gimp try Gimp on Roll App, though I suspect you could build gimp locally if you wanted.

There are plenty of image editing programs in Chrome Web Store.  

I tend to use Pixlr and Sumo Paint but there are dozens of various types of image or photo editing applications available.

Step 7 - Have Fun & Build Something Cool!

For between a couple hundred and a few hundred bucks what more could you ask for?

So, go have fun and build something cool!

Summary

So, Chromebooks ain't just for students, grandmas and casual users!  

A properly tuned up Chromebook can make a great development box.  

Since March, 2014 I have been developing two production applications and deploying those applications from my Chromebook.  

What can you do with yours?

9 comments:

  1. Hi,
    Thanks a lot for this tutorial!!
    First I used Chromebrew, but I don't want the packages installed as user.
    I als tried de dev_install. I did a lot, but as a programmer I want control over what is does. ;-)
    So I started looking into gentoo and wanted to extend it manually. Then indeed /dev/root used all of the big 2gg :-(

    Read a lot about partitioning, searched for better options. Tried to misuse Chrubuntu to do the partitioning, but Chrome wont fell into that trick ;)

    Is there a way to enlarge /dev/root ? And have Gentoo/Chrome still running?
    I dont know enough yet to try on my own. And dont have the time to figure it all out for now.

    If i cant find any solution, I will use crouton for now. So I will have linux. But I would love to have a clean and extended Gentoo/Chrome.

    Greetz, Joly

    ReplyDelete
    Replies
    1. I have enough space on the hard disk, about 10gig. But /dev/root gets only 2 which is used for more then 80%.
      I thought this is why you gave this tip about prefixing npm, so packages will install outside the root.

      meanwhile i found that Gentoo-chrome seems too much stripped. Like not having a c-compiler. And i dont have enough experience to go that far yet. So i could not install a simple packages as Nano.

      Delete
  2. Went along fine until installing Mongo and then no space left on device?

    ReplyDelete
    Replies
    1. Not sure why you would run out of space. I have done this on both an HP and a Lenovo without a single problem. Did you make sure you deleted the backups?

      Delete these backups from /mnt/stateful_partition/backups/ otherwise they will eat up drive space. A Chromebook that runs out of drive space is a painful experience.

      Delete
    2. Unfortunately that only freed up 39M. I'm not really familiar w/Linux. /dev/root is 1.2G used (97% full) mounted on / , and /home is using 1.8G of 11G. I can tar Mongo to home, but doing: cd ~/ and then then curl http://install.meteor.com | sh/bin will fail tar with "Cannot mkdir: No space left on device" and /dev/root is back to 100% used.

      Delete
    3. Does your Chromebook have a small SSD? I have only done this on HP 14's and Lenovo Yoga 113. Both have 16GB SSD. What Chromebook do you have?

      Delete
  3. This comment has been removed by the author.

    ReplyDelete