Tuesday, September 23, 2014

Recovering My Chromebook

The Experiment


I bought a samsung ARM chromebook a year back and after 3 weeks of using chromeos, i got bored. So, i went ahead and did what any sane person would do, try installing Linux on it. Also the lure towards linux on chromebook is specially irresistible if you have to carry a heavy Dell laptop on your back while cycling to college every day.
My initial thoughts were that the installation process would be very similar to installing new ROM's on Android devices. But boy was I wrong.
My goal was to install a flavor of Linux to completely replace the chromeos. That is no chrooted xfce or dual booted ubuntu.

There are number of options out there that would allow installation of Linux on chromebook.
1. Installing Debian : https://wiki.debian.org/InstallingDebianOn/Samsung/ARMChromebook
2. Installing Arch :  https://wiki.archlinux.org/index.php/Samsung_Chromebook_(ARM)
3. Installing Kali Linux: http://docs.kali.org/armel-armhf/install-kali-samsung-chromebook

And I am pretty sure there are many more. Options 1 and 3 provide you with a SD card and a USB stick image that can be written onto the devices. After that the USB can be plugged into the USB-1 of the chromebook and rebooted to enter the OS of your choice. But the idea of a USB sticking out of my device never found favor with my heart(and also the fact that those images failed to boot my chromebook).

Installation of Arch Linux on the other hand proved very helpful. Creating a boot-able image using the tutorial work well on USB's, but there seems to be problems when I used it with a SanDisk 8gb and 16gb SDHC(some comments online suggested that the Kingston SDHC's were good for the task.). Now after we created a boot-able SDHC, the rest of the instructions are on moving the contents of the SDHC to the eMMC. But this is the step where things get really sketchy in terms of instructions that we can find on the internet. I tried a few sites for weeks with partial or no results.
1. You need to flash your chromebook's 'rw' SPI with nv_uboot.
2. Create boot/u-boot partition in eMMC
3. Create root partition in eMMC
4. update settings in the new nv-boot to boot the eMMC.

Better read the arch link shared above as it covers these steps in detail.

Anyways, if the steps above do not work out, you will most probably be in a state of frustration with you device not being able to recover to chromeos. So steps below will describe how to recover back to chromeos.


Way Back To Recovery

This is a solution for people who are stuck with nv-uboot(non verified u boot) and cannot seem to get their system recovered using the recovery USB. This is because nv-uboot is not signed by google and the recovery USB checks if the flash on the chromebook contains original google verfied flash. So reverting the SPI flash image to a google signed uboot image will allow recovery of the system.

This is the solution to write back the 'rw' region of SPI with the original chromeos firmware. If you already have a backup of you old SPI flash then you can go ahead and write it down already and boot with the recovery stick to get back your chromeos.

If you have lost the SPI flash backup(like i did) that you were supposed to take, then you need to do the following to obtain it.

Download the linux_recovery.sh for linux and run it.
     a. Type in 'SNOW' at the image prompt. This will list the list of devices with their market names.
     b. For samsung chromebook select 'Samsung ARM Chromebook'.
     c. The recovery tool will then go ahead and download the image(mostly to /tmp/tmp.somevarcharstring). You can stop the recovery process as soon as the download is over as all we need is the image.
     d. Now we need to load the image

           losetup -P /dev/loop0 <bin file>

            WARNING: If it says that -P options is not recognized, then chances are that you are on a ubuntu derivative and need to update utils-linux. But downloading the utils-linux source code and installing it could make break your installation, so better do it on a virtual machine.
     e. Once the losetup executes without error mount the partition 3 of the chromeos image using the command

           mount -o ro /dev/loop0p3 /mnt/somewhere

     f. Then run the command

           /mnt/somewhere/usr/sbin/chromeos-firmwareupdate --sb_extract /tmp/placetoextract

      g. In the extract location you will find the extracted blob files, search for a file ending with rw.bin. This is the SPI flash image that we want.
     h. As long as you can boot into chromebook using a bootable usb, you can flash the SPI using flashroom-google. Use the command.
          flashrom.google -p linux_spi:dev=/dev/spidev1.0 -r origial_image-snow.bin

            Replace origial_image-snow.bin with the *.rw.bin that we extracted above.


After the above work, you can reboot chromebook with the recovery USB and follow the steps to complete the recovery.

Tuesday, May 27, 2014

Dual Monitor Setup and Linux


Dell XPS - l502x and 19'Dell monitor

The l502x, where can I start ? Most days I love it, the other days I loathe it. I spent more on it than a MacBook air would cost, and I did not get the high screen resolution, light weight or battery life. Things that are proving very important as I am concentrating more on development. But what I did get is a Nvidia GPU and JBL speakers(which are awesome btw). And all this I can live with, especially given that it can run games on Windows 7 like a boss. But then Nvidia had to go and add Optimus technology to it and not provide support(sketchy support) for that in Linux. And Linux being my primary OS, it makes me hate by little machine sometimes.

So, now I go ahead and buy a monitor so that I could have more screen real estate. Got a cheap 19 inch monitor for 40 euros. The monitor has a VGA port only and the lappy has HDMI and mini display ports.  Now I for one did not know that the small pesky port was a mini display port and went ahead and bought a VGA to HDMI convertor and a HDMI cable, 30 more euros down the drain. And did it work ? No. Neither Linux nor Windows seem to detect it. Tested all PnC and the bottom line was that by Nvidia which owns the HDMI port on my lappy was not ready to accept my monitor for output. 

So after some head banging on the Internet, I decided that the mini display port was the way to go. So I bought another mini display port o VGA converter. And it worked from the get go. No new packages need to be installed, no new drivers need to be installed, nothing. I could even have bumblebee installed and do my power saving for the laptop.

So, for this setup, just get a mini display port to VGA converter.

Multiple Screen Wallpapers

To get the multiple-screen wallpapers going on Linux, install nitrogen. The thing is pretty self explanatory and does not need much sorcery. You can refer to the description here. (However, there seems to be some bug with nitrogen and crashes after some random time.)

Screen resolution

In case I am travelling and my native resolution does not provide me with much real estate on the screen, I use the software called newrez developed by Marc. This can be accessed from here. This is again a simple program and pretty easy to use.
The site does say that it supports dual monitor, but I was getting errors on running it for multiple monitors. But the code is readable in newrez file. One can always debug that to get it to work on dual monitors.


Conky

On multiple screens conky is again difficult to use. I found a cool config here. While running this, conky was crashing on my. So I had to compare the default config(this was working for me, /etc/conky/conky.conf)  with the new config from noobslab. The variable "own_window_type override" turned out to be the culprit, so I had to comment that out.

But then conky was getting printed in the middle of the second monitor. This can be solved by changing the value of gap_x and testing it till you get it placed in the desired location.

Terminator

I was also looking for some cool themes for my terminator window. 
First off I needed to add the cowsay|fortune|toilet combo that would print a output as below whenever the terminal was opened.

I then wanted to have a terminator color scheme that was better than solarized(though this is pretty cool, it feels out of place in backgrounds where the colors are bright like green, yellow, etc). On wandering the Internet I  stumbled upon this site, where you can adjust the color settings to get a terminator theme of your liking. The changing of settings takes a little time to getting used to(just make sure that the column before the column 40m is pretty neat, that would take care of most of your daily terminal views). Once the settings are to your liking, click get scheme, select "terminator" and you have your config file generate. Add the generated config to ~/.config/terminator/config file under "profiles". My config looked like this.

  [[4bit-dirty-yellow]]
    scrollbar_position = hidden
    palette = "#363b2c:#731f34:#3e780f:#73520f:#194469:#4d1f69:#197843:#868b7c:#545949:#8a1f3e:#488f0f:#8a610f:#194e80:#5b1f80:#198f51:#909686"
    background_color = "#e6ac2f"
    background_image = None
    foreground_color = "#363b2c"

The code for terminal prompt.

#! /usr/bin/python
import os; 
import random;

#Get the list of files in the cows location !!
var1 = os.listdir("/usr/share/cowsay/cows");
var2 = ["-b", "-d", "-g", "-p", "-s", "-t", "-w", "-y"];

#Generate a random
rand1 = random.randint(0,len(var1)-1);
rand2 = random.randint(0,len(var2)-1);

#Generate the command string
cmd1 = str("fortune -a | cowsay -n " +var2[rand2]+ " -f /usr/share/cowsay/cows/" + var1[rand1]) + " | toilet -F gay -f term";
#print cmd1;
os.system(cmd1);