2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
Building a TemplateVM for a new OS
2019-05-26 20:32:45 -04:00
==============================================================
2019-08-01 21:13:45 -04:00
If you don't like using one of the existing templates because of specific administration, package management or other building needs, you can build a TemplateVM for your distribution of choice.
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
This article shows how to go about building a template for a different OS.
2019-05-26 20:32:45 -04:00
2019-08-02 00:59:16 -04:00
You should make sure you understand the details of the BuilderPlugins API - they are explained [here][API].
2019-05-26 20:32:45 -04:00
Qubes builder scripts
=====================
2019-08-01 21:13:45 -04:00
One way to start is by creating Qubes builder scripts for your new OS.
Note that this will probably make your testing process harder than trying to build the package directly in an HVM on which you have already installed the new OS.
2019-05-26 20:32:45 -04:00
chroot initialization
---------------------
You need to customize some scripts that will be used to build all the Qubes tools.
2019-08-01 21:13:45 -04:00
Create a new directory to hold the files for the new os.
You can start from the Fedora scripts in `builder-rpm/template-scripts` , and see how they have been changed for Debian and Archlinux.
The scripts you need are in :
2019-05-26 20:32:45 -04:00
~~~
2019-08-01 21:13:45 -04:00
builder-archlinux/scripts
builder-debian/template-debian
builder-rpm/template-scripts
2019-05-26 20:32:45 -04:00
~~~
### 00\_prepare.sh
2019-08-01 21:13:45 -04:00
The goal of the first script `00_prepare.sh` is to download and verify the signature of the installation CD and tools, or the native tools for building an OS.
You can use the `$CACHEDIR` directory variable to store files that could be reused (such as downloaded scripts or iso files).
2019-05-26 20:32:45 -04:00
### 01\_install\_core.sh
2019-08-01 21:13:45 -04:00
The goal of this script is to install a base environment of your target OS inside the `$INSTALLDIR` directory variable.
Generally you need to bootstrap/install your package manager inside the `$INSTALLDIR` directory and install the base packages.
2019-05-26 20:32:45 -04:00
### Testing the installation process
2019-08-01 21:13:45 -04:00
Edit the file `builder.conf` to change the variable `$DISTS_VM` to your OS name (`DISTS_VM=your_os_name`).
Then try to create (make) the template to check that at least these first two scripts are working correctly:
2019-05-26 20:32:45 -04:00
~~~
make linux-template-builder
~~~
Qubes builder Makefiles
-----------------------
2019-08-01 21:13:45 -04:00
Now you need to create Makefiles specific to your OS.
You will find the required scripts to adapt in the `builder-*` folders:
2019-05-26 20:32:45 -04:00
~~~
prepare-chroot-yourOSname
Makefile.yourOSname
~~~
### prepare-chroot-yourOSname
2019-08-01 21:13:45 -04:00
The goal of this file is to prepare a development environment of your target OS inside a chroot.
You will reuse the `00_prepare.sh` and `01_install_core.sh` scripts.
Additionally, the following things have to be done in this Makefile:
2019-05-26 20:32:45 -04:00
- the `$1` variable will contain the installation directory (`$INSTALLDIR` should contain the same value as `$1` when you run `00_prepare.sh` or `01_install_core.sh` )
- after your base system is installed, you should install development tools and libraries (gcc, make, ...)
2019-08-01 21:13:45 -04:00
- create a user called 'user' inside your chroot, and give them enough rights to run the command sudo without any password
- register all the repositories that will be necessary and synchronize the package database
2019-05-26 20:32:45 -04:00
- register a custom repository that will be used to store Qubes packages
### Makefile.yourOSname
2019-08-01 21:13:45 -04:00
This file will be used to define the action required when installing a custom package.
The most important one are:
2019-05-26 20:32:45 -04:00
- `dist-prepare-chroot` : that's where you will call `prepare-chroot-yourOSname` if the chroot has not been initialized.
- `dist-package` : that's where you will chroot the development environment and run the command used to build a package.
- `dist-build-dep` : that's where you will create the custom repository for your target OS based on already compiled packages.
2019-08-01 21:13:45 -04:00
These additional targets need to exist once you have created your first packages:
2019-05-26 20:32:45 -04:00
- `dist-copy-out` : that's where you will retrieve the package you just built and put it with all the other packages you prepared.
2019-08-01 21:13:45 -04:00
- `update-repo` : that's where you will retrieve the package that has been built and add it to the custom repository.
2019-05-26 20:32:45 -04:00
### Testing the development chroot
2019-08-01 21:13:45 -04:00
You will be able to test these scripts when making the first Qubes packages.
Don't forget that the first things that run when running `make somecomponent-vm` will be these two scripts, and that you will need to debug it at this point.
2019-05-26 20:32:45 -04:00
Qubes packages
--------------
* [vmm-xen ](https://github.com/QubesOS/qubes-vmm-xen )
* [core-vchan-xen ](https://github.com/QubesOS/qubes-core-vchan-xen )
* [linux-utils ](https://github.com/QubesOS/qubes-linux-utils )
* [core-agent-linux ](https://github.com/QubesOS/qubes-core-agent-linux )
* [gui-common ](https://github.com/QubesOS/qubes-gui-common )
* [gui-agent-linux ](https://github.com/QubesOS/qubes-gui-agent-linux )
Additional Installation scripts
-------------------------------
2019-08-01 21:13:45 -04:00
Again you need to create new scripts based on the existing scripts in these folders:
2019-05-26 20:32:45 -04:00
~~~
2019-08-01 21:13:45 -04:00
builder-archlinux/scripts
builder-debian/template-debian
builder-rpm/template-scripts
2019-05-26 20:32:45 -04:00
~~~
### 02\_install\_groups.sh
The goal of this script is to install all the packages that you want to use in your template (eg: firefox, thunderbird, a file manager, Xorg...).
### 04\_install\_qubes.sh
2019-08-01 21:13:45 -04:00
The goal of this script is to install in your template all the packages you built previously.
Also you need to edit the fstab file of your template to mount Qubes virtual hard drives.
2019-05-26 20:32:45 -04:00
### 09\_cleanup.sh
2019-08-01 21:13:45 -04:00
This script is used to finalize and to remove unnecessary things from your template, such as cached packages, unused development packages ...
2019-05-26 20:32:45 -04:00
Starting with an HVM
====================
2019-08-01 21:13:45 -04:00
If no Qubes packages are available for your selected OS you could start by installing your OS in an HVM.
Your goals will be:
2019-05-26 20:32:45 -04:00
- to identify how to install the OS using command lines
- to create required Qubes packages
2019-08-01 21:13:45 -04:00
- to identify potential issues, making sure all Qubes agents and scripts work correctly.
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
As soon as you manage to get `qrexec` and `qubes-gui-agent` working, you will be ready to start preparing a template VM.
2019-05-26 20:32:45 -04:00
### Xen libraries
2019-08-01 21:13:45 -04:00
Several Xen libraries are required for Qubes to work correctly.
In fact, you need to make `xenstore` commands working before anything else.
For this, Qubes git can be used as several patches have been selected by Qubes developers that could impact the activity inside a VM.
Start by retrieving a recent git and identify how you can build a package from it: `git clone https://github.com/QubesOS/qubes-vmm-xen.git` .
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
Find the .spec file in the git repository (this is the file used to build rpm packages), and try to adapt it to your OS in order to build a package similar to the target 'vmm-xen'.
2020-01-18 13:35:56 -05:00
For example, a PKGBUILD has been created for
2020-12-07 23:23:40 -05:00
[ArchLinux ](https://www.qubes-os.org/doc/building-archlinux-template/ ) which can be found in the vmm-xen repository.
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
Don't be afraid of the complexity of the PKGBUILD: most of the code is almost a copy/paste of required sources and patches found in the .spec file provided in the git repository.
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
Note once the package has been successfully compiled and installed, you need to setup XEN filesystem.
Add the following line to your fstab (you can create this line in your package install script):
`xen /proc/xen xenfs defaults 0 0` .
2019-05-26 20:32:45 -04:00
2019-08-01 21:13:45 -04:00
Now install the package you built and mount `/proc/xen` .
Verify that xenstore-read works by running: `xenstore-read name` . That should give you the current qube name.
2019-08-02 00:59:16 -04:00
[API]: https://github.com/QubesOS/qubes-builder/blob/master/doc/BuilderPluginAPI.md