Saturday, December 3, 2011

Recovering ChromeOS with a small flash drive on FreeBSD

If you've got a Chromebook and have ever made a typing error in DEV mode while switching over to a Linux installation, you've probably know what it's like to put your machine into an unusable state. You will need to resort to using a recovery image, and the instructions are right here for that.

Google has a few recovery utilities on various platforms to build a bootable image for a broken Chromebook: The utilities are runnable on Linux, Windows and Apple machines. However, if your Chomebook crashed and you don't have a 4GB flash drive for use with the Window utility, and only have a FreeBSD machine, there is still a way to recover.

Truth be told, the actual stable channel recovery image is only 97+ MB of data, so you really don't need a 4GB flash stick to recover your machine. Unfortunately, under Windows, the recovery software requires you have a 4 GB stick or SD card. But all you really need is a 1G stick or SD card.

If you're using FreeBSD, the Linux version of the software will let you download an image, but it wants to use process file system which has been phased-out. You can still install a Linux compatible process file system for the sake of the script, but it will not recognize anything plugged into the USB ports for some reason.

The best thing under these circumstances is to make a bootable device yourself, and this means simply downloading the latest stable channel image from here. If you are on FreeBSD and use wget, it will complain about an unverifiable SSL certificate, so you must tell it to ignore that:

# wget --no-check-certificate https://dl.google.com/dl/chromeos/recovery/cr48-stable-recovery

Unzip the image, and plug in your flash stick:

# unzip cr48-stable-recovery

It shouldn't matter what's on the stick as long as you've backed it up, because the next command will wipe it out entirely and drop the image raw on whatever used to be there:

# dd if=chromeos_0.15.1011.118_x86-mario_recovery_stable-channel_mp-v2.bin of=/dev/da0 bs=4194304 conv=sync

# sync


The command above was stolen from Google's Linux recovery script which fails to recognize a flash drive under FreeBSD. The huge blocksize greatly reduces the transfer time, and sync seals the deal when it's done. When you plug the stick into the CR-48, it will go through some tests, print some graphics to the screen, and may tell you the recovery failed. However, if you pull out the stick from the USB port, it will reboot into Chrome just fine :)

A Neat Trick

The Linuxcommando Blog showed a neat inter-process commandline trick that really shows the versatility of the UNIX terminal. It involves prodding a process running in one terminal with a signal from a shell prompt in another, making the process in the first terminal tell something about what it's doing.

The specific scenario has to do with dd, the UNIX tape drive copying program. It essentially gives no status while it's running, which for large file copies can be annoying, especially if things are going rather slow. The deal is, once you fire off dd on a long copy, it doesn't say anything until it's done. Below is a command to copy a 900+ MB recovery image to a flash drive:

# dd if=chromeos_0.15.1011.118_x86-mario_recovery_stable-channel_mp-v2.bin of=/dev/da0

Due to the slow transfer speed of flash drives, and the large size of the file, this can take 20 minutes and dd will (dutifully) not report anything during that period. However, (on FreeBSD) if you open another terminal and discover the process ID of the dd process, you can prod it into telling you what its progress is:

# sudo kill -SIGINFO 18940

Every time you run this, the process running in the first terminal will spit out something like this on stderr, but it won't stop running:

71055360 bytes transferred in 262.988274 secs (270185 bytes/sec)
346343+0 records in
346342+0 records out