Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Forked from kapilhp/linux_on_c100pa.md with my modifications as commentes on the main Gist.

An account of how to create a USB disk that will boot a Linux 4.19 kernel (based off Chrome OS' most recent working kernel) on an Asus C100PA with a Debian ("buster") root file system. This may also work on other veyron-* devices.

Setup USB Disk

In this first step we will create a Chrome OS GPT partition table on USB drive that looks like this:

      start        size    part  contents
           0           1          PMBR
           1           1          Pri GPT header
           2          32          Pri GPT table
          34       65536       1  Label: "kernel"
                                  Type: ChromeOS kernel
                                  UUID: NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN
                                  Attr: priority=0 tries=0 successful=0 
       65570       65536       2  Label: "alt-kernel"
                                  Type: ChromeOS kernel
                                  UUID: NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN
                                  Attr: priority=0 tries=0 successful=0 
      131106     7690173       3  Label: "root"
                                  Type: Linux data
                                  UUID: NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN
     7821279          32          Sec GPT table
     7821311           1          Sec GPT header

If you already know how to do this, then skip the steps given below. (The numbers in the first column are for a specific USB drive. Some of them could be different for you.) Basically, partition 1 will hold the Chrome OS "style" kernel image, partition 3 will have the root file system for Debian. Partition 2 will be useful if one wants to test alternative kernels.

  1. Go to file manager and eject the USB drive if it is mounted.

Note: The commands below need to run as root on Chrome OS. This means that you need to be in developer mode (it is complicated to explain how to do this here). I also prefer to work within crouton in developer mode since it is a familiar Debian environment; in the latter case you need to install fdisk and cgpt with apt install fdisk cgpt.

  1. From /proc/partitions figure out the drive name. We will assume that it is /dev/sda.

  2. Run fdisk /dev/sda and type g followed by w to create a new GPT partition table. Or, if you prefer a complete command-line approach run echo label: gpt | sfdisk /dev/sda; alternatively, parted --script /dev/sda mklabel gpt.

  3. Run cgpt create /dev/sda to setup the Chrome OS extensions to the GPT partition table.

  4. Now we create partitions in succession:

a. cgpt add -b 34 -s 65536 -t kernel -l "kernel" /dev/sda will create partition 1 of size 32M. a. cgpt add -b 65570 -s 65536 -t kernel -l alt-kernel /dev/sda will create partition 2. Note that $65570 = 34 + 65536$! a. Use cgpt show /dev/sda to get the available size for partition 3. If $n$ is the first number in the second last row of the output, then the size is $m=n-131106$. Note that $131106=65570+65536$! a. cgpt add -b 131106 -s <m> -t data -l root /dev/sda will create the root partition.

Note: At this point (and various other points!) the Chrome OS utility cros-disks may mount your partitions, you will need to unmount them from the file manager to avoid silly errors.

Create the Debian root file system

This step will create a Debian (buster) root file system on /dev/sda3 (the chosen partition for this) using debootstrap. If you already know how to do this, then you can skip the following steps.

We assume that you want to create a Debian root file system on /dev/sda3, and that this file system is not mounted, and that you have root access.

  1. Create a blank ext4 file system on the partition with mkfs.ext4 /dev/sda3.

  2. Mount it in some empty directory. In Debian (and Crouton) /mnt is usually available for such temporary mounts, so you do mount /dev/sda3 /mnt.

  3. Get a copy of the debootstrap package and install it somewhere. In Debian (and Crouton) this is as easy as apt install debootstrap.

  4. Run debootstrap --arch=armhf --foreign buster /mnt to create the Debian buster root file system on the partition mounted at /mnt.

  5. If the above steps were not run on your Chromebook, then you need to eject your drive and get it to your Chromebook. As usual you need to have root on your Chromebook at the partition needs to be mounted somewhere. Since I worked with Crouton, I didn't have to do anything, the partition continued to be mounted at /mnt.

  6. Run the second stage of the installation process with chroot /mnt /debootstrap/debootstrap --second-stage.

  7. At this stage, it is probably a good idea to "expand" /mnt/etc/apt/sources.list to include security and other updates. (Why not?!) So it should look like:

deb http://deb.debian.org/debian/ buster main non-free contrib
deb http://deb.debian.org/debian/ buster-updates main non-free contrib
deb http://deb.debian.org/debian-security buster/updates main non-free contrib
  1. Run chroot /mnt apt update and chroot /mnt apt upgrade just to get your (minimal) Debian root up-to-date. This also checks that you can connect to the Debian repositories within the chroot. (If you get a name lookup error, you may need to copy /etc/resolv.conf into /mnt/etc/resolv.conf.)

  2. Set root password chroot /mnt passwd root

Install Linux Build dependencies

We assume that your Debian root file system is mounted at /mnt and install things required to build the Linux kernel.

  1. Probably a good idea to mount some of the utility filesystems at this point with mount --bind /dev /mnt/dev, chroot /mnt mount -t proc proc /proc and chroot /mnt mount -t sysfs sysfs /sys.

  2. You need to run chroot /mnt apt install <pkg> for the packages build-essential, libncurses5-dev, libssl-dev, bc, bison, flex, git, initramfs-tools.

Getting Chrome OS kernel sources, config and firmware

The build process is based on the current stable channel version of Chrome OS. The following steps need to be carried out in the Chrome OS root.

  1. Run modprobe configs to get the running configuration of the Chrome OS kernel in /proc/config.gz. Copy this file to some location accessible to your Crouton.

  2. Run tar -czf /tmp/extras.tar.gz /lib/firmware /opt/google/touch and copy this file to some location accessible to your Crouton.

  3. grep CHROMEOS_RELEASE_BUILDER_PATH /etc/lsb-release should give you something like veyron_minnie-release/R83-13020.87.0. The relevant portion of that is R83-13020

  4. uname -r should give you something like 4.19.113-08544-ge67503bc40df. The relevant parts of that are 4.19 and e67503bc40df (which is the tail following the g --- for Google?).

  5. Browse the Google Chromium Source tree at https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/release-R83-13020.B-chromeos-4.19. Note how we used the R83-13020 and 4.19. At the top of the page against commit you will see a hexadecimal number which starts with e67503bc40df (our last relevant part!). This shows that you have the correct source for the kernel that is running on your Chromebook!

  6. Click on the tgz link, or copy the link and download it using curl or wget. It should give you a file called release-R83-13020.B-chromeos-4.19.tar.gz

  7. Make this file accessible to your Crouton if necessary. Now assume that you are in the same situation as the previous step and have your Debian root file system mounted at /mnt.

  8. Make a directory to unpack this archive mkdir -p /mnt/usr/src/linux-chromeos-4.19/.

  9. Unpack the archive with tar -xf release-R83-13020.B-chromeos-4.19.tar.gz -C /mnt/usr/src/linux-chromeos-4.19/

  10. Copy the config.gz from (1) above to /mnt/root/chromeos.config.gz and unzip it with gunzip /mnt/root/chromeos.config.gz.

  11. Unpack extras.tar.gz from (2) above using tar -xf extras.tar.gz -C /mnt so that the files are in /lib/firmware and /opt within the Debian file system.

Building the Chrome OS kernel

Assume that the root of the Debian file system is mounted at /mnt and this has the /dev, /proc and /sys mounts as above as well.

Enter this with chroot /mnt before running the next steps.

  1. Run cd /usr/src/linux-chromeos-4.19/ to enter the kernel sources.

  2. Copy the running (Chrome OS) kernel configuration with cp /root/chromeos.config .config

  3. Enable a few flags in this configuration file.

    • ./scripts/config --enable CONFIG_VT
    • ./scripts/config --enable CONFIG_FRAMEBUFFER_CONSOLE
    • ./scripts/config --enable CONFIG_DRM_FBDEV_EMULATION

The above three are probably essential as a replacement for Chrome OS' use of frecon. The next ones are not very clear. Some experimentation is required to see if they are all required!

  • ./scripts/config --enable CONFIG_DRM_MALI_DISPLAY
  • ./scripts/config --enable CONFIG_ROCKCHIP_LVDS
  • ./scripts/config --enable CONFIG_ROCKCHIP_RGB
  • ./scripts/config --enable CONFIG_DRM_PANEL_LVDS

The following is a way to reduce the size of the kernel and also its debug-ability! You may or may not want to do this!

  • ./scripts/config --disable CONFIG_DEBUG_INFO
  1. Finally, make this into a proper .config with make ARCH=arm -j6 olddefconfig.

  2. Now run make ARCH=arm -j6 <target> for the targets zImage, modules, dtbs, modules_install and dtbs_install.

  3. Before installing the kernel one needs to run ln -s /dev/sda3 /dev/root so that Debian's update-initramfs is able to guess the root file system to build the initrd.img. After this you can run make ARCH=arm -j6 zinstall. Then you can remove the /dev/root link unlink /dev/root. Don't worry too much about the failure to build the initrd.img as we will not use it to boot the system at this point.

Installing the kernel

At this point you are in the Debian chroot where, in /boot you have your vmlinuz-4.19.113, System.map-4.19.113 and initrd.img-4.19.113 and in /boot/dtbs/4.19.113 you will have the file rk3288-veyron-minnie.dtb.

  1. Install the tools needed to install the kernel with apt install vim vboot-utils vboot-kernel-utils u-boot-tools

  2. Create the file /boot/kernel.its with the following contents.

/dts-v1/;

/ {
    description = "Kernel image with one or more FDT blobs";
    images {
        kernel@1{
            description = "kernel";
            data = /incbin/("vmlinuz-4.19.113");
            type = "kernel_noload";
            arch = "arm";
            os = "linux";
            compression = "none";
            hash@1{
                algo = "sha1";
            };
        };
        fdt@1{
            description = "device_tree";
            data = /incbin/("dtbs/4.19.113/rk3288-veyron-minnie.dtb");
            type = "flat_dt";
            arch = "arm";
            compression = "none";
            hash@1{
                algo = "sha1";
            };
        };
    };
    configurations {
        default = "conf@1";
        conf@1{
            kernel = "kernel@1";
            fdt = "fdt@1";
        };
    };
};

  1. Use this to create the FIT image that can be loadedby u-boot with the command mkimage -f /boot/kernel.its /boot/kernel.itb

  2. Create a file /boot/cmdline with the contents

cros_secure console=tty1 noinitrd nosplash root=/dev/sda3 rootfstype=ext4 rw rootwait lsm.module_locking=0 vt.global_cursor_default=1

It is not clear that all these options are required. Some experimentation is needed! Note that /dev/sda3 should probably be replaced with a "UUID" or a label or something.

  1. Create an empty /boot/bootloader.bin file. (Why? No idea!) The command is dd if=/dev/zero of=/boot/bootloader.bin bs=512 count=1

  2. Create the image for the kernel partition with the command

vbutil_kernel --pack /boot/image.kpart --version 1 --arch arm \
    --vmlinuz /boot/kernel.itb --bootloader /boot/bootloader.bin --config /boot/cmdline \
    --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
    --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk 
  1. Install this kernel in /dev/sda1 with dd if=/boot/image.kpart of=/dev/sda1

  2. Activate this for booting with cgpt add -i 1 -P 1 -T 1 -S 1 /dev/sda

  3. (optional) Install additional tools that you may require for networking apt install net-tools wireless-tools wpasupplicant iw

  4. (optional) Install nano for easy file editing apt install nano

At this point your system should be ready! Unmount /dev, /proc and /sys and exit from the "chroot". Then unmount the partition umount /dev/sda3.

Booting your new system

Before rebooting ensure that you have enabled USB booting and disabled verified boot with crossystem dev_boot_usb=1 and crossystem dev_boot_signed_only=0. It should be possible to make sure that only certain signatures are accepted even with these settings according to some docs, but, for now, your system is "wide open" for anyone to install anything! Security has been over-ridden!

After this you can shut down your system and hit Ctrl+U at the usual developer splash screen. If all went well then your Debian system should boot up!

Adding WiFi connection

  1. Scan for Wifi network iwlist wlan0 scan | grep -i ssid

  2. Edit file nano /etc/network/interface

`auto lo wlan0 iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet dhcp
	wpa-ssid wifissid
	wpa-psk wifipassword`

Change wifissid and wifipassword accordingly

  1. Restart network /etc/init.d/networking restart

  2. (optional) If you install graphic interface and you would like to use network-manager to manage your network, remember replace nano /etc/network/interface with following only

auto lo iface lo inet loopback

Installing on Internal Memory from SD/USB Drive

NOTE: My C100PA showing internal partition as mmcblk2

My cgpt show /dev/mmcblk2 output before modifications:

   start        size    part  contents
       0           1          PMBR (Boot GUID: 5AC2007B-FC7B-264A-AAB0-2C34ABC22A8C)
       1           1 IGNORED  Pri GPT header
30777311          32          Sec GPT table
 8704000    22073296       1  Label: "STATE"
                              Type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
                              UUID: 5F663D21-1867-BE4B-A815-C619E4ED570C
   20480       32768       2  Label: "KERN-A"
                              Type: ChromeOS kernel
                              UUID: F8689AB3-B21E-1846-8C6D-827C2519F900
                              Attr: priority=1 tries=6 successful=1 
 4509696     4194304       3  Label: "ROOT-A"
                              Type: ChromeOS rootfs
                              UUID: 6493DC60-BABF-6B45-BDF2-A9DA3E959E23
   53248       32768       4  Label: "KERN-B"
                              Type: ChromeOS kernel
                              UUID: C9BD5F47-EA75-BF48-8EBC-29916F0F2F2F
                              Attr: priority=0 tries=15 successful=0 
  315392     4194304       5  Label: "ROOT-B"
                              Type: ChromeOS rootfs
                              UUID: C4A60461-EB35-4B4A-891F-B634EA749D68
   16448           1       6  Label: "KERN-C"
                              Type: ChromeOS kernel
                              UUID: DAFE74BB-7F64-8845-A4D2-6D7E937E5C15
                              Attr: priority=0 tries=15 successful=0 
   16449           1       7  Label: "ROOT-C"
                              Type: ChromeOS rootfs
                              UUID: F23CEA35-F92D-F14A-825E-2DBB3F97318B
   86016       32768       8  Label: "OEM"
                              Type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
                              UUID: DA5D04EE-23B5-2B43-B466-7081413D00F6
   16450           1       9  Label: "reserved"
                              Type: ChromeOS reserved
                              UUID: 5DB6265C-032C-3A41-B52D-F8731F53032D
   16451           1      10  Label: "reserved"
                              Type: ChromeOS reserved
                              UUID: 8E701AF2-386B-C947-A0BC-82E8657FD197
      64       16384      11  Label: "RWFW"
                              Type: ChromeOS firmware
                              UUID: E011502A-202E-2146-9D48-D52D570CB1A4
  249856       65536      12  Label: "EFI-SYSTEM"
                              Type: EFI System Partition
                              UUID: EC84A7D1-82A1-8C49-8310-6D8451A43160
                              Attr: legacy_boot=1 
30777343           1          Sec GPT header

shrink ROOT-A and ROOT-B partitions

cgpt add -i 3 -s 32 /dev/mmcblk2
cgpt add -i 5 -s 32 /dev/mmcblk2

expand STATE partition

cgpt add -i 1 -b 4509728 /dev/mmcblk2
mkfs -t ext4 /dev/mmcblk2p1
mount -t ext4 /dev/mmcblk2p1 /mnt
cp -ax / /mnt

edit /mnt/boot/cmdline

change /dev/sda3 to /dev/mmcblk2p1

go to chroot on mounted drive

chroot /mnt

run vbutil_kernel

vbutil_kernel --pack /boot/image.kpart --version 1 --arch arm \
    --vmlinuz /boot/kernel.itb --bootloader /boot/bootloader.bin --config /boot/cmdline \
    --keyblock /usr/share/vboot/devkeys/kernel.keyblock \
    --signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk 

exit

copy kernel to internal partition

dd if=/mnt/boot/image.kpart of=/dev/mmcblk2p2

to identify from which system I am booted I added

/etc/hostname with content DebianOnSD for USB Drive /mnt/etc/hostname with DebianOnC100PA for internal storage

umount /mnt

set mmcblk2p2 to the high priority and successful

cgpt add -i 2 -P 10 -S 1 /dev/mmcblk2

set mmcblk2p4 to low priority so it is not used

cgpt add -i 4 -P 0 -S 0 /dev/mmcblk2

reboot

Upon dev screen remove usb and press Ctrl+D to boot from Internal storage.


My cgpt show /dev/mmcblk2 output after modifications:

   start        size    part  contents
       0           1          PMBR (Boot GUID: 5AC2007B-FC7B-264A-AAB0-2C34ABC22A8C)
       1           1 IGNORED  Pri GPT header
30777311          32          Sec GPT table
 4509728    26267568       1  Label: "STATE"
                              Type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
                              UUID: 40727337-D512-F24E-BF40-C41A17205D90
   20480       32768       2  Label: "KERN-A"
                              Type: ChromeOS kernel
                              UUID: 25EEC339-DADB-4749-9DC8-8A0B15516DE5
                              Attr: priority=10 tries=0 successful=1 
 4509696          32       3  Label: "ROOT-A"
                              Type: ChromeOS rootfs
                              UUID: 643698FE-9CAB-E64A-9421-56D14E7755D7
   53248       32768       4  Label: "KERN-B"
                              Type: ChromeOS kernel
                              UUID: 4348C23B-A099-D54A-B98E-A45E1273C4A3
                              Attr: priority=0 tries=15 successful=0 
  315392          32       5  Label: "ROOT-B"
                              Type: ChromeOS rootfs
                              UUID: B5206336-D004-864A-8F8F-7A7BFC4CB6EB
   16448           1       6  Label: "KERN-C"
                              Type: ChromeOS kernel
                              UUID: E2398E0F-3D0C-EE44-A305-712C357AACBF
                              Attr: priority=0 tries=15 successful=0 
   16449           1       7  Label: "ROOT-C"
                              Type: ChromeOS rootfs
                              UUID: C6DB4BD7-C98D-2D41-BE72-5BB7562033B1
   86016       32768       8  Label: "OEM"
                              Type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
                              UUID: BB52865D-8CCE-624F-B886-03D7A448FAF5
   16450           1       9  Label: "reserved"
                              Type: ChromeOS reserved
                              UUID: 0555E86B-17AC-8C46-B38B-2B62BA5500FF
   16451           1      10  Label: "reserved"
                              Type: ChromeOS reserved
                              UUID: D64A9FE8-C107-424E-9168-0F467C2BE77B
      64       16384      11  Label: "RWFW"
                              Type: ChromeOS firmware
                              UUID: 96C7A412-3EB8-1045-A8F3-56C35EE8940A
  249856       65536      12  Label: "EFI-SYSTEM"
                              Type: EFI System Partition
                              UUID: C7F93964-8490-4C46-BB54-E44DDB7AC07C
                              Attr: legacy_boot=1 
30777343           1          Sec GPT header
@kapilhp

This comment has been minimized.

Copy link

@kapilhp kapilhp commented Oct 23, 2020

Thanks for improving on my gist and sorry about the long silence.

Hope the C100PA is working fine for you! I have been working at creating a working ChromiumOS image from the instructions of Keith Myers and Chromium Developers. It is working with minor modifications.

Did you manage to get Arnold the Bat's CARMOS to boot? That would be an easier option compared with building on one's own.

@idarek

This comment has been minimized.

Copy link
Owner Author

@idarek idarek commented Oct 23, 2020

Thanks for improving on my gist and sorry about the long silence.

Hope the C100PA is working fine for you! I have been working at creating a working ChromiumOS image from the instructions of Keith Myers and Chromium Developers. It is working with minor modifications.

Did you manage to get Arnold the Bat's CARMOS to boot? That would be an easier option compared with building on one's own.

No, I never been able to boot chromium and that was a bit disappointing.
After plenty of tries decided to get rid of this device. Above I will call as my final commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.