home-server/README.md

4.7 KiB

Fedora Home Server spin

Build environment

This project contains a KIWI NG build machine environment provisioned via cloud-init.

This tutorial assumes a recent Fedora host. The build process is driven by make, so examine the makefile at any time for a deeper understanding of what's going.

Configure the host

libvirt and some related tools are needed to continue. Install with make install:

make install

Add yourself to the libvirt group:

sudo usermod -a -G libvirt $USER

Log out and log back in for group membership to take effect.

Download the image

The KIWI project recommends that the build host use a distribution as close as possible to the target. This is because KIWI relies on the host for many of the tools that it orchestrates. A Fedora Cloud image can be downloaded with make download:

make download

Start the KIWI builder

Use make create to start the KIWI builder virtual machine:

make create
$ make create
qemu-img resize vm/fedora-build.qcow2 100G
Image resized.
virt-install --name fedora-build \
        --memory 2048 \
        --vcpus 2 \
        --memorybacking source.type=memfd,access.mode=shared \
...
Domain has shutdown. Continuing.
Domain creation completed.
Restarting guest.

This command takes awhile. On creation, KIWI and its dependencies are installed, and there are a lot. The KIWI builder system is configured via cloud-init, so you can examine the config.yaml file to understand what the system contains.

Once initialized, the VM can be started and stopped with make start and make stop respectively. To destroy the VM, run make destroy.

View the console

Access the VM console. The login account is fedora:fedora as defined in the config.yaml file:

make console
$ make console
virsh --connect qemu:///session console fedora-build
Connected to domain 'fedora-build'
Escape character is ^] (Ctrl + ])

localhost login: fedora
Password:
[fedora@localhost ~]$

To exit the VM console: Ctrl+]

To open the graphical console:

make viewer

Run an example

The KIWI example projects can be downloaded with make kiwi. Git is required. These end up in the kiwi/ directory:

make kiwi

Once the examples have downloaded, run sudo make example inside the build VM to build a sample minimal Fedora ISO:

sudo make example
[fedora@localhost ~]$ sudo make example
rm -rf /root/output output/
kiwi-ng \
        --profile Live \
        system build \
        --description kiwi/build-tests/x86/fedora/test-image-live-disk/ \
        --set-repo=http://dl.fedoraproject.org/pub/fedora/linux/releases/44/Everything/x86_64/os/,rpm-md \
        --target-dir /root/output
...
[ INFO    ]: 05:32:42 | --> image_packages: /root/output/kiwi-test-image-live-disk.x86_64-2.0.0.packages
[ INFO    ]: 05:32:42 | --> image_verified: /root/output/kiwi-test-image-live-disk.x86_64-2.0.0.verified
[ INFO    ]: 05:32:42 | --> live_image: /root/output/kiwi-test-image-live-disk.x86_64-2.0.0.iso
mkdir -p output/
mv /root/output/*.iso output/

This will take some time to complete. Once finished, the built example ISO will be in output/.

$ ls output/
kiwi-test-image-live-disk.x86_64-2.0.0.iso

Run make test to spin up an ephemeral VM to try your new ISO image.

make test
$ make test
export DISK=$(mktemp -u /tmp/test-XXXXXX.qcow2) && \
qemu-img create -f qcow2 $DISK 20G && \
virt-install --name fedora-test \
        --memory 2048 --vcpus 2 \
        --cdrom output/kiwi*.iso \
        --boot cdrom,hd \
        --disk path=$DISK,bus=virtio \
...

This command runs your new Fedora ISO in a fresh virtual machine with a GUI console window. When the console window is closed, the virtual machine and storage are also destroyed, so repeated testing is straightforward.

Troubleshooting

Permissions

KIWI must be run as root, so errors like this usually indicate that you've forgotten to use sudo.

[fedora@localhost ~]$ make example
rm -rf /root/output output/
rm: cannot remove '/root/output': Permission denied
rm: cannot remove 'output/kiwi.result': Permission denied
rm: cannot remove 'output/kiwi.result.json': Permission denied
rm: cannot remove 'output/kiwi-test-image-live-disk.x86_64-2.0.0.changes': Permission denied
rm: cannot remove 'output/kiwi-test-image-live-disk.x86_64-2.0.0.iso': Permission denied
rm: cannot remove 'output/kiwi-test-image-live-disk.x86_64-2.0.0.packages': Permission denied
rm: cannot remove 'output/kiwi-test-image-live-disk.x86_64-2.0.0.verified': Permission denied
make: *** [makefile:84: example] Error 1

Run make example as root:

sudo make example