Wednesday, June 8, 2016

Restore a chroot to a different machine

On a chromebook you can set up chroots. This is possible through crouton. Chroots are separated environments that run all your linux software on the same kernel as the host machine. The result is you can take a chroot and copy it to a completely different machine and everything will run as before. That is just a fantastic and super easy way to keep all the environments on different machines in sync. So I routinely copy over chroots from one to the other machine, here is how to do that.

I use a chromebox and a chromebook. The chromebox is faster and has a better internet connection (over ehternet). So I tend to set up the chroot on the chromebox and then copy it to the chromebook. That is actually very easy.

The chromebox becomes the source machine and the chromebook is the target. The first step is to make a backup of your chroot on the source machine.

cd ~/Downloads
sudo edit-chroot -b trusty

Now copy the backup to a medium. I use a USB stick.

cp trusty-datestring-timestring.tar.gz  /media/removable/USB\ Drive/

That datestring-timestring will look like 20160607-2007 or similar.

On the target machine remove the old chroot if the name is the same, otherwise you can leave it there. Then insert the USB Drive and restore the chroot.

To remove the old chroot: sudo edit-chroot -d trusty

I assume you already have crouton on this device if not download it from

cd ~/Downloads
sudo sh -e crouton -r trusty -f /media/removable/USB\ Drive/trusty-datestring-timestring.tar.gz 

That is all. You now have an identical chroot with all your software on the target machine.

I have set up virtual box on the source machine so when I fire up the chroot on the target I get this error.

/etc/rc.local failed with code 2

You can either set up the condition for virtual box (see my post from June 7) or get rid of the error. To get rid of the error make rc.local non executable with:

sudo chmod 644 /etc/rc.local

The error will not reappear. Obviously virtualbox will not be able to start on the target machine.

Written with StackEdit.

Tuesday, June 7, 2016

Setup Chromebook for development

June 7th, 2016.
This how I set up my chromebook, I do some development work, mainly front end and quantitative programming. I share this because some of it is hard to find out. This page owes a lot to a sources, I mention them in the text. All the work on crouton is borowed from David Schneider, but there other sources as well.

Go into developer mode

Depends on the machine on the Asus chromebox depress the reset button (next to the Kensignton lock) and the start the machine, nex release the reset button. After that pres Ctrl-D at the prompt (there is no hint on the screen). A good source for developer mode is:

Install the crouton extension

Crouton is an easy way to get access to a full linux setup on your chromebook, you will find everything you need here:
First install the crouton extension, this is for integration with your browser. You can get it by this link: crouton extension.

Setup crouton

Download crouton (it is a script). You can get it here:
Install crouton via these commands:
sudo sh ~/Downloads/crouton -r trusty -t core,xiwi,keyboard,x11,cli-extra,extension,
     audio,chrome,xorg //add ,xfce if you want a desktop
After it runs you can enter the chroot with sudo enter-chroot, this will get you into Ubuntu.

Setup software in Ubuntu

This section is borrowed from this website: however the setup for nodejs is not functional if you want to use gulp. I have changed that section in the part below.
This part of the set up is done in the chroot, see above.
You may, of course choose, what you want to install, this is just what I figured out and wanted to share.


sudo apt-get install git
Using version control is quite essential.

NPM + NodeJS

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs
Check your version with node -v, you can check you have the most recent on
For other nodejs versions, for example 0.12 use in stead:
curl -L | sudo bash -
and then
sudo apt-get install nodejs
and then to compile and install native addons from npm you may also need to install build tools:
sudo apt-get install -y build-essential
To be able to install packages into global directory, we need to move it under home:
npm config set prefix '~/.npm-packages'
echo 'export PATH="$PATH:$HOME/.npm-packages/bin"' >> ~/.bashrc
//this should work now:
npm install -g bower grunt gulp ember-cli babel

Web starter kit

This is not really software the web starter kit from github on google/web-starter-kit is a template for web (apps). The dowload version of 0.6.3 does not seem to work well the cloned version does.
I found gulp with web starter kit (from google) does not run well with the latest gulp (3.9.1) so you may want to downgrade to 3.9.0. with
npm install -g gulp@3.9.0
This is a solution from Yeoman, see

Sublime Text 3

Sublime is very popular, I am not a fan, I prefer Zed, a native app for chrome, you can get it here:
For sublime follow this section.
sudo apt-get install software-properties-common python-software-properties -y
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
At this it is reccomend installing Nautilus (a file browser) to get full support of gtk windowing system. Sublime fails to launch without it and on top of it, you get a GUI for file browsing. That maye be handy sometimes.
sudo apt-get install nautilus
Now you can launch Sublime with:
xiwi -t subl


sudo apt-get install terminator
You can now launch terminator in a window with:
sudo xiwi -t terminator

Set up for virtual box

You may also want to run virtual box. I took these from the ubuntu/debian ppa for chromebook kernel headers. You can find it here:
Currently supported:
- Kernel 3.4.0 Architecture arm, i386 and am64 ==> These all need
- Kernel 3.8.11 Architecture arm, i386 and am64 ==> amd64 is
tested. i386 and arm needs testing.
- Kernel 3.10.18 Architecture arm
and amd64 ==> amd64 is tested. i386 and arm needs testing.
Open a crosh shell and follow on screen instructions:
cd ~/Downloads
sudo sh ~/Downloads/change-kernel-flags
When running sudo sh ~/Downloads/change-kernel-flags -h it will give you the usage. You may want to revert the changes so put save a backup kernel use -r:
 sudo sh ~/Downloads/change-kernel-flags -r
Note: You will need to repeat the above steps after each chromeos update.
The following is done only once. Open a shell in your chroot:
cd ~

sudo sh
This script will: add a signing key with which the packages are signed, add the ppa to the sources.list.d install linux-headers-, install linux-image-, add a rc.local script to load vboxdrv modules on entering the chroot if they are available.
Kernel headers are build according to this guide kernel headers for arm are cross compiled.
Now go ahead and install virtual box sudo apt-get install virtualbox

Install Rstudio

RStudio needs the latest r-base, not standard available in the ubuntu packages, so you need to add sources first. This method will use the latest development version of R-base from Michael Rutter.

sudo apt-key adv --keyserver --recv-keys E084DAB9 // wil add a key to your keyring
sudo add-apt-repository ppa:marutter/rdev

If you are met with the message: sudo: add-apt-repository: command not found. 
You can install it with 
sudo apt-get install software-properties-common
Then continue.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install r-base
After which you have r-base installed. You can now install R-studio if you like, download it from the Rstudio website and install using the debian package installer (in the GUI) if you have chosen the *.deb version.


Aliases can save you a lot of time and energy. In your .bashrc add some lines, here is a few I use very frequently:
 alias cdd="cd ~/Downloads"
 alias x="xiwi -t"
 alias xw="xiwi -w"
There is also one handy alias that can allow you to get into chroot a bit faster. It has to be stored in .bashrc outside chroot:
echo 'alias ec="sudo enter-chroot"' >> ~/Downloads/.bashrc
And then leave chroot, and move it to the chronos home .bashrc:
cat ~/Downloads/.bashrc >> ~/.bashrc
If you have just added these you need run source .bashrc to activate them.

Setup autostart on Chromebook

Move your crouton script and the backup into the Downloads directory on the machine (as well as all the keys and stuff). Specifically include crouton crouton.init crouton.conf and rw-rootfs.
After reboot run the file rw-rootfs (this is a script < see )
Run this file in the shell (not in the chroot)
like this: sudo sh ~/Downloads/rw-rootfs
It will reboot.
Next copy the crouton.conf file to /etc/init with this:
`sudo cp ~/Downloads/crouton.conf /etc/init/` 
Reboot and it will work. I use this to enter-chroot on startup

Backup and restore chroot

To backup your chroot use: sudo edit-chroot -b nameofchroot
To restore use sudo edit-chroot -r nameofchroot
You can delete a chroot by sudo edit-chroot -d evilchroot
In the event that you want to restore a backup to a stock chromebook (with developer mode enabled) you can use the crouton installer with the -f option specifying the backup’s tarball, e.g.,
sudo sh -e crouton -r raring -f /media/removable/SD\ Card/backup/raring-20130617-1234.tar.gz 

Update the software

When a new version of your chroot comes out you may want to upgrade.
Check for updates, download the latest version, and see what’s new by running croutonversion -u -d -c from the chroot (run croutonversion -h to see what those parameters actually do).
Exit the chroot and run sudo sh ~/Downloads/crouton -u -n chrootname. It will update all installed targets.

After an update of chomeos do

If you have virtual box installed, rerun the script to change the kernel flags. Open a crosh shell and follow on-screen instructions:
sudo sh ~/Downloads/change-kernel-flags
then reboot.
If you have set up autostart, rerun the file to make root writable this in the shell (not in the chroot)
like this: sudo sh ~/Downloads/rw-rootfs. It will reboot.
Next copy the crouton.conf file to /etc/init with this: sudo cp ~/Downloads/crouton.conf /etc/init/ if you have set up autostart.