• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Custom Kernel / Rootfs
2
3This document explains how to build a custom kernel and use debootstrab to build a rootfs for
4running crosvm.
5
6For an easier way to get started with prebuilt images, see [Example Usage](./example_usage.md)
7
8### Build a kernel
9
10The linux kernel in chromiumos comes preconfigured for running in a crosvm guest and is the easiest
11to build. You can use any mainline kernel though as long as it's configured for para-virtualized
12(virtio) devices
13
14If you are using the chroot for ChromiumOS development, you already have the kernel source.
15Otherwise, you can clone it:
16
17```bash
18git clone --depth 1 -b chromeos-5.10 https://chromium.googlesource.com/chromiumos/third_party/kernel
19```
20
21Either way that you get the kernel, the next steps are to configure and build the bzImage:
22
23```bash
24CHROMEOS_KERNEL_FAMILY=termina ./chromeos/scripts/prepareconfig container-vm-x86_64
25make olddefconfig
26make -j$(nproc) bzImage
27```
28
29This kernel does not build any modules, nor does it support loading them, so there is no need to
30worry about an initramfs, although they are supported in crosvm.
31
32### Build a rootfs disk
33
34This stage enjoys the most flexibility. There aren't any special requirements for a rootfs in
35crosvm, but you will at a minimum need an init binary. This could even be `/bin/bash` if that is
36enough for your purposes. To get you started, a Debian rootfs can be created with [debootstrap].
37Make sure to define `$CHROOT_PATH`.
38
39```bash
40truncate -s 20G debian.ext4
41mkfs.ext4 debian.ext4
42mkdir -p "${CHROOT_PATH}"
43sudo mount debian.ext4 "${CHROOT_PATH}"
44sudo debootstrap stable "${CHROOT_PATH}" http://deb.debian.org/debian/
45sudo chroot "${CHROOT_PATH}"
46passwd
47echo "tmpfs /tmp tmpfs defaults 0 0" >> /etc/fstab
48echo "tmpfs /var/log tmpfs defaults 0 0" >> /etc/fstab
49echo "tmpfs /root tmpfs defaults 0 0" >> /etc/fstab
50echo "sysfs /sys sysfs defaults 0 0" >> /etc/fstab
51echo "proc /proc proc defaults 0 0" >> /etc/fstab
52exit
53sudo umount "${CHROOT_PATH}"
54```
55
56> Note: If you run crosvm on a testing device (e.g. Chromebook in Developer mode), another option is
57> to share the host's rootfs with the guest via virtiofs. See the
58> [virtiofs usage](./advanced_usage.md#virtiofs-as-rootfs).
59
60You can simply create a disk image as follows:
61
62```bash
63fallocate --length 4G disk.img
64mkfs.ext4 ./disk.img
65```
66
67[debootstrap]: https://wiki.debian.org/Debootstrap
68