Droo-Labs

the perspicacious ramblings of droo

Dual Boot Fedora on Chromebook

DO NOT treat this like a recipe! I pieced together these notes after reading through a number of different guides and poking around ChromeOS a little. I did this install over a year ago, so it’s not fresh in my memory. I’m selling my Pixel soon (after buying the new one), so I thought I’d get these posted before I no longer had it.

These directions are notes I had after installing this configuration on my Chromebook Pixel (64gb). Your values may be different, but you should get a good idea of what’s going on by reading through these notes!

First, you’ll need your Chromebook in developer mode. And if my memory serves me correctly, you’ll need rootfs verification turned off on the drive as well.

This guide assumes you’re running as root. To do this, type “sudo su” into the shell.

This is what my drive looked like at the beginning:
localhost user # cgpt show -q /dev/sda
10276864 114733056 1 Linux data
20480 32768 2 ChromeOS kernel
6082560 4194304 3 ChromeOS rootfs
53248 32768 4 ChromeOS kernel
1888256 4194304 5 ChromeOS rootfs
16448 1 6 ChromeOS kernel
16449 1 7 ChromeOS rootfs
86016 1638400 8 Linux data
16450 1 9 ChromeOS reserved
16451 1 10 ChromeOS reserved
64 16384 11 ChromeOS firmware
1855488 32768 12 EFI System Partition

localhost user # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.2G 1.1G 179M 86% /
devtmpfs 1.9G 540K 1.9G 1% /dev
tmp 1.9G 224K 1.9G 1% /tmp
shmfs 1.9G 418M 1.5G 22% /dev/shm
/dev/sda1 54G 2.1G 49G 5% /home
/dev/sda8 772M 272M 461M 38% /usr/share/oem
< ... snip ...>

So, let’s do 36GB from sda1… 16MB of which for KERN-C

54 – 42 = 12 * 1024 * 1024 * 1024 = 12885000000 / 512-bytes = 25165824 blocks = 12GB

localhost user # cgpt add -i 1 -b 10276864 -s 25165824 -l STATE /dev/sda

localhost user # cgpt show -q /dev/sda
10276864 25165824 1 Linux data
< ... snip ...>

So…
10276864 + 25165824 = 35442688 = start block
16 * 1024 * 1024 = 16777216 / 512-byte = 32768 = size

localhost user # cgpt add -i 6 -b 35442688 -s 32768 -l KERN-C /dev/sda

35442688 + 32768 = 35475456 = start block
114733056 – 25165824 – 32768 = 89534464

localhost user # cgpt add -i 7 -b 35475456 -s 89534464 -l ROOT-C /dev/sda

So, we now have…
localhost / # cgpt show /dev/sda
start size part contents
0 1 PMBR (Boot GUID: E5780C4A-FEC4-CF4A-9F10-99B1C66F832B)
1 1 Pri GPT header
2 32 Pri GPT table
10276864 25165824 1 Label: “STATE”
Type: Linux data
UUID: D4F54A90-A6FF-294D-BFC4-61E14EDD7A39
20480 32768 2 Label: “KERN-A”
Type: ChromeOS kernel
UUID: 38441F4B-D3C1-C24B-8A84-5CD673F205E0
Attr: priority=2 tries=0 successful=1
6082560 4194304 3 Label: “ROOT-A”
Type: ChromeOS rootfs
UUID: FCF8C319-1BEA-F240-BC6F-4282883DFCF9
53248 32768 4 Label: “KERN-B”
Type: ChromeOS kernel
UUID: 4AF1B9B2-E894-9242-B84A-C44492BFF574
Attr: priority=1 tries=0 successful=1
1888256 4194304 5 Label: “ROOT-B”
Type: ChromeOS rootfs
UUID: 96B509A9-455B-8A47-AFB2-C520EDB2A265
35442688 32768 6 Label: “KERN-C”
Type: ChromeOS kernel
UUID: EDFA1D91-C8D0-FC45-9E2A-FE264F7122BB
Attr: priority=0 tries=0 successful=0
35475456 89534464 7 Label: “ROOT-C”
Type: ChromeOS rootfs
UUID: 10BFB5E2-A71B-474A-8660-D2EEA6CA6118
86016 1638400 8 Label: “OEM”
Type: Linux data
UUID: 52634829-EAB3-374F-9C99-AB684BB8FB7A
16450 1 9 Label: “reserved”
Type: ChromeOS reserved
UUID: 6514C723-DA3E-404B-9B43-204889AC4D96
16451 1 10 Label: “reserved”
Type: ChromeOS reserved
UUID: 192F034B-A760-5946-BC89-DFC235CCFF42
64 16384 11 Label: “RWFW”
Type: ChromeOS firmware
UUID: BB53BEDB-911E-FF4C-B281-3E7619E63535
1855488 32768 12 Label: “EFI-SYSTEM”
Type: EFI System Partition
UUID: E5780C4A-FEC4-CF4A-9F10-99B1C66F832B
125045391 32 Sec GPT table
125045423 1 Sec GPT header

Now let’s clear out the Linux data partition. First, the math!

10276864 blocks * 512-byte (block size) / 131072-byte (128kb) = 40144 = seek
25165824 blocks * 512-byte (block size) / 131072-byte (128kb) = 98304 = count

Then…
localhost user # dd if=/dev/zero of=/dev/sda bs=131072 seek=40144 count=98304

And now for the Linux / partition:

89534464 + 255 = 89534719

localhost user # cd /tmp
localhost user # rm -rf test.bin
localhost user # dd if=/dev/zero bs=512 seek=89534719 count=1 of=test.bin
localhost user # cgpt create test.bin
localhost user # cgpt boot -p test.bin
localhost user # cgpt add -b 128 -s 89534719 -t data -l fedora test.bin

Now we need to install Linux on test.bin — we’ll use VirtualBox!

localhost user # scp test.bin :test.bin
localhost user # ssh
localhost user # VBoxManage convertdd test.bin test.vdi –format VDI

Install fedora!

After you’ve installed Fedora:

localhost user # VBoxManage internalcommands converttoraw test.vdi test_new.bin
localhost user # dd if=test_new.bin bs=512 skip=128 count=89534719 of=rootfs.bin

localhost user # exit
localhost user # ssh @ bzip2 -c /home//rootfs.bin | bunzip2 -c | dd of=/dev/sda7

localhost user # mkdir /tmp/urfs
localhost user # mount /dev/sda7 /tmp/urfs

localhost user # cp /usr/bin/cgpt /tmp/urfs/usr/bin/
localhost user # chmod a+rx /tmp/urfs/usr/bin/cgpt

localhost user # cd /lib/modules
localhost user # cp -ar * /tmp/urfs/lib/modules/

localhost user # umount /tmp/urfs

localhost user # rootdev -s

localhost user # dd if=/dev/sda4 of=/dev/sda6

localhost user # make_dev_ssd.sh –partitions ‘6’ –save_config foo

localhost user # cat foo
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/sda7 noinitrd

localhost user # make_dev_ssd.sh –partitions ‘6’ –set_config foo

Now, in ChromeOS, run the following to boot into Fedora on reboot:

localhost user # cgpt add -i 6 -P 5 -T 1 -S 0 /dev/sda

In Fedora to boot into ChromeOS:
cgpt add -i 6 -P 5 -S 1 /dev/sda

To update the boot kernel, run the following in ChromeOS, replacing the new kernel version:

localhost / # echo “console=tty1 debug verbose root=/dev/sda7 rootwait rw” > /tmp/config
localhost / # vbutil_kernel –pack /tmp/newkern –keyblock /usr/share/vboot/devkeys/kernel.keyblock –version 1 –signprivate /usr/share/vboot/devkeys/kernel_data_key.vbprivk –config=/tmp/config –vmlinuz /mnt/sda7/boot/vmlinuz-3.11.10-301.fc20.x86_64 –arch x86_64
dd if=/tmp/newkern of=/dev/sda6

I also used a little script in Linux to keep it booting into Linux, allowing ChromeOS fallback, or switch back to ChromeOS:

vim /usr/local/bin/set_next_boot.sh

#!/bin/bash

. /etc/nextboot.conf

if [[ $IS_FEDORA -eq 1 ]]; then
cgpt add -i 6 -P 5 -T 1 -S 0 /dev/sda
else
cgpt add -i 6 -P 5 -T 0 -S 0 /dev/sda
fi

vim /usr/local/bin/switch_boot.sh

#!/bin/bash

. /etc/nextboot.conf

if [[ $IS_FEDORA -eq 1 ]]; then
echo “$CHROME” > $NEXT_FILE
else
echo “$FEDORA” > $NEXT_FILE
fi

echo -e “Set to $(cat $NEXT_FILE)”

vim /etc/nextboot.conf

NEXT_FILE=”/.next_boot”
FEDORA=”fedora”
CHROME=”chrome”
IS_FEDORA=0
if [[ “$(cat $NEXT_FILE)” == “fedora” ]]; then
IS_FEDORA=1
fi

vim /lib/systemd/system/nextboot.service

[Unit]
Description=Switch next boot partition

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/local/bin/set_next_boot.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

systemctl enable nextboot

Now, to switch back to ChromeOS, just run switch_boot.sh and reboot. If you want to stay in Fedora after rebooting from chrome, run switch_boot.sh and reboot! And that’s all there is to it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>