usb-bootable

Booting GNU/Linux distribution from USB stick with Chromebook

Yes! Finally I could run Debian with my Chromebook with an USB stick instead of installing in hard disk. Currently I’ve Debian on my hard disk too but this opens a lot of possibilities for running any GNU/Linux with only an USB stick on Chromebook. That means that you can boot any GNU/Linux distribution from [...]

Yes! Finally I could run Debian with my Chromebook with an USB stick instead of installing in hard disk. Currently I’ve Debian on my hard disk too but this opens a lot of possibilities for running any GNU/Linux with only an USB stick on Chromebook.
That means that you can boot any GNU/Linux distribution from an USB stick without affecting nothing else as the USB stick. So it’s pretty cool!
UPDATE: you can use  a shell script to make this process easy, see this post: http://www.chromebook-linux.com/2011/11/shell-script-to-easy-install-gnulinux.html
Here is the procedure to make your own bootable USB on Chromebook.

WARNING: this method will not work for CR-48 Chromebook, at least on this version


Requeriments
1. An USB stick. The size of USB stick basically depends on your needs, in this guide you will need at least 6 GB because I’m mounting a root filesystem of 5 GB and we need a little more space for the kernel partition. Anyway I tested this with a 16GB basically because was the USB stick which I had.
2. A computer with GNU/Linux and the Chrome OS chroot environment installed. Follow this guide if you don’t know how to install: http://www.chromium.org/chromium-os/developer-guide

Overview
Basically what we’re going to do is formatting your USB stick with only the required Chrome OS partitions to run the system. 
We need at least 2 partitions, one partition for the kernel image and a second partition for the root filesystem.
The Chrome OS bootstub executes the kernel on our first partition, so we need to modify the kernel parameters and pass the correct rootfs or we will get a nice kernel panic.

Partition #1: KERN-A (Chrome OS kernel)
Partition #2: ROOT-A (Chrome OS rootfs)

So the partition schema is something like this:
CODE
    start      size    part  contents
         0         1          PMBR (Boot GUID: 161CE441-575D-B843-A79B-06BAF66184F7)
         1         1          Pri GPT header
         2        32          Pri GPT table
      1024     32768       1  Label: “KERN-A”
                              Type: ChromeOS kernel
                              UUID: 5A6CC62F-913F-894D-8CA0-73B00C854F7B
                              Attr: priority=1 tries=0 successful=1
     33792  10485760       2  Label: “ROOT-A”
                              Type: ChromeOS rootfs
                              UUID: C2A90A59-04CE-AC48-A392-7729FB96A985
  31236063        32          Sec GPT table
  31236095         1          Sec GPT header

Preparing the USB stick
We’re going to destroy all the data and partitions in our USB stick to generate a correct GUID partitioning. 

Connect your USB stick to your local machine, open a console and enter the Chrome OS chroot.
Here we’re going to assume the USB partition is /dev/sdg, but you need to know what partition corresponds on your system. To know which partition is, execute this command after connecting your USB stick:
CODE
dmesg | tail

This will tells you which partition corresponds to your USB.

Then, delete the current partition table:
CODE
dd if=/dev/zero of=/dev/sdg bs=512 count=1

Next, make a new one:
CODE
sudo cgpt create /dev/sdg

Put the protective old-style MBR:
CODE
sudo cgpt boot -p /dev/sdg

Rescan the drive (or just remove and reinsert)
CODE
sudo blockdev –rereadpt /dev/sdg

Create a Chrome OS kernel partition:
CODE
sudo cgpt add -b 512 -s 32768 -t kernel -P 1 -S 1 -l KERN-A /dev/sdg

Then rescan the drive again (or remove and reinsert):
CODE
sudo blockdev –rereadpt /dev/sdg

Okay, we’ve the kernel partition (KERN-A) in our USB stick. I suggest you to destroy all data in this partition to prevent odd things:
CODE
sudo dd if=/dev/zero of=/dev/sdg1

Next, we need to create the root filesystem partition:
CODE
sudo cgpt add -b 33792 -s 10485760 -t rootfs -P 1 -S 1 -l ROOT-A /dev/sdg

Clean the data on rootfs partition:
CODE
sudo dd if=/dev/zero of=/dev/sdg2

Now we’ve the same partitioning schema that you saw before. 
What we need now is to fill this partitions with a valid and signed kernel image and mount a valid rootfs.

Generating a kernel on KERN-A partition
In this guide we’re going to use the Chrome OS kernel, so we need to enter the chroot and generate a Chrome OS kernel with a custom kernel parameters.

Let’s prepare the kernel parameters. Enter the Chrome OS chroot and execute:
CODE
echo “console=tty1 init=/sbin/init add_efi_memmap boot=local rootwait ro noresume noswap i915.modeset=1 loglevel=7 kern_guid=%U tpm_tis.force=1 tpm_tis.interrupts=0 root=/dev/sdb2 noinitrd” > usbconfig.txt

This will create a file with our kernel parameters.
Please, take a moment to look what parameters we’re passing to the kernel:
CODE
console=tty1
init=/sbin/init
add_efi_memmap
boot=local
rootwait
ro
noresume
noswap
i915.modeset=1
loglevel=7
kern_guid=%U
tpm_tis.force=1
tpm_tis.interrupts=0
root=/dev/sdb2
noinitrd

In my case, the USB root partition on my Chromebook is /dev/sdb2, that corresponds the USB partition in my Chromebook, but you need to know which partition is in your Chromebook, you can open a console in your Chromebook and connect an USB stick to make a: dmesg | tail to know which device corresponds.

We pass loglevel=7 to get some verbose kernel information.

Now you need a Chrome OS kernel, you can download the Chrome OS kernel 2.6.38.3+ here: http://files.chromebook-linux.com/kernel-2.6.38.3.bin

And you need the kernel modules too, you need to copy later the kernel modules on folder /lib/modulesDownload the kernel modules for Chrome OS kernel 2.6.38.3+ here: http://files.chromebook-linux.com/modules-2.6.38.3.tar.bz2

Next, you need to generate the kernel blob with your current kernel command-line parameters (on file usbconfig.txt), so you need to repack the kernel you had download using the tool vbutil_kernel:
CODE
vbutil_kernel –repack newkernel.bin \ –config usbconfig.txt
 –signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk \
 –oldblob kernel-2.6.38.3.bin

Next, copy the binary generated to the USB KERN-A partition:
CODE
sudo dd if=newkernel.bin of=/dev/sdg1

Done. A signed kernel with a custom kernel parameters it’s copied in our USB stick, now we need to copy/create the root filesystem.

Generating the root filesystem on ROOT-A partition

In this guide we’re going to use a Debian root filesystem, it’s the same that you can download on this webpage. See this post: http://www.chromebook-linux.com/2011/11/how-to-install-gnulinux-debian-603-on.html

Now you need to download a valid Linux root filesystem, you can download a Debian 6.0.3 here: http://files.chromebook-linux.com/debian-6.0.3/
Download only the debian_rootfs.binXX.bz2 files! You can create a shell script like this to easy download:
CODE
#!/bin/sh
for one in a b
do
  for two in a b c d e f g h i j k l m n o p q r s t u v w x y z
  do
    PART=”http://files.chromebook-linux.com/debian-6.0.3/debian_rootfs.bin$one$two.bz2″
    wget $PART
 done
done

After downloading all the parts, you need to unzip and merge all the downloaded parts. 
A quick way to do it:
CODE
bunzip2 debian_rootfs.bin*.bz2
cat debian_rootfs.bin* > debian_rootfs.bin


Next, we need to copy the kernel modules inside this rootfs or we can’t use the audio, wifi, etc… in our Chromebook.To do it, we need to create a temporary mountpoint and we’re going to copy the kernel modules inside.

CODE
sudo mkdir -p /mnt/temp_rootfs
sudo mount -t ext2 debian_rootfs.bin /mnt/temp_rootfs
sudo cp -ar 2.6.38.3+ /mnt/temp_rootfs/lib/modules
sudo umount /mnt/temp_rootfs
rmdir /mnt/temp_rootfs

Finally, we copy the Debian root filesystem to the ROOT-A partition:
CODE
sudo dd if=debian_rootfs.bin of=/dev/sdg2 bs=4096

Done! Our job is finished!
Now we’ve a bootable USB stick with GNU/Linux Debian!

Booting the USB stick
Turn on the developer mode in your Chromebook, put the USB stick in your Chromebook and turn on the Chromebook.

When the “Chrome OS verification is turned off” message appears, press the keys:
CODE
CTRL + U

This will boot your Chromebook from your USB!

Welcome to GNU/Linux Debian from USB! :-)