Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit f9b528d

Browse files
committed
docs, run fsck on partitions
1 parent 01fc7f8 commit f9b528d

12 files changed

+157
-86
lines changed

README.md

Lines changed: 30 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,36 @@
11
# terraOS
22
Boot Linux-based operating systems from a RMA shim.
33

4-
## How do I use it?
5-
- Clone this repository.
6-
- Build the bootloader by running `sudo bash build.sh <input RMA shim> <output image path>`.
7-
- Flash it to a USB.
8-
- If you want to boot from squashfs, expand the 1st partition.
9-
- Copy all squashfses you want to boot from into the 1st partition.
10-
- For each rootfs you want to use with persistence, do these steps:
11-
- Create a new partition with type "ChromeOS rootfs" via fdisk or your favourite partitioning utility.
12-
- Format the partition.
13-
- Extract the tarball or bootstrap your rootfs as root into the root of the partition. If you are using `cp`, **make sure to use the `a` flag to preserve permissions and users**. To build the default rootfs, see [here](#how-do-i-build-the-terraos-rootfs).
14-
- Make sure the init program is at "/sbin/init" as that is the path that is executed.
15-
- TerraOS will autodetect all partitions on all GPT devices (including internal storage) with type "ChromeOS rootfs" and display them in a list that you can boot from.
16-
17-
## FAQ
18-
### What works on the default rootfs?
19-
`make_rootfs.sh` copies firmware and modules from the RMA shim and ALSA kernel module configurations from the recovery image, so most if not all features should work out of the box. If features do not work, see [here](#crowdsourced-list-of-compatibility).
20-
- Systemd
21-
- Graphics
22-
- 3D Acceleration
23-
- Audio (this is board dependent)
24-
- WiFi (this is board dependent)
25-
26-
### Can I use a different distro?
27-
Yes, you will need to either use a non-systemd distro or manually compile systemd with the [chromiumos patches](https://aur.archlinux.org/cgit/aur.git/tree/0002-Disable-mount_nofollow-for-ChromiumOS-kernels.patch?h=systemd-chromiumos). Then you can just follow the regular instructions and install your distro instead.
28-
29-
### Can I use this without a USB in?
30-
Yes, you will need to create a "ChromeOS rootfs" partition on the internal storage and copy your rootfs there. In the future, there will be support for copying the filesystem to RAM.
31-
32-
### Where is my WiFi, audio, etc?!
33-
Run `dmesg` and find the proper firmware for your board. Download it and manually add it to the rootfs. If you are using some exotic device it may not be in the RMA shim kernel. In that case you will have to compile the exact kernel version in the shim and then the module.
34-
35-
## How do I build the TerraOS rootfs?
36-
**The password for the `terraos` user is `terraos`.**
37-
```
38-
sudo bash create_rootfs.sh <rootfs path - needs to be empty> <shim> <board recovery image> <systemd-chromiumos.pkg.tar.zst> <systemd-chromiumos-libs.pkg.tar.zst> <systemd-chromiumos-sysvcompat.pkg.tar.zst>
39-
```
4+
![Image of terraOS bootloader](preview.png)
405

41-
Then you can add extra firmware such as the ones from the crowdsourced list of firmware needed for WiFi below.
6+
## How does it work?
7+
terraOS utilizes a bug in chromebook RMA shims, which are bootable recovery images that are used for running diagnostic utilities, to chainload regular Linux distros by replacing the rootfs. Replacing the rootfs entirely doesn't work however, since the RMA shim boots in an environment made specifically for those diagnostic utilities. terraOS is made to get around that.
428

43-
To build systemd-chromiumos:
44-
```
45-
git clone https://aur.archlinux.org/systemd-chromiumos
46-
cd systemd-chromiumos
47-
makepkg -Cs --skipinteg --nocheck
48-
```
9+
## How do I add my own distros?
10+
You'll need to create a partition with the type `chromeOS rootfs` (`3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec`) and bootstrap your distro in the root of an ext4 filesystem on that partition. Place any squashfs files in the root of the first partition.
4911

50-
`sudo tar cajvf ../<filename> *` seems to create a sane tarball of the generated rootfses.
51-
`sudo mksquashfs * ../<filename> -comp gzip` creates a squashfs image of the generated rootfs.
52-
53-
## How do I build ChromeOS for TerraOS?
54-
```
55-
sudo bash create_cros_persistent.sh <reven_recovery> <cros_recovery> <rma_shim> <path_to_image>
56-
```
57-
The `path_to_image` must be a path to a file.
58-
59-
60-
## How do I build terrastage1.tar.zst?
61-
- Use the buildroot config located in this repo.
62-
63-
## Crowdsourced list of compatibility
64-
If you get all features working on your TerraOS install, check here to make sure someone hasn't already posted data for your board and make a PR modifying this README.
65-
66-
### Octopus
67-
All features work out of the box. Update your TerraOS rootfs, since this was fixed in a newer version.
12+
## How do I use it?
13+
1. Clone this repo.
14+
2. Create a build directory.
15+
3. Run `bash ../scripts/build_stage1.sh <defconfig>`
16+
- Use `terraos` as the defconfig if building for x86_64 chromebooks.
17+
- Use `terraos_jacuzzi` as the defconfig if building for `jacuzzi` board chromebooks. Support for `jacuzzi` board chromebooks is experimental and may not work, however.
18+
4. Run `bash ../scripts/build_aur_packages.sh`
19+
5. Run `bash ../scripts/build_all.sh <shim.bin> <board_recovery.bin> <reven_recovery.bin>` replacing `<shim.bin>` with the path to a shim for your board, `<board_recovery.bin>` with the path to a recovery image for your board, and `<reven_recovery.bin>` with the path to a chromeOS flex recovery of the same version.
20+
21+
This will place a built bootloader image, squashfs and tarballs of the arch rootfs, a bootloader image with the arch rootfs, a bootloader image with terraOS chromeOS, and a bootloader image with both the arch rootfs and terraOS chromeOS in the build directory.
22+
23+
## How do I install to internal storage?
24+
1. Boot into terraOS and copy over the image you used to flash your terraOS drive.
25+
2. Use GParted or `sudo fdisk -l` to find your internal storage. Replace `/dev/mmcblkX` in the rest of the steps with the internal storage device.
26+
3. Run `sudo dd if=<image> of=/dev/mmcblkX status=progress bs=16M oflag=direct` to write the image to the internal storage. Replace `<image>` with the path to the image you copied.
27+
28+
Alternatively you can manually create a `chromeOS rootfs` type partition via `parted` or `fdisk`, format as ext4, and copy over the rootfs.
29+
30+
## What doesn't work?
31+
- Deep sleep (kernel issue)
32+
- Swap (disabled in kernel)
33+
- Audio on dedede (firmware bug)
34+
35+
## Can I use a different distro?
36+
Yes, you will need to either use a non-systemd distro or manually compile systemd with the [chromiumos patches](https://aur.archlinux.org/cgit/aur.git/tree/0002-Disable-mount_nofollow-for-ChromiumOS-kernels.patch?h=systemd-chromiumos).

preview.png

25.2 KB
Loading

scripts/build_all.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set -e
2-
if [ $# -le 1 ]; then
3-
echo "usage: build_all.sh shim.bin board_recovery.bin"
2+
if [ $# -lt 3 ]; then
3+
echo "usage: build_all.sh shim.bin board_recovery.bin reven_recovery.bin"
44
exit 1
55
fi
66

@@ -11,9 +11,13 @@ fi
1111

1212
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
1313

14-
bash ${SCRIPT_DIR}/build_rootfs.sh arch_rootfs ${1} ${2}
15-
bash ${SCRIPT_DIR}/build_bootloader.sh ${1} bootloader.img
14+
bash ${SCRIPT_DIR}/build_rootfs.sh arch_rootfs "${1}" "${2}"
15+
bash ${SCRIPT_DIR}/build_bootloader.sh "${1}" bootloader.img
1616
bash ${SCRIPT_DIR}/build_arch_only.sh arch_rootfs
17+
bash ${SCRIPT_DIR}/build_cros_persistent.sh "${3}" "${2}" "${1}" bootloader.img terra_chromeos.img
18+
zstd -k terra_chromeos.img
19+
zip terra_chromeos.img.zip terra_chromeos.img
20+
bash ${SCRIPT_DIR}/build_arch_chromeos.sh arch_rootfs
1721
(
1822
cd arch_rootfs;
1923
mksquashfs * ../terra_arch_gzip.squashfs

scripts/build_arch_chromeos.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
if [ ${EUID} -ne 0 ]; then
2+
echo "this script must be run as root" >&2
3+
exit 1
4+
fi
5+
6+
if [ $# -lt 1 ]; then
7+
echo "usage: build_arch_chromeos.sh <rootfs_dir>"
8+
exit 1
9+
fi
10+
11+
cp terra_chromeos.img terra_chromeos_arch.img
12+
truncate -s 9G terra_chromeos_arch.img
13+
OUT_DEV=$(losetup -Pf --show terra_chromeos_arch.img)
14+
15+
(
16+
echo "n"
17+
echo "13"
18+
echo ""
19+
echo ""
20+
echo ""
21+
echo "t"
22+
echo "13"
23+
echo "3cb8e202-3b7e-47dd-8a3c-7ff2a13cfcec"
24+
echo "w"
25+
) | fdisk "${OUT_DEV}"
26+
27+
cgpt add -i 13 -l terra_arch "${OUT_DEV}"
28+
29+
mkfs.ext4 "${OUT_DEV}"p13
30+
31+
mkdir mnt
32+
mount "${OUT_DEV}"p13 mnt
33+
cp -a "${1}"/* mnt/
34+
umount mnt
35+
rm -r mnt
36+
37+
losetup -d ${OUT_DEV}
38+
39+
zstd -k terra_chromeos_arch.img
40+
zip terra_chromeos_arch.img.zip terra_chromeos_arch.img

scripts/build_arch_only.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ if [ ${EUID} -ne 0 ]; then
33
exit 1
44
fi
55

6+
if [ $# -lt 1 ]; then
7+
echo "usage: build_arch_only.sh <rootfs_dir>"
8+
exit 1
9+
fi
10+
611
cp bootloader.img terra_arch.img
712
truncate -s 4G terra_arch.img
813
OUT_DEV=$(losetup -Pf --show terra_arch.img)

scripts/build_bootloader.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
help(){
22
echo "Usage:
3-
build.sh <shim> <output_filename>
4-
build.sh -h | --help
3+
build_bootloader.sh <shim> <output_filename>
4+
build_bootloader.sh -h | --help
55
66
Builds the TerraOS bootloader."
77
}

scripts/build_cros_persistent.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
help(){
44
echo "Usage:
5-
create_cros_persistent.sh <reven_recovery_image> <chromeos_recovery_image> <shim> <terraos_bootloader> <output_image>
6-
create_cros_persistent.sh -h | --help"
5+
build_cros_persistent.sh <reven_recovery_image> <chromeos_recovery_image> <shim> <terraos_bootloader> <output_image>
6+
build_cros_persistent.sh -h | --help"
77
}
88

99
die() {

scripts/build_rootfs.sh

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mkdir "${1}"
8282

8383
if test -d mnt; then rm -r mnt; fi
8484

85-
PACKAGES="base networkmanager pulseaudio pavucontrol alsa-utils mesa-amber which sudo vim neofetch base-devel"
85+
PACKAGES="base networkmanager pulseaudio pavucontrol alsa-utils mesa-amber which sudo vim neofetch base-devel cloud-utils util-linux"
8686

8787
if ! has_arg "--no-xfce" "$@"; then
8888
PACKAGES="${PACKAGES} network-manager-applet xfce4 xfce4-goodies lightdm-gtk-greeter firefox noto-fonts"
@@ -105,8 +105,31 @@ arch-chroot "${1}" locale-gen || die "failed to generate locale files"
105105
echo "LANG=en_US.UTF-8" > "${1}/etc/locale.conf"
106106
echo "terraos" > "${1}/etc/hostname"
107107

108-
if ! has_arg "--no-kill-frecon" "$@"; then
108+
cat <<"EOT" > "${1}/usr/local/bin/expand-root.sh"
109+
set -xe
110+
PART=$(findmnt -no SOURCE /)
111+
DEV=$(lsblk -npo PKNAME ${PART})
112+
echo "${DEV} ${PART} ${PART#${DEV}}"
113+
echo "w" | fdisk ${DEV}
114+
growpart ${DEV} ${PART#${DEV}}
115+
resize2fs ${PART}
116+
EOT
117+
118+
cat <<EOT > "${1}/etc/systemd/system/expand-root.service"
119+
[Unit]
120+
Description=Resize root on first boot
121+
ConditionPathExists=!/usr/local/bin/expand-root.completed
122+
123+
[Service]
124+
Type=simple
125+
ExecStart=/usr/bin/bash /usr/local/bin/expand-root.sh
126+
ExecStartPost=/usr/bin/touch /usr/local/bin/expand-root.completed
109127
128+
[Install]
129+
WantedBy=basic.target
130+
EOT
131+
132+
if ! has_arg "--no-kill-frecon" "$@"; then
110133
cat <<EOT > "${1}/etc/systemd/system/kill-frecon.service"
111134
[Unit]
112135
Description=Tell frecon to kill itself
@@ -118,7 +141,6 @@ ExecStart=/usr/bin/killall frecon-lite
118141
[Install]
119142
WantedBy=basic.target
120143
EOT
121-
122144
arch-chroot "${1}" systemctl enable kill-frecon || die "failed to enable kill-frecon service"
123145
fi
124146

scripts/build_stage1.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/bash
22
set -e
33

4+
if [ $# -lt 1 ]; then
5+
echo "usage: build_stage1.sh <defconfig>"
6+
echo "available defconfigs:"
7+
echo " - terraos"
8+
echo " - terraos_jacuzzi"
9+
exit 1
10+
fi
11+
412
git clone https://github.com/r58Playz/buildroot -b terra-stage1
513
cd buildroot
614
make ${1}_defconfig

src/boot.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ pub fn boot_from_partition(dev: String, termsize: tui::Point, init_cmd: &str) {
2323

2424
tui::flush();
2525

26+
utils::run_fsck(&dev)
27+
.expect("Failed to check partition for errors");
28+
2629
unistd::mkdir("/newroot", stat::Mode::S_IRWXU).expect("Failed to create newroot");
2730
// we use /bin/mount and not nix::mount::* because /bin/mount has autodetection of fstype
28-
utils::run_cmd("/bin/mount", &[dev, "/newroot".to_string()])
29-
.expect("Failed to mount partition");
31+
utils::run_cmd("/bin/mount", &[dev, "/newroot".into()]).expect("Failed to mount partition");
3032

3133
boot_from_newroot(termsize, center, false, init_cmd);
3234
}

0 commit comments

Comments
 (0)